Skip to content

Commit bf96eac

Browse files
committed
python: format all zero UtilDatetime objects as an empty string
Problem: It is inconvenient that UtilDatetime objects (obtained via the `!d` conversion specifier) are treated differently than the normal datetime conversion (`!D`) when the timestamp is zero. In the first case, the datetime is rendered to the epoch date in whatever format is specified by the user, while in the second case the result is an empty string. Since a zero timestamp is considered "unset", the empty string is much more preferable here. Since the prime use case for UtilDatetime is in output format rendering for utilities, have this class return an empty string by default for zero timestamps, presuming these are unset. Fix one test in t2800-jobs-cmd.t that assumed a 00:00 result.
1 parent e3c8698 commit bf96eac

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/bindings/python/flux/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ def __format__(self, fmt):
314314
# any Python format spec:
315315
vals = fmt.split("::", 1)
316316

317-
# Call strftime() to get the formatted datetime as a string
318-
result = self.strftime(vals[0])
317+
if self == datetime.fromtimestamp(0.0):
318+
result = ""
319+
else:
320+
# Call strftime() to get the formatted datetime as a string
321+
result = self.strftime(vals[0])
319322

320323
# If there was a format spec, apply it here:
321324
try:

t/t2800-jobs-cmd.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ test_expect_success 'flux-jobs emits empty string for special case t_estimate' '
10081008
flux jobs -no "${fmt}" >t_estimate_annotations.out 2>&1 &&
10091009
test_debug "cat t_estimate_annotations.out" &&
10101010
for i in `seq 1 $(state_count active)`; do
1011-
echo ",00:00,,,,-,-,-" >> t_estimate_annotations.exp
1011+
echo ",,,,,-,-,-" >> t_estimate_annotations.exp
10121012
done &&
10131013
test_cmp t_estimate_annotations.out t_estimate_annotations.exp
10141014
'

0 commit comments

Comments
 (0)