PyZipline/pyzipline/utils.py
SeaswimmerTheFsh bf0f556278
Some checks failed
Pylint / Pylint (3.12) (push) Failing after 34s
fix: pylint fixes
2023-12-22 13:56:50 -05:00

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')