Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130718: Normalize edge cases in datetime.timestamp and datetime.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
donBarbos committed Mar 2, 2025
commit c836cb3dcbc19533e7c93f438b6fc3c6d968c256
12 changes: 12 additions & 0 deletions 12 Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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 test_astimezone_max and test_astimezone_min. We can test the values near datetime.min and datetime.max separately, and use self.subTest to try a few different values for time zone.

I'm not sure if @support.run_with_tz can be parameterized, but if it can we should try it on a few different time zones.

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):
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.