File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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
7182def convert_camel_case (dct : Dict [str , Any ]) -> Dict [str , Any ]:
You can’t perform that action at this time.
0 commit comments