diff --git a/stock_indicators/_cstypes/datetime.py b/stock_indicators/_cstypes/datetime.py index 1a2ee63a..ac9a6715 100644 --- a/stock_indicators/_cstypes/datetime.py +++ b/stock_indicators/_cstypes/datetime.py @@ -20,6 +20,8 @@ class DateTime: 3/26/2021 10:02:22 PM """ def __new__(cls, datetime: PyDateTime) -> CsDateTime: + if datetime.tzinfo is not None: + datetime = datetime.astimezone(PyDateTime.timezone.utc) return CsDateTime.Parse(datetime.isoformat(timespec='seconds')) diff --git a/tests/common/test_cstype_conversion.py b/tests/common/test_cstype_conversion.py index 63cf6e4d..6b158c61 100644 --- a/tests/common/test_cstype_conversion.py +++ b/tests/common/test_cstype_conversion.py @@ -46,7 +46,7 @@ def test_auto_conversion_from_double_to_float(self): def test_quote_constructor_retains_timezone(self): dt = datetime.fromisoformat('2000-03-26 23:00+0000') q = Quote( - date=dt, + date=dt.astimezone(datetime.timezone.utc), open=Decimal('23'), high=Decimal('26'), low=Decimal('20'),