-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Retain timezone awareness #410
base: main
Are you sure you want to change the base?
Conversation
Fixes #409 Modify the `DateTime` class in `stock_indicators/_cstypes/datetime.py` to use `datetime.isoformat(timespec='seconds')` to retain timezone information. Update the `to_pydatetime` function in `stock_indicators/_cstypes/datetime.py` to handle timezone information correctly. Add a test in `tests/common/test_cstype_conversion.py` to verify that the `Quote` constructor retains timezone information. * Add `test_quote_constructor_retains_timezone` method to test the `Quote` constructor with timezone-aware datetime objects. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/facioquo/stock-indicators-python/issues/409?shareId=XXXX-XXXX-XXXX-XXXX).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
…atetime objects * Add a check in `_set_date` to convert timezone-aware datetime objects to UTC
* Import `timezone` from `datetime` * Check if `value` has timezone information and convert it to UTC if it does * Ensure `quote.Date` is set to `CsDateTime(value)`
… method to handle timezone-aware datetime objects * **`stock_indicators/_cstypes/datetime.py`** - Update `DateTime` class to convert timezone-aware datetime objects to UTC - Update `to_pydatetime` function to retain timezone information when converting C# `System.DateTime` objects back to Python `datetime` objects * **`tests/common/test_cstype_conversion.py`** - Add `test_quote_constructor_retains_timezone` method to verify the retention of timezone information in the `Quote` constructor
… datetime objects * Add a check in `_set_date` to convert timezone-aware datetime objects to UTC before setting the `Date` property
…ne-aware datetime objects * Preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects * Handle timezone-aware datetime objects when converting C# `System.DateTime` objects to Python `datetime` objects * Ensure type object `datetime.datetime` has attribute `timezone` if missing Add test cases to verify handling of various date formats in `Quote` class * Add `test_quote_constructor_handles_various_date_formats` method to verify retention of timezone information in `Quote` constructor * Add test cases to verify `Quote` class can handle various date formats
…ne-aware datetime objects * Preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects * Handle timezone-aware datetime objects when converting C# `System.DateTime` objects to Python `datetime` objects * Ensure type object `datetime.datetime` handles scenarios where attribute `timezone` is missing Update `_get_date` and `_set_date` functions in `Quote` class to handle timezone-aware datetime objects * Handle timezone-aware datetime objects without normalizing them to UTC * Ensure `Quote` class can handle timezone-aware datetime objects when initializing and setting the `date` property Add tests for timezone handling in `Quote` class * Add `test_quote_constructor_retains_timezone` to verify retention of timezone information in `Quote` constructor * Add test cases to verify `Quote` class and related functions can handle various date formats
…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
…ne information * Preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects * Handle different date formats and retain timezone information when converting C# `System.DateTime` objects to Python `datetime` objects * Avoid setting the timezone attribute directly on the datetime class and handle timezone-aware datetime objects correctly using existing methods
…tetime objects * **`stock_indicators/_cstypes/datetime.py`** - Remove timezone normalization to UTC in `DateTime` class - Preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects * **`stock_indicators/indicators/common/quote.py`** - Add timezone handling in `_set_date` function to convert to UTC if timezone-aware - Ensure `Quote` class handles timezone-aware datetime objects without normalizing to UTC
…ne information and various date formats * **DateTime class**: - Preserve timezone information when converting Python `datetime` objects to C# `System.DateTime` objects - Avoid setting the timezone attribute directly on the datetime class * **to_pydatetime function**: - Handle different date formats and retain timezone information when converting C# `System.DateTime` objects to Python `datetime` objects * **Tests**: - Add `test_quote_constructor_retains_timezone` method to verify retention of timezone information in the `Quote` constructor - Add `test_quote_constructor_handles_various_date_formats` method to verify handling of various date formats in the `Quote` class
…timezone-aware datetime objects * Add check for `tzinfo` attribute in `_set_date` function and adjust timezone accordingly * Modify test cases in `test_cstype_conversion.py` to verify correct handling of timezone information in `Quote` constructor
… and convert them to UTC * Remove unnecessary timezone conversion logic
* Remove unnecessary timezone conversion in `__new__` method
* Add "github.copilot" to the extensions list * Update the `test` task to use single quotes instead of double quotes * Ensure the Dockerfile supports all the dependencies required by GitHub Copilot Update `quote.py` to handle timezone-aware datetime objects * Modify `_get_date` and `_set_date` functions to handle timezone-aware datetime objects and convert them to UTC Update `datetime.py` to retain timezone information * Update `DateTime` class to retain timezone information when converting Python `datetime` objects to C# `System.DateTime` objects * Update `to_pydatetime` function to retain timezone information when converting C# `System.DateTime` objects back to Python `datetime` objects Update `test_quote.py` to verify timezone retention * Add `test_quote_constructor_retains_timezone` method to verify the retention of timezone information in the `Quote` constructor * Add `test_quote_constructor_handles_various_date_formats` method to verify that the `Quote` class can handle various date formats
* **test_cstype_conversion.py**: Remove unused `timezone` import in `test_quote_constructor_retains_timezone` and `test_quote_constructor_handles_various_date_formats` methods. * **test_quote.py**: Remove unused `timezone` import in `test_quote_constructor_retains_timezone` and `test_quote_constructor_handles_various_date_formats` methods. Add blank lines for better readability.
Signed-off-by: Dave Skender <8432125+DaveSkender@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
@LeeDongGeon1996 this is still essentially broken. I'll keep working on it, but I could use another set of eyes reviewing it too if you have a chance. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Dave Skender <8432125+DaveSkender@users.noreply.github.com>
Modify `DateTime` class to use `datetime.isoformat(timespec='seconds')` to retain timezone information Update `to_pydatetime` function to handle timezone information correctly Add tests to verify that the `Quote` constructor retains timezone information * Add `test_quote_constructor_retains_timezone` method to `TestCsTypeConversion` class * Import `Quote` class from `stock_indicators.indicators.common.quote` * Add assertions to check timezone and time of `Quote` date --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/facioquo/stock-indicators-python/pull/410?shareId=XXXX-XXXX-XXXX-XXXX).
@@ -30,4 +30,4 @@ def to_pydatetime(cs_datetime: CsDateTime) -> PyDateTime: | |||
Parameter: | |||
cs_datetime : `System.DateTime` of C#. | |||
""" | |||
return PyDateTime.fromisoformat(cs_datetime.ToString("s", CsCultureInfo.InvariantCulture)) | |||
return PyDateTime.fromisoformat(cs_datetime.ToString("o", CsCultureInfo.InvariantCulture)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o
format won't work according to #310
Fixes #409
Modify the
DateTime
class instock_indicators/_cstypes/datetime.py
to usedatetime.isoformat(timespec='seconds')
to retain timezone information.Update the
to_pydatetime
function instock_indicators/_cstypes/datetime.py
to handle timezone information correctly.Add a test in
tests/common/test_cstype_conversion.py
to verify that theQuote
constructor retains timezone information.test_quote_constructor_retains_timezone
method to test theQuote
constructor with timezone-aware datetime objects.For more details, open the Copilot Workspace session.