Skip to content

Commit 74be1ff

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 8596055 commit 74be1ff

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
@@ -321,7 +321,7 @@ def parse_fsd(fsd_string):
321321
return seconds
322322

323323

324-
def parse_datetime(string, now=None):
324+
def parse_datetime(string, now=None, assumeFuture=True):
325325
"""Parse a possibly human readable datetime string or offset
326326
327327
If string starts with `+` or `-`, then the remainder of the string
@@ -359,6 +359,9 @@ def parse_datetime(string, now=None):
359359

360360
cal = Calendar()
361361
cal.ptc.StartHour = 0
362+
if not assumeFuture:
363+
cal.ptc.DOWParseStyle = 0
364+
cal.ptc.YearParseStyle = 0
362365
time_struct, status = cal.parse(string, sourceTime=now.timetuple())
363366
if status == 0:
364367
raise ValueError(f'Invalid datetime: "{string}"')

0 commit comments

Comments
 (0)