summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/llnl/util/lang.py7
-rw-r--r--lib/spack/spack/test/llnl/util/lang.py2
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index bffec90a71..03783265dd 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -448,7 +448,8 @@ def pretty_string_to_date(date_str, now=None):
Args:
date_str (str): string representing a date. This string might be
- in different format (like ``YYYY``, ``YYYY-MM``, ``YYYY-MM-DD``)
+ in different format (like ``YYYY``, ``YYYY-MM``, ``YYYY-MM-DD``,
+ ``YYYY-MM-DD HH:MM``, ``YYYY-MM-DD HH:MM:SS``)
or be a *pretty date* (like ``yesterday`` or ``two months ago``)
Returns:
@@ -467,6 +468,10 @@ def pretty_string_to_date(date_str, now=None):
pattern[re.compile(r'^\d{4}-\d{2}-\d{2}$')] = lambda x: datetime.strptime(
x, '%Y-%m-%d'
)
+ pattern[re.compile(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$')] = \
+ lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M')
+ pattern[re.compile(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$')] = \
+ lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
pretty_regex = re.compile(
r'(a|\d+)\s*(year|month|week|day|hour|minute|second)s?\s*ago')
diff --git a/lib/spack/spack/test/llnl/util/lang.py b/lib/spack/spack/test/llnl/util/lang.py
index 4c1928aaa6..edeab72c28 100644
--- a/lib/spack/spack/test/llnl/util/lang.py
+++ b/lib/spack/spack/test/llnl/util/lang.py
@@ -82,6 +82,8 @@ def test_pretty_string_to_date_delta(now, delta, pretty_string):
('%Y', '2018'),
('%Y-%m', '2015-03'),
('%Y-%m-%d', '2015-03-28'),
+ ('%Y-%m-%d %H:%M', '2015-03-28 11:12'),
+ ('%Y-%m-%d %H:%M:%S', '2015-03-28 23:34:45'),
])
def test_pretty_string_to_date(format, pretty_string):
t1 = datetime.strptime(pretty_string, format)