feat: added a util function for converting datetimes to iso 8601 strings

This commit is contained in:
Seaswimmer 2023-12-21 15:47:28 -05:00
parent 48523895e9
commit eb9640e54f
Signed by: cswimr
GPG key ID: 1EBC234EEDA901AE

View file

@ -11,3 +11,14 @@ def convert_str_to_datetime(date_string: str) -> datetime:
datetime: Datetime object datetime: Datetime object
""" """
return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ') return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')
def convert_datetime_to_str(datetime: datetime) -> str:
"""Converts a datetime object to a Zipline (`ISO 8601`) date string
Args:
datetime: Datetime to convert
Returns:
str: Converted date string
"""
return datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')