~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/timestamp.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import calendar
18
18
import time
72
72
    :param date: A date formated by format_highres_date
73
73
    :type date: string
74
74
 
75
 
    >>> import time, random
76
 
    >>> unpack_highres_date('Thu 2005-06-30 12:38:52.350850105 -0500')
77
 
    (1120153132.3508501, -18000)
78
 
    >>> unpack_highres_date('Thu 2005-06-30 17:38:52.350850105 +0000')
79
 
    (1120153132.3508501, 0)
80
 
    >>> unpack_highres_date('Thu 2005-06-30 19:38:52.350850105 +0200')
81
 
    (1120153132.3508501, 7200)
82
 
    >>> unpack_highres_date('Sun 2006-07-09 12:35:38.867522001 +0530')
83
 
    (1152428738.867522, 19800)
84
 
    >>> from bzrlib.osutils import local_time_offset
85
 
    >>> t = time.time()
86
 
    >>> o = local_time_offset()
87
 
    >>> t2, o2 = unpack_highres_date(format_highres_date(t, o))
88
 
    >>> t == t2
89
 
    True
90
 
    >>> o == o2
91
 
    True
92
 
    >>> t -= 24*3600*365*2 # Start 2 years ago
93
 
    >>> o = -12*3600
94
 
    >>> for count in xrange(500):
95
 
    ...   t += random.random()*24*3600*30
96
 
    ...   o = ((o/3600 + 13) % 25 - 12)*3600 # Add 1 wrap around from [-12, 12]
97
 
    ...   date = format_highres_date(t, o)
98
 
    ...   t2, o2 = unpack_highres_date(date)
99
 
    ...   if t != t2 or o != o2:
100
 
    ...      print 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t)
101
 
    ...      break
102
 
 
103
75
    """
104
76
    # Weekday parsing is locale sensitive, so drop the weekday
105
77
    space_loc = date.find(' ')
139
111
    if offset % 60 != 0:
140
112
        raise ValueError(
141
113
        "can't represent timezone %s offset by fractional minutes" % offset)
142
 
    # so that we don't need to do calculations on pre-epoch times, 
 
114
    # so that we don't need to do calculations on pre-epoch times,
143
115
    # which doesn't work with win32 python gmtime, we always
144
116
    # give the epoch in utc
145
117
    if secs == 0: