tools (date_utils): moved date_parse to common.date_utils, because it can be used in frontends
This commit is contained in:
parent
d36f76e7d3
commit
0242772939
1 changed files with 21 additions and 17 deletions
|
|
@ -21,10 +21,21 @@
|
|||
|
||||
from sat.core.constants import Const as C
|
||||
import datetime
|
||||
from dateutil import parser as dateutil_parser
|
||||
from babel import dates
|
||||
import calendar
|
||||
import time
|
||||
|
||||
|
||||
def date_parse(value):
|
||||
"""Parse a date and return corresponding unix timestamp
|
||||
|
||||
@param value(unicode): date to parse, in any format supported by dateutil.parser
|
||||
@return (int): timestamp
|
||||
"""
|
||||
return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple())
|
||||
|
||||
|
||||
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):
|
||||
"""format date according to locale
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue