Skip to content

Commit

Permalink
Update DateTime class and to_pydatetime function to preserve time…
Browse files Browse the repository at this point in the history
…zone information

* Update `DateTime` class to preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects
* Update `to_pydatetime` function to handle different date formats and retain timezone information when converting C# `System.DateTime` objects to Python `datetime` objects
* Add `test_quote_constructor_handles_various_date_formats` method to verify that the `Quote` class can handle various date formats
  • Loading branch information
DaveSkender committed Jan 1, 2025
1 parent c4b5d70 commit be18867
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 6 deletions.
4 changes: 0 additions & 4 deletions stock_indicators/_cstypes/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class DateTime:
3/26/2021 10:02:22 PM
"""
def __new__(cls, datetime: PyDateTime) -> CsDateTime:
if datetime.tzinfo is not None:
datetime = datetime.astimezone(PyTimezone.utc)
return CsDateTime.Parse(datetime.isoformat(timespec='seconds'))


Expand All @@ -33,8 +31,6 @@ def to_pydatetime(cs_datetime: CsDateTime) -> PyDateTime:
cs_datetime : `System.DateTime` of C#.
"""
py_datetime = PyDateTime.fromisoformat(cs_datetime.ToString("o", CsCultureInfo.InvariantCulture))
if py_datetime.tzinfo is not None:
py_datetime = py_datetime.astimezone(py_datetime.tzinfo)
return py_datetime

if not hasattr(PyDateTime, 'timezone'):
Expand Down
2 changes: 0 additions & 2 deletions stock_indicators/indicators/common/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def _get_date(quote):
return to_pydatetime(quote.Date)

def _set_date(quote, value):
if value.tzinfo is not None:
value = value.astimezone(timezone.utc)
quote.Date = CsDateTime(value)

def _get_open(quote):
Expand Down

0 comments on commit be18867

Please sign in to comment.