Skip to content

Commit 967c521

Browse files
authored
Merge pull request #873 from benoitf/RAMALAMA-871
fix: use iso8601 for JSON modified field
2 parents cb4ea96 + 3082ad9 commit 967c521

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

ramalama/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import platform
66
import subprocess
7-
import time
7+
from datetime import datetime, timezone
88
from pathlib import Path
99

1010
import ramalama.oci
@@ -547,7 +547,8 @@ def _list_models(args):
547547
else:
548548
name = str(path).replace("/", "://", 1)
549549
file_epoch = path.lstat().st_mtime
550-
modified = int(time.time() - file_epoch)
550+
# convert to iso format
551+
modified = datetime.fromtimestamp(file_epoch, tz=timezone.utc).isoformat()
551552
size = get_size(path)
552553

553554
# Store data for later use
@@ -607,26 +608,25 @@ def list_cli(args):
607608
size_width = len("SIZE")
608609
for model in sorted(models, key=lambda d: d['name']):
609610
try:
610-
modified = human_duration(model["modified"]) + " ago"
611+
delta = int(datetime.now(timezone.utc).timestamp() - datetime.fromisoformat(model["modified"]).timestamp())
612+
modified = human_duration(delta) + " ago"
613+
model["modified"] = modified
611614
except TypeError:
612-
modified = model["modified"]
615+
pass
613616
# update the size to be human readable
614617
model["size"] = human_readable_size(model["size"])
615618
name_width = max(name_width, len(model["name"]))
616-
modified_width = max(modified_width, len(modified))
619+
modified_width = max(modified_width, len(model["modified"]))
617620
size_width = max(size_width, len(model["size"]))
618621

619622
if not args.quiet and not args.noheading and not args.json:
620623
print(f"{'NAME':<{name_width}} {'MODIFIED':<{modified_width}} {'SIZE':<{size_width}}")
621624

622625
for model in models:
623-
try:
624-
modified = human_duration(model["modified"]) + " ago"
625-
except TypeError:
626-
modified = model["modified"]
627626
if args.quiet:
628627
print(model["name"])
629628
else:
629+
modified = model['modified']
630630
print(f"{model['name']:<{name_width}} {modified:<{modified_width}} {model['size'].upper():<{size_width}}")
631631

632632

ramalama/oci.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import subprocess
44
import tempfile
5+
from datetime import datetime
56

67
import ramalama.annotations as annotations
78
from ramalama.common import MNT_FILE, engine_version, exec_cmd, perror, run_cmd
@@ -112,6 +113,11 @@ def list_models(args):
112113
del model["id"]
113114

114115
models += list_manifests(args)
116+
for model in models:
117+
# Convert to ISO 8601 format
118+
parsed_date = datetime.fromisoformat(model["modified"].replace(" UTC", "").replace(" ", "T"))
119+
model["modified"] = parsed_date.isoformat()
120+
115121
return models
116122

117123

0 commit comments

Comments
 (0)