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 merge_directive_changes( local_branch: Branch, main_branch: Branch, hoster: Hoster, name: str, message: str, include_patch: bool = False, include_bundle: bool = False, overwrite_existing: bool = False, ) -> MergeDirective: from breezy import osutils import time remote_branch, public_branch_url = hoster.publish_derived( local_branch, main_branch, name=name, overwrite=overwrite_existing) public_branch = open_branch(public_branch_url) directive = MergeDirective2.from_objects( local_branch.repository, local_branch.last_revision(), time.time(), osutils.local_time_offset(), main_branch, public_branch=public_branch, include_patch=include_patch, include_bundle=include_bundle, message=message, base_revision_id=main_branch.last_revision(), ) return directive
def send_hg(branch, revision_id, submit_branch, public_branch, no_patch, no_bundle, message, base_revision_id): return HgMergeDirective.from_objects(branch.repository, revision_id, time.time(), osutils.local_time_offset(), submit_branch, public_branch=public_branch, message=message)
def create_date_str(timestamp=None, offset=None): """Just a wrapper around format_date to provide the right format. We don't want to use '%a' in the time string, because it is locale dependant. We also want to force timezone original, and show_offset Without parameters this function yields the current date in the local time zone. """ if timestamp is None and offset is None: timestamp = time.time() offset = local_time_offset() return format_date(timestamp, offset, date_fmt='%Y-%m-%d %H:%M:%S', timezone='original', show_offset=True)