Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-130718: Normalize edge cases indatetime.timestamp
anddatetime.astimezone
#130752
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3122,6 +3122,18 @@ def dst(self, dt): return 1 | ||
with self.assertRaises(TypeError): | ||
dt_broken.astimezone() | ||
dt_big = self.theclass(9999, 12, 31, 23, 59, 59) | ||
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. I don't love that the original style violates the one-assert-per-test style, and we should probably not continue that. Let's move this into its own method, like I'm not sure if | ||
dt_big_utc = dt_big.replace(hour=19, | ||
tzinfo=timezone(timedelta(hours=-4), 'EDT')) | ||
self.assertEqual(dt_big_utc, | ||
dt_big.replace(tzinfo=timezone.utc).astimezone()) | ||
other_tz = timezone(timedelta(hours=+4), '+04') | ||
dt_other_tz = dt_big.replace(tzinfo=other_tz) | ||
dt_utc_tz = dt_big.replace(tzinfo=timezone.utc) | ||
self.assertEqual(dt_other_tz, dt_other_tz.astimezone(tz=other_tz)) | ||
self.assertEqual(dt_utc_tz, dt_utc_tz.astimezone(tz=timezone.utc)) | ||
def test_subclass_datetime(self): | ||
class C(self.theclass): | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5415,6 +5415,7 @@ | ||
{ | ||
struct tm local_time; | ||
time_t t; | ||
long long old_u = u; | ||
u -= epoch; | ||
t = u; | ||
if (t != u) { | ||
@@ -5424,7 +5425,14 @@ | ||
} | ||
if (_PyTime_localtime(t, &local_time) != 0) | ||
return -1; | ||
// Check edge cases | ||
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. This should be more specific — what this code does is very opaque, so we should have a "why" comment here. Something like "When the year is outside the allowed year boundaries, return the original utc timestamp because ". | ||
int year = local_time.tm_year + 1900; | ||
if (year < MINYEAR || year > MAXYEAR) { | ||
Py_DECREF(year); | ||
Check warning on line 5432 in Modules/_datetimemodule.c
| ||
donBarbos marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return old_u; | ||
} | ||
return utc_to_seconds(year, | ||
local_time.tm_mon + 1, | ||
local_time.tm_mday, | ||
local_time.tm_hour, | ||
Uh oh!
There was an error while loading.Please reload this page.