def test_random(self): t = time.time() o = local_time_offset() t2, o2 = timestamp.unpack_highres_date( timestamp.format_highres_date(t, o)) self.assertEqual(t, t2) self.assertEqual(o, o2) t -= 24 * 3600 * 365 * 2 # Start 2 years ago o = -12 * 3600 for count in range(500): t += random.random() * 24 * 3600 * 30 try: time.gmtime(t + o) except (OverflowError, ValueError): # We've reached the maximum for time_t on this platform break if time.localtime(t).tm_year > 9998: # strptime doesn't always understand years with more than 4 # digits. break # Add 1 wrap around from [-12, 12] o = ((o / 3600 + 13) % 25 - 12) * 3600 date = timestamp.format_highres_date(t, o) t2, o2 = timestamp.unpack_highres_date(date) self.assertEqual( t, t2, 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2 - t)) self.assertEqual( o, o2, 'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2 - t))
def test_unpack_highres_date(self): self.assertEqual((1120153132.3508501, -18000), timestamp.unpack_highres_date( 'Thu 2005-06-30 12:38:52.350850105 -0500')) self.assertEqual((1120153132.3508501, 0), timestamp.unpack_highres_date( 'Thu 2005-06-30 17:38:52.350850105 +0000')) self.assertEqual((1120153132.3508501, 7200), timestamp.unpack_highres_date( 'Thu 2005-06-30 19:38:52.350850105 +0200')) self.assertEqual((1152428738.867522, 19800), timestamp.unpack_highres_date( 'Sun 2006-07-09 12:35:38.867522001 +0530'))
def complete_info(self): """This makes sure that all information is properly split up, based on the assumptions that can be made when information is missing. """ from breezy.timestamp import unpack_highres_date # Put in all of the guessable information. if not self.timestamp and self.date: self.timestamp, self.timezone = unpack_highres_date(self.date) self.real_revisions = [] for rev in self.revisions: if rev.timestamp is None: if rev.date is not None: rev.timestamp, rev.timezone = \ unpack_highres_date(rev.date) else: rev.timestamp = self.timestamp rev.timezone = self.timezone if rev.message is None and self.message: rev.message = self.message if rev.committer is None and self.committer: rev.committer = self.committer self.real_revisions.append(rev.as_revision())