Skip to content

Commit 9a3e128

Browse files
[issue-718] ignore microseconds during datetime conversion to ISO string
Signed-off-by: Armin Tänzer <[email protected]>
1 parent 56fd602 commit 9a3e128

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/spdx_tools/spdx/datetime_conversions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ def datetime_to_iso_string(date: datetime) -> str:
1616
"""
1717
Return an ISO-8601 representation of a datetime object.
1818
"""
19+
if date.microsecond != 0:
20+
date = date.replace(microsecond=0) # SPDX does not support microseconds
21+
1922
return date.isoformat() + "Z"

tests/spdx/test_datetime_conversions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def test_datetime_to_iso_string():
1212
assert datetime_to_iso_string(datetime(2022, 12, 13, 1, 2, 3)) == "2022-12-13T01:02:03Z"
1313

1414

15+
def test_datetime_to_iso_string_with_microseconds():
16+
assert datetime_to_iso_string(datetime(2022, 12, 13, 1, 2, 3, 666666)) == "2022-12-13T01:02:03Z"
17+
18+
1519
def test_datetime_from_str():
1620
date_str = "2010-03-04T05:45:11Z"
1721

0 commit comments

Comments
 (0)