-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Construct Timestamp with tz correctly near DST border #21407
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
Changes from 1 commit
c5566d5
5d207ea
f4eb827
c8dabe1
795cc39
f171f9f
7e183a8
3dd00d7
ae9dc7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,6 +350,10 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz, | |
# sort of a temporary hack | ||
if ts.tzinfo is not None: | ||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): | ||
# tz.localize does not correctly localize Timestamps near DST | ||
if hasattr(ts, 'to_pydatetime'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Elsewhere we've used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @jbrockmendel. Seems clearer than trying to get |
||
nanos += ts.nanosecond | ||
ts = ts.to_pydatetime() | ||
ts = tz.normalize(ts) | ||
obj.value = pydatetime_to_dt64(ts, &obj.dts) | ||
obj.tzinfo = ts.tzinfo | ||
|
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.
This check might be superfluous since
datetimes
natively have theastimezone
method. Then this whole block might be able to be simplified.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.
hmm, you can try that and see if it works. maybe add a comment anyhow