Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/util.py @ 3281:45b639607e52
Merge with crew
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 06 Oct 2006 17:14:18 -0500 |
parents | c9cd63a6fce9 |
children | ec6f400cff4d |
comparison
equal
deleted
inserted
replaced
3280:ae85272b59a4 | 3281:45b639607e52 |
---|---|
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, None |
912 when = int(time.mktime(time.strptime(date, format))) + offset | 913 timetuple = time.strptime(date, format) |
913 return when, offset | 914 localunixtime = int(calendar.timegm(timetuple)) |
915 if offset is None: | |
916 # local timezone | |
917 unixtime = int(time.mktime(timetuple)) | |
918 offset = unixtime - localunixtime | |
919 else: | |
920 unixtime = localunixtime + offset | |
921 return unixtime, offset | |
914 | 922 |
915 def parsedate(string, formats=None): | 923 def parsedate(string, formats=None): |
916 """parse a localized time string and return a (unixtime, offset) tuple. | 924 """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 | 925 The date may be a "unixtime offset" string or in one of the specified |
918 formats.""" | 926 formats.""" |
927 except ValueError: | 935 except ValueError: |
928 pass | 936 pass |
929 else: | 937 else: |
930 break | 938 break |
931 else: | 939 else: |
932 raise ValueError(_('invalid date: %r') % string) | 940 raise ValueError(_('invalid date: %r ' |
941 'see hg(1) manual page for details') | |
942 % string) | |
933 # validate explicit (probably user-specified) date and | 943 # validate explicit (probably user-specified) date and |
934 # time zone offset. values must fit in signed 32 bits for | 944 # time zone offset. values must fit in signed 32 bits for |
935 # current 32-bit linux runtimes. timezones go from UTC-12 | 945 # current 32-bit linux runtimes. timezones go from UTC-12 |
936 # to UTC+14 | 946 # to UTC+14 |
937 if abs(when) > 0x7fffffff: | 947 if abs(when) > 0x7fffffff: |