summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatthias Wolf <m+git@sushinara.net>2019-02-13 11:05:00 +0100
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2019-02-13 11:05:00 +0100
commit861dd06bd1aae9c9c52c57575cf711510691b616 (patch)
tree8cbcdc24bf3c1022b6d00fc44fc2e97edac1d7ff /lib
parentf65a1155e1aa30864c4c8bb49d1e5445f1ab9b67 (diff)
downloadspack-861dd06bd1aae9c9c52c57575cf711510691b616.tar.gz
spack-861dd06bd1aae9c9c52c57575cf711510691b616.tar.bz2
spack-861dd06bd1aae9c9c52c57575cf711510691b616.tar.xz
spack-861dd06bd1aae9c9c52c57575cf711510691b616.zip
enh: allow time like HH:MM in date strings. (#10034)
Diffstat (limited to 'lib')
-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)