comparison mercurial/util.py @ 19287:8b04e1344111

util: add an optional timestamp parameter to makedate This will be used by the upcoming shelve extension.
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 03 Jun 2013 17:20:45 -0700
parents 78501209488a
children dd7c992d3cc1
comparison
equal deleted inserted replaced
19286:78501209488a 19287:8b04e1344111
995 break 995 break
996 if limit: 996 if limit:
997 limit -= len(s) 997 limit -= len(s)
998 yield s 998 yield s
999 999
1000 def makedate(): 1000 def makedate(timestamp=None):
1001 '''Return the current time as a (unixtime, offset) tuple based off 1001 '''Return a unix timestamp (or the current time) as a (unixtime,
1002 the local timezone.''' 1002 offset) tuple based off the local timezone.'''
1003 timestamp = time.time() 1003 if timestamp is None:
1004 timestamp = time.time()
1004 if timestamp < 0: 1005 if timestamp < 0:
1005 hint = _("check your clock") 1006 hint = _("check your clock")
1006 raise Abort(_("negative timestamp: %d") % timestamp, hint=hint) 1007 raise Abort(_("negative timestamp: %d") % timestamp, hint=hint)
1007 delta = (datetime.datetime.utcfromtimestamp(timestamp) - 1008 delta = (datetime.datetime.utcfromtimestamp(timestamp) -
1008 datetime.datetime.fromtimestamp(timestamp)) 1009 datetime.datetime.fromtimestamp(timestamp))