2023-12-21 08:49:31 -05:00
|
|
|
"""This is a list of various utility functions used in PyZipline."""
|
2023-12-19 05:36:18 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
def convert_str_to_datetime(date_string: str) -> datetime:
|
2023-12-20 18:13:55 -05:00
|
|
|
"""Converts a Zipline date string to a datetime object
|
2023-12-19 05:36:18 -05:00
|
|
|
|
2023-12-20 17:53:00 -05:00
|
|
|
Args:
|
2023-12-21 08:49:31 -05:00
|
|
|
date_string: String to convert
|
2023-12-20 17:53:00 -05:00
|
|
|
|
|
|
|
Returns:
|
2023-12-21 08:49:31 -05:00
|
|
|
datetime: Datetime object
|
2023-12-19 05:36:18 -05:00
|
|
|
"""
|
|
|
|
return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')
|
2023-12-21 15:47:28 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2023-12-22 13:48:46 -05:00
|
|
|
return datetime.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00')
|