diff options
Diffstat (limited to 'gnunet/strings.py')
-rw-r--r-- | gnunet/strings.py | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/gnunet/strings.py b/gnunet/strings.py index c84e32c..1484495 100644 --- a/gnunet/strings.py +++ b/gnunet/strings.py | |||
@@ -53,48 +53,22 @@ def string_to_data(s): | |||
53 | def absolute_time_to_string(t): | 53 | def absolute_time_to_string(t): |
54 | return t.strftime("%a %b %d %H:%M:%S %Y") | 54 | return t.strftime("%a %b %d %H:%M:%S %Y") |
55 | 55 | ||
56 | |||
57 | def string_to_absolute_time(s): | 56 | def string_to_absolute_time(s): |
58 | if s == "end of time": | 57 | if s == "end of time": |
59 | return None | 58 | return None |
60 | try: | 59 | for fmt in ( |
61 | return datetime.datetime.strptime(s, "%a %b %d %H:%M:%S %Y") | 60 | "%a %b %d %H:%M:%S %Y", |
62 | except ValueError: | 61 | "%c", |
63 | pass | 62 | "%Ec", |
64 | try: | 63 | "%Y-%m-%d %H:%M:%S", |
65 | return datetime.datetime.strptime(s, "%c") | 64 | "%Y-%m-%d %H:%M", |
66 | except ValueError: | 65 | "%x", |
67 | pass | 66 | "%Ex", |
68 | try: | 67 | "%Y-%m-%d", |
69 | return datetime.datetime.strptime(s, "%Ec") | 68 | "%Y-%m", |
70 | except ValueError: | 69 | "%Y"): |
71 | pass | 70 | try: |
72 | try: | 71 | return datetime.datetime.strptime(s, fmt) |
73 | return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") | 72 | except ValueError: |
74 | except ValueError: | 73 | pass |
75 | pass | ||
76 | try: | ||
77 | return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M") | ||
78 | except ValueError: | ||
79 | pass | ||
80 | try: | ||
81 | return datetime.datetime.strptime(s, "%x") | ||
82 | except ValueError: | ||
83 | pass | ||
84 | try: | ||
85 | return datetime.datetime.strptime(s, "%Ex") | ||
86 | except ValueError: | ||
87 | pass | ||
88 | try: | ||
89 | return datetime.datetime.strptime(s, "%Y-%m-%d") | ||
90 | except ValueError: | ||
91 | pass | ||
92 | try: | ||
93 | return datetime.datetime.strptime(s, "%Y-%m") | ||
94 | except ValueError: | ||
95 | pass | ||
96 | try: | ||
97 | return datetime.datetime.strptime(s, "%Y") | ||
98 | except ValueError: | ||
99 | pass | ||
100 | raise ValueError("%s is not a properly formatted time string" % s) | 74 | raise ValueError("%s is not a properly formatted time string" % s) |