Skip to content

Commit c14c92f

Browse files
zblenessbact
andcommitted
Apply suggestions from code review
Co-authored-by: Arthit Suriyawongkul <arthit@gmail.com> Signed-off-by: Zalan Blenessy <zalan.blenessy@volvocars.com>
1 parent 01b9b79 commit c14c92f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/spdx_tools/spdx/datetime_conversions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ def datetime_from_str(date_str: str) -> datetime:
1616
# The secondFrag allows fractional second notation as well.
1717
# normalize to micro seconds so that we can use %f with strptime
1818
date_str = re.sub(r"\.(\d{1,6})\d*Z$", r".\1Z", date_str)
19-
return datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ") # raises ValueError if format does not match
19+
warnings.warn(
20+
"Invalid date format. Expected YYYY-MM-DDThh:mm:ssZ "
21+
"Sub-second fractions have been discarded",
22+
category=UserWarning,
23+
stacklevel=2
24+
)
25+
return datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ") # raises ValueError if format does not match
2026

2127

2228
def datetime_to_iso_string(date: datetime) -> str:

0 commit comments

Comments
 (0)