From 865259d40e40a4dadfe215abae85516bd563e05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 8 Nov 2016 13:38:36 +0100 Subject: [PATCH] pretty_date('some string') now tries to parse the string as datetime. dateutil.parser.parse('some string') is used for this. --- pillar/web/utils/__init__.py | 3 +++ requirements.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/pillar/web/utils/__init__.py b/pillar/web/utils/__init__.py index 4860a041..6af25fe5 100644 --- a/pillar/web/utils/__init__.py +++ b/pillar/web/utils/__init__.py @@ -5,6 +5,7 @@ import logging import traceback import sys +import dateutil.parser from flask import current_app from flask import request from flask_login import current_user @@ -72,6 +73,8 @@ def pretty_date(time, detail=False, now=None): # Normalize the 'time' parameter so it's always a datetime. if type(time) is int: time = datetime.datetime.fromtimestamp(time, tz=pillarsdk.utils.utc) + elif isinstance(time, basestring): + time = dateutil.parser.parse(time) now = now or datetime.datetime.now(tz=time.tzinfo) diff = now - time # TODO: flip the sign, so that future = positive and past = negative. diff --git a/requirements.txt b/requirements.txt index db83657e..81282348 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,6 +26,7 @@ Pillow==2.8.1 pycparser==2.14 pycrypto==2.6.1 pyOpenSSL==0.15.1 +python-dateutil==2.5.3 requests==2.9.1 rsa==3.4.2 simplejson==3.8.2