From ce6d5d9f408be01f7fb9ff9978a410d33eee2ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 25 Apr 2017 18:29:59 +0200 Subject: [PATCH] utils: add parsing of datetimes formatted as %Y-%m-%dT%H:%M:%SZ (#16033) --- tests/test_misc.py | 9 ++++++++- wcs/qommon/misc.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 0db9ddac..c940b7a3 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -14,7 +14,7 @@ import wcs.api # workaround against circular dependencies :/ from wcs.qommon.form import FileSizeWidget from wcs.qommon.humantime import humanduration2seconds, seconds2humanduration from wcs.qommon.misc import (simplify, json_loads, parse_isotime, format_time, - date_format) + date_format, get_as_datetime) from wcs.admin.settings import FileTypesDirectory from wcs.scripts import Script from wcs.qommon import evalutils @@ -237,6 +237,13 @@ def test_date_format(): finally: os.environ = orig_environ +def test_get_as_datetime(): + pub = create_temporary_pub() + datetime_value = datetime.datetime(2017, 4, 25, 12, 0) + assert get_as_datetime('2017-04-25 12:00') == datetime_value + assert get_as_datetime('2017-04-25T12:00:00Z') == datetime_value + assert get_as_datetime('25/04/2017 12:00') == datetime_value + def test_etld(): pub = create_temporary_pub() pub.load_effective_tld_names() diff --git a/wcs/qommon/misc.py b/wcs/qommon/misc.py index 2c5fee74..8b3020c4 100644 --- a/wcs/qommon/misc.py +++ b/wcs/qommon/misc.py @@ -167,7 +167,7 @@ DATE_FORMATS = { } DATETIME_FORMATS = { - 'C': ['%Y-%m-%d %H:%M'], + 'C': ['%Y-%m-%d %H:%M', '%Y-%m-%dT%H:%M:%SZ'], 'fr': ['%d/%m/%Y %H:%M'], } -- 2.11.0