Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 1321:b47f96a178a3
Clean up date and timezone handling.
We used to pass changelog dates around as a "unixtime timezone" string
containing a pair of encoded ints. Now, they get passed around as a
(unixtime, timezone) tuple of numbers, which makes much more sense.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Thu, 22 Sep 2005 23:19:47 -0700 |
parents | 5f277e73778f |
children | 8f06817bf266 |
comparison
equal
deleted
inserted
replaced
1320:5f277e73778f | 1321:b47f96a178a3 |
---|---|
542 s = f.read(size) | 542 s = f.read(size) |
543 while len(s) >= 0: | 543 while len(s) >= 0: |
544 yield s | 544 yield s |
545 s = f.read(size) | 545 s = f.read(size) |
546 | 546 |
547 def datestr(change=None, format='%c'): | 547 def makedate(): |
548 """represent a change date as a localized time. | 548 t = time.time() |
549 a change date is a 'unixtime offset' string, where unixtime is | 549 if time.daylight: tz = time.altzone |
550 seconds since the epoch, and offset is seconds away from UTC.""" | 550 else: tz = time.timezone |
551 if change is None: | 551 return t, tz |
552 t = time.time() | 552 |
553 if time.daylight: tz = time.altzone | 553 def datestr(date=None, format='%c'): |
554 else: tz = time.timezone | 554 """represent a (unixtime, offset) tuple as a localized time. |
555 else: | 555 unixtime is seconds since the epoch, and offset is the time zone's |
556 t, tz = change[2].split(' ') | 556 number of seconds away from UTC.""" |
557 try: | 557 t, tz = date or makedate() |
558 # a conversion tool was sticking non-integer offsets into repos | |
559 tz = int(tz) | |
560 except ValueError: | |
561 tz = 0 | |
562 return ("%s %+03d%02d" % | 558 return ("%s %+03d%02d" % |
563 (time.strftime(format, time.gmtime(float(t) - tz)), | 559 (time.strftime(format, time.gmtime(float(t) - tz)), |
564 -tz / 3600, | 560 -tz / 3600, |
565 ((-tz % 3600) / 60))) | 561 ((-tz % 3600) / 60))) |