Revision 3416
Added by Aaron Marcuse-Kubitza over 12 years ago
schemas/py_functions.sql | ||
---|---|---|
52 | 52 |
|
53 | 53 |
epoch = from_timestamp(0) |
54 | 54 |
|
55 |
def strftime(format, datetime_): |
|
56 |
'''datetime.strftime() can't handle years before 1900''' |
|
57 |
return (datetime_.replace(year=epoch.year, day=1).strftime(format |
|
58 |
.replace('%Y', '%%Y') |
|
59 |
.replace('%d', '%%d') |
|
60 |
) |
|
61 |
.replace('%Y', '%04d' % datetime_.year) |
|
62 |
.replace('%d', '%02d' % datetime_.day) |
|
63 |
) |
|
64 |
|
|
65 | 55 |
def strtotime(str_, default=epoch): |
66 | 56 |
import dateutil.parser |
67 | 57 |
return dateutil.parser.parse(str_, default=default) |
... | ... | |
106 | 96 |
month, day = day, month |
107 | 97 |
else: raise FormatException(e) |
108 | 98 |
|
109 |
try: return strftime('%Y-%m-%d', date) |
|
110 |
except ValueError, e: raise FormatException(e) |
|
99 |
return str(date) |
|
111 | 100 |
$$; |
112 | 101 |
|
113 | 102 |
|
Also available in: Unified diff
schemas/py_functions.sql: _date(): Just run str() on the returned datetime because it will usually be converted to a PostgreSQL timestamp anyway, so excluding the time from the string isn't necessary