Skip to content

Commit 8e9a03d

Browse files
committed
python: add assumeFuture argument to flux.util.parse_datetime
Problem: The parse_datetime() utility function is statically configured to assume future dates when a term like "Friday" is given. That is, instead of giving the date for the previous Friday, the function will return then next Friday instead. This behavior should be configurable. Add an assumeFuture parameter to the function which defaults to True. If set to False, then parse_datetime() will assume dates in the past instead.
1 parent d7bd7d4 commit 8e9a03d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/bindings/python/flux/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def parse_fsd(fsd_string):
331331
return seconds
332332

333333

334-
def parse_datetime(string, now=None):
334+
def parse_datetime(string, now=None, assumeFuture=True):
335335
"""Parse a possibly human readable datetime string or offset
336336
337337
If string starts with `+` or `-`, then the remainder of the string
@@ -369,6 +369,9 @@ def parse_datetime(string, now=None):
369369

370370
cal = Calendar()
371371
cal.ptc.StartHour = 0
372+
if not assumeFuture:
373+
cal.ptc.DOWParseStyle = 0
374+
cal.ptc.YearParseStyle = 0
372375
time_struct, status = cal.parse(string, sourceTime=now.timetuple())
373376
if status == 0:
374377
raise ValueError(f'Invalid datetime: "{string}"')

0 commit comments

Comments
 (0)