diff options
Diffstat (limited to 'ishtar_common/urls_converters.py')
-rw-r--r-- | ishtar_common/urls_converters.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ishtar_common/urls_converters.py b/ishtar_common/urls_converters.py index 9395af648..b5185fd1f 100644 --- a/ishtar_common/urls_converters.py +++ b/ishtar_common/urls_converters.py @@ -17,6 +17,8 @@ # See the file COPYING for details. +from datetime import datetime + class UnderscoreSlug: regex = '[_0-9a-z]+' @@ -27,3 +29,15 @@ class UnderscoreSlug: def to_url(self, value): return str(value) + +class DateTimeConverter: + regex = r"\d{4}-\d{1,2}-\d{1,2}T\d{1,2}\:\d{1,2}\:\d{1,2}\.\d{1,6}" + date_format = '%Y-%m-%dT%H:%M:%S.%f' + + def to_python(self, value): + return datetime.strptime(value, self.date_format) + + def to_url(self, value): + if isinstance(value, datetime): + return value.strftime(self.date_format) + return value |