comparison mercurial/util.py @ 3250:e96d2956eb4a

util.strdate: compute timestamp using UTC, not local timezone
author Jose M. Prieto <jmprieto@gmx.net>
date Tue, 03 Oct 2006 12:33:14 +0200
parents 7492b33bdd9f
children e5c9a084ffe3
comparison
equal deleted inserted replaced
3243:1d3aceae87c1 3250:e96d2956eb4a
13 """ 13 """
14 14
15 from i18n import gettext as _ 15 from i18n import gettext as _
16 from demandload import * 16 from demandload import *
17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") 17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
18 demandload(globals(), "os threading time") 18 demandload(globals(), "os threading time calendar")
19 19
20 # used by parsedate 20 # used by parsedate
21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', 21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
22 '%a %b %d %H:%M:%S %Y') 22 '%a %b %d %H:%M:%S %Y')
23 23
901 def hastimezone(string): 901 def hastimezone(string):
902 return (string[-4:].isdigit() and 902 return (string[-4:].isdigit() and
903 (string[-5] == '+' or string[-5] == '-') and 903 (string[-5] == '+' or string[-5] == '-') and
904 string[-6].isspace()) 904 string[-6].isspace())
905 905
906 # NOTE: unixtime = localunixtime + offset
906 if hastimezone(string): 907 if hastimezone(string):
907 date, tz = string[:-6], string[-5:] 908 date, tz = string[:-6], string[-5:]
908 tz = int(tz) 909 tz = int(tz)
909 offset = - 3600 * (tz / 100) - 60 * (tz % 100) 910 offset = - 3600 * (tz / 100) - 60 * (tz % 100)
910 else: 911 else:
911 date, offset = string, 0 912 date, offset = string, 0
912 when = int(time.mktime(time.strptime(date, format))) + offset 913 localunixtime = int(calendar.timegm(time.strptime(date, format)))
913 return when, offset 914 unixtime = localunixtime + offset
915 return unixtime, offset
914 916
915 def parsedate(string, formats=None): 917 def parsedate(string, formats=None):
916 """parse a localized time string and return a (unixtime, offset) tuple. 918 """parse a localized time string and return a (unixtime, offset) tuple.
917 The date may be a "unixtime offset" string or in one of the specified 919 The date may be a "unixtime offset" string or in one of the specified
918 formats.""" 920 formats."""