24 lines
686 B
Python
24 lines
686 B
Python
"""This is a list of various utility functions used in PyZipline."""
|
|
from datetime import datetime
|
|
|
|
def convert_str_to_datetime(date_string: str) -> datetime:
|
|
"""Converts a Zipline date string to a datetime object
|
|
|
|
Args:
|
|
date_string: String to convert
|
|
|
|
Returns:
|
|
datetime: Datetime object
|
|
"""
|
|
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')
|