~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to common.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-13 20:08:02 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050713200802-b90130548125dfdc
Added common to the set of tests, fixed a problem with time conversions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
Common entries, like strings, etc, for the changeset reading + writing code.
4
4
"""
5
5
 
 
6
import bzrlib
 
7
 
6
8
header_str = 'Bazaar-NG changeset v'
7
9
version = (0, 0, 5)
8
10
 
109
111
 
110
112
    >>> encode(u'abcdefg')
111
113
    'abcdefg'
112
 
    >>> encode(u'a b\tc\\nd\\\\e')
 
114
    >>> encode(u'a b\\tc\\nd\\\\e')
113
115
    'a b\\\\tc\\\\nd\\\\e'
114
 
    >>> encode('a b\tc\\nd\\e')
 
116
    >>> encode('a b\\tc\\nd\\e')
115
117
    'a b\\\\tc\\\\nd\\\\e'
116
118
    >>> encode(u'\\u1234\\u0020')
117
119
    '\\\\u1234 '
130
132
    >>> decode('abcdefg')
131
133
    u'abcdefg'
132
134
    >>> decode('a b\\\\tc\\\\nd\\\\e')
133
 
    u'a b\tc\\nd\\\\e'
 
135
    u'a b\\tc\\nd\\\\e'
134
136
    >>> decode('\\\\u1234\\\\u0020')
135
137
    u'\\u1234 '
136
138
    >>> for s in ('test', 'strings'):
181
183
def unpack_highres_date(date):
182
184
    """This takes the high-resolution date stamp, and
183
185
    converts it back into the tuple (timestamp, timezone)
184
 
    Where timestamp is in real seconds, and timezone is an integer
 
186
    Where timestamp is in real UTC since epoch seconds, and timezone is an integer
185
187
    number of seconds offset.
186
188
 
187
189
    :param date: A date formated by format_highres_date
209
211
    ...   t2, o2 = unpack_highres_date(date)
210
212
    ...   if t != t2 or o != o2:
211
213
    ...      print 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t)
 
214
    ...      break
212
215
 
213
216
    """
214
217
    #from bzrlib.errors import BzrError
215
218
    from bzrlib.osutils import local_time_offset
216
 
    import time
 
219
    import time, calendar
217
220
    # Up until the first period is a datestamp that is generated
218
221
    # as normal from time.strftime, so use time.strptime to
219
222
    # parse it
226
229
    offset = int(offset)
227
230
    offset = int(offset / 100) * 3600 + offset % 100
228
231
    
229
 
    # mktime returns the a local timestamp, not the timestamp based
230
 
    # on the offset given in the file, so we need to adjust based
231
 
    # on what the local offset is, and then re-adjust based on
232
 
    # offset read
233
 
    timestamp = time.mktime(base_time)
234
 
    timestamp += local_time_offset(timestamp) - offset
 
232
    # time.mktime returns localtime, but calendar.timegm returns UTC time
 
233
    timestamp = calendar.timegm(base_time)
 
234
    timestamp -= offset
235
235
    # Add back in the fractional seconds
236
236
    timestamp += fract_seconds
237
237
    return (timestamp, offset)