Skip to content

Commit

Permalink
Merge pull request #5841 from chu11/issue5827_specifier_empty_string
Browse files Browse the repository at this point in the history
python: return empty string on epoch time for D conversion flag
  • Loading branch information
mergify[bot] committed Mar 28, 2024
2 parents aca18f5 + 8c344db commit 99ea1fc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/man1/flux-jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ the following conversion flags are supported by :program:`flux jobs`:

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

**!d**
convert a timestamp to a Python datetime object. This allows datetime
Expand Down
5 changes: 5 additions & 0 deletions src/bindings/python/flux/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ def convert_field(self, value, conv):
else:
raise
elif conv == "D":
# the JobInfo class initializes many timestamps to 0.0 if
# they are not available. Treat epoch time as special case
# and just return empty string.
if not value:
return ""
# As above, but convert to ISO 8601 date time string.
try:
value = datetime.fromtimestamp(value).strftime("%FT%T")
Expand Down
1 change: 1 addition & 0 deletions t/flux-jobs/tests/issue#5827/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D conversion flag outputs empty string on epoch timestamp
1 change: 1 addition & 0 deletions t/flux-jobs/tests/issue#5827/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{t_run},{t_run!D}
1 change: 1 addition & 0 deletions t/flux-jobs/tests/issue#5827/input
Original file line number Diff line number Diff line change
@@ -0,0 +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}
1 change: 1 addition & 0 deletions t/flux-jobs/tests/issue#5827/output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0,

0 comments on commit 99ea1fc

Please sign in to comment.