Skip to content

Commit 12da523

Browse files
mbrinkhoffgreenbonebot
authored andcommitted
Fix: format_date timespec and fallback timezone
1 parent 3550550 commit 12da523

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pontos/nvd/api.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,28 @@ def now() -> datetime:
5555
return datetime.now(tz=timezone.utc)
5656

5757

58-
def format_date(date: datetime) -> str:
58+
def format_date(
59+
date: datetime,
60+
fallback_timezone: timezone = timezone.utc,
61+
timespec: str = "milliseconds",
62+
) -> str:
5963
"""
6064
Format date matching to NVD api
6165
6266
Args:
6367
date: Date to format
68+
fallback_timezone: The timezone to attach if date
69+
is not timezone aware
70+
timespec: Timespec to pass to datetime.isoformat
6471
6572
Returns:
6673
Formatted date as string
6774
"""
68-
return date.isoformat(timespec="seconds")
75+
76+
if not date.tzinfo:
77+
date = date.astimezone(fallback_timezone)
78+
79+
return date.isoformat(timespec=timespec)
6980

7081

7182
def convert_camel_case(dct: Dict[str, Any]) -> Dict[str, Any]:

0 commit comments

Comments
 (0)