24 lines
685 B
Python
24 lines
685 B
Python
"""This is a list of various utility functions used in PyZipline."""
|
|
from datetime import datetime as dtime
|
|
|
|
def convert_str_to_datetime(date_string: str) -> dtime:
|
|
"""Converts a Zipline date string to a datetime object
|
|
|
|
Args:
|
|
date_string: String to convert
|
|
|
|
Returns:
|
|
datetime: Datetime object
|
|
"""
|
|
return dtime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%fZ')
|
|
|
|
def convert_datetime_to_str(datetime: dtime) -> str:
|
|
"""Converts a datetime object to a Zipline (`ISO 8601`) date string
|
|
|
|
Args:
|
|
datetime: Datetime to convert
|
|
|
|
Returns:
|
|
str: Converted date string
|
|
"""
|
|
return datetime.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00')
|