Mercurial > libervia-backend
comparison sat/tools/common/date_utils.py @ 2612:3e4e78de9cca
tools (date_utils): moved date_parse to common.date_utils, because it can be used in frontends
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 21 Jun 2018 01:21:44 +0200 |
parents | 5b26033c49a8 |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2611:c180ca699e72 | 2612:3e4e78de9cca |
---|---|
19 | 19 |
20 """tools to help manipulating time and dates""" | 20 """tools to help manipulating time and dates""" |
21 | 21 |
22 from sat.core.constants import Const as C | 22 from sat.core.constants import Const as C |
23 import datetime | 23 import datetime |
24 from dateutil import parser as dateutil_parser | |
24 from babel import dates | 25 from babel import dates |
26 import calendar | |
25 import time | 27 import time |
28 | |
29 | |
30 def date_parse(value): | |
31 """Parse a date and return corresponding unix timestamp | |
32 | |
33 @param value(unicode): date to parse, in any format supported by dateutil.parser | |
34 @return (int): timestamp | |
35 """ | |
36 return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple()) | |
26 | 37 |
27 | 38 |
28 def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt='short', auto_new_fmt='relative', locale_str=C.DEFAULT_LOCALE): | 39 def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt='short', auto_new_fmt='relative', locale_str=C.DEFAULT_LOCALE): |
29 """format date according to locale | 40 """format date according to locale |
30 | 41 |