diff 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
line wrap: on
line diff
--- a/sat/tools/common/date_utils.py	Thu Jun 21 01:21:44 2018 +0200
+++ b/sat/tools/common/date_utils.py	Thu Jun 21 01:21:44 2018 +0200
@@ -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