PyZipline/pyzipline/utils.py

25 lines
686 B
Python
Raw Normal View History

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:
"""Converts a Zipline date string to a datetime object
2023-12-19 05:36:18 -05:00
Args:
2023-12-21 08:49:31 -05:00
date_string: String to convert
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')
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')