equal
deleted
inserted
replaced
12 |
12 |
13 from i18n import gettext as _ |
13 from i18n import gettext as _ |
14 from demandload import * |
14 from demandload import * |
15 demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") |
15 demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") |
16 demandload(globals(), "os threading time") |
16 demandload(globals(), "os threading time") |
|
17 |
|
18 # used by parsedate |
|
19 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', |
|
20 '%a %b %d %H:%M:%S %Y') |
17 |
21 |
18 class SignalInterrupt(Exception): |
22 class SignalInterrupt(Exception): |
19 """Exception raised on SIGTERM and SIGHUP.""" |
23 """Exception raised on SIGTERM and SIGHUP.""" |
20 |
24 |
21 def pipefilter(s, cmd): |
25 def pipefilter(s, cmd): |
881 else: |
885 else: |
882 date, offset = string, 0 |
886 date, offset = string, 0 |
883 when = int(time.mktime(time.strptime(date, format))) + offset |
887 when = int(time.mktime(time.strptime(date, format))) + offset |
884 return when, offset |
888 return when, offset |
885 |
889 |
886 def parsedate(string, formats=('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M')): |
890 def parsedate(string, formats=None): |
887 """parse a localized time string and return a (unixtime, offset) tuple. |
891 """parse a localized time string and return a (unixtime, offset) tuple. |
888 The date may be a "unixtime offset" string or in one of the specified |
892 The date may be a "unixtime offset" string or in one of the specified |
889 formats.""" |
893 formats.""" |
|
894 if not formats: |
|
895 formats = defaultdateformats |
890 try: |
896 try: |
891 when, offset = map(int, string.split(' ')) |
897 when, offset = map(int, string.split(' ')) |
892 except ValueError: |
898 except ValueError: |
893 for format in formats: |
899 for format in formats: |
894 try: |
900 try: |