Skip to content

Commit 99ea1fc

Browse files
authored
Merge pull request #5841 from chu11/issue5827_specifier_empty_string
python: return empty string on epoch time for D conversion flag
2 parents aca18f5 + 8c344db commit 99ea1fc

File tree

6 files changed

+11
-1
lines changed

6 files changed

+11
-1
lines changed

doc/man1/flux-jobs.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ the following conversion flags are supported by :program:`flux jobs`:
240240

241241
**!D**
242242
convert a timestamp field to ISO8601 date and time (e.g. 2020-01-07T13:31:00).
243-
Defaults to empty string if timestamp field does not exist.
243+
Defaults to empty string if timestamp field does not exist or the timestamp
244+
is 0 (i.e epoch time).
244245

245246
**!d**
246247
convert a timestamp to a Python datetime object. This allows datetime

src/bindings/python/flux/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ def convert_field(self, value, conv):
462462
else:
463463
raise
464464
elif conv == "D":
465+
# the JobInfo class initializes many timestamps to 0.0 if
466+
# they are not available. Treat epoch time as special case
467+
# and just return empty string.
468+
if not value:
469+
return ""
465470
# As above, but convert to ISO 8601 date time string.
466471
try:
467472
value = datetime.fromtimestamp(value).strftime("%FT%T")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
D conversion flag outputs empty string on epoch timestamp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{t_run},{t_run!D}

t/flux-jobs/tests/issue#5827/input

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id": 375843192832, "userid": 1000, "urgency": 16, "priority": 0, "t_submit": 1711580059.6155457, "t_depend": 1711580059.6265068, "state": 8, "name": "sleep", "cwd": "/tmp/foo", "ntasks": 1, "ncores": 1, "duration": 0.0}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0,

0 commit comments

Comments
 (0)