arkn98 commented on PR #2996:
URL: https://github.com/apache/cassandra/pull/2996#issuecomment-1863000630

   @bschoening Thanks for the review!
   
   No. This is because when you call `astimezone()` on a naive datetime object, 
it assumes the object to be in the system timezone.
   
   > If self is naive, it is presumed to represent time in the system timezone.
   
   But, the Datastax driver gives out naive UTC datetime objects. Here's an 
example that illustrates the problem. Assume it is `00:00` in New York, which 
corresponds to `05:00` in UTC.
   
   ```python
   >>> utc_naive = datetime.datetime(2023, 11, 25, 5, 0, 0)
   >>> print(utc_naive)                   # this is what we get from the driver
   2023-11-25 05:00:00
   >>> print(utc_naive.astimezone())
   2023-11-25 05:00:00-05:00              # which is wrong; it should be 12AM 
in New York
   
   
   >>> utc_aware = utc_naive.replace(tzinfo=timezone.utc)
   >>> print(utc_aware)
   2023-11-25 05:00:00+00:00
   >>> print(utc_aware.astimezone())
   2023-11-25 00:00:00-05:00             # this is correct
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to