Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 2523:4ab59a3acd16
validate the resulting date in parsedate
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Fri, 30 Jun 2006 18:48:06 +0200 |
parents | 85f796baab10 |
children | 8cb894370514 |
comparison
equal
deleted
inserted
replaced
2522:85f796baab10 | 2523:4ab59a3acd16 |
---|---|
880 """parse a localized time string and return a (unixtime, offset) tuple. | 880 """parse a localized time string and return a (unixtime, offset) tuple. |
881 The date may be a "unixtime offset" string or in one of the specified | 881 The date may be a "unixtime offset" string or in one of the specified |
882 formats.""" | 882 formats.""" |
883 try: | 883 try: |
884 when, offset = map(int, string.split(' ')) | 884 when, offset = map(int, string.split(' ')) |
885 return when, offset | 885 except ValueError: |
886 except ValueError: pass | 886 for format in formats: |
887 for format in formats: | 887 try: |
888 try: | 888 when, offset = strdate(string, format) |
889 return strdate(string, format) | 889 except ValueError: |
890 except ValueError: pass | 890 pass |
891 raise ValueError(_('invalid date: %r') % string) | 891 else: |
892 break | |
893 else: | |
894 raise ValueError(_('invalid date: %r') % string) | |
895 # validate explicit (probably user-specified) date and | |
896 # time zone offset. values must fit in signed 32 bits for | |
897 # current 32-bit linux runtimes. timezones go from UTC-12 | |
898 # to UTC+14 | |
899 if abs(when) > 0x7fffffff: | |
900 raise ValueError(_('date exceeds 32 bits: %d') % when) | |
901 if offset < -50400 or offset > 43200: | |
902 raise ValueError(_('impossible time zone offset: %d') % offset) | |
903 return when, offset | |
892 | 904 |
893 def shortuser(user): | 905 def shortuser(user): |
894 """Return a short representation of a user name or email address.""" | 906 """Return a short representation of a user name or email address.""" |
895 f = user.find('@') | 907 f = user.find('@') |
896 if f >= 0: | 908 if f >= 0: |