Skip to content

gh-133940: test_strftime incorrectly calculates expected week #134281

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

Merged
merged 1 commit into from
May 20, 2025

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant

Conversation

GGyll
Copy link
Contributor

@GGyll GGyll commented May 19, 2025

self.jan1 results to January 1st 2024 if set to Irish Time Zone. By letting time.mktime correct the tm_wday and tm_isdst values we can prevent this and we will always get the current year.

@GGyll GGyll requested review from pganssle and abalkin as code owners May 19, 2025 20:47
@python-cla-bot
Copy link

python-cla-bot bot commented May 19, 2025

All commit authors signed the Contributor License Agreement.

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label May 19, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 19, 2025

Most changes to Python blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@GGyll
Copy link
Contributor Author

GGyll commented May 19, 2025

This is a test change so no NEWS entry needed

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Sprint 2024 May 19, 2025
@gpshead gpshead removed this from Sprint 2024 May 19, 2025
StanFromIreland
Comment on lines +42 to +56
jan1 = time.struct_time(
(
now.tm_year, # Year
1, # Month (January)
1, # Day (1st)
0, # Hour (0)
0, # Minute (0)
0, # Second (0)
-1, # tm_wday (will be determined)
1, # tm_yday (day 1 of the year)
-1, # tm_isdst (let the system determine)
)
)
# use mktime to get the correct tm_wday and tm_isdst values
self.jan1 = time.localtime(time.mktime(jan1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jan1 = time.struct_time(
(
now.tm_year, # Year
1, # Month (January)
1, # Day (1st)
0, # Hour (0)
0, # Minute (0)
0, # Second (0)
-1, # tm_wday (will be determined)
1, # tm_yday (day 1 of the year)
-1, # tm_isdst (let the system determine)
)
)
# use mktime to get the correct tm_wday and tm_isdst values
self.jan1 = time.localtime(time.mktime(jan1))
self.jan1 = time.localtime(time.mktime((now[0], 1, 1, 0, -1, 1, -1)))

Why not just all on one line like before, it seems clear to me, and this is a test after all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I like the long version myself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is overkill and distracting, if you are looking at these tests you are probably familiar with struct_time anyway.

StanFromIreland
Copy link
Contributor

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it works. I changed the buildbot config so running it here will be of no use.

@gpshead
Copy link
Member

gpshead commented May 19, 2025

!buildbot raspbian

@gpshead gpshead added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 19, 2025
@StanFromIreland
Copy link
Contributor

StanFromIreland commented May 19, 2025

I changed the buildbot config so running it here will be of no use.

@gpshead There is no point unless you have changed the config on yours? It seems buildbot is down right now too.

@gpshead gpshead added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 20, 2025
@gpshead gpshead merged commit e3dda8f into python:main May 20, 2025
56 checks passed
@miss-islington-app
Copy link

Thanks @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 20, 2025
…ythonGH-134281)

Let the system determine the correct tm_wday and tm_isdst.
(cherry picked from commit e3dda8f)

Co-authored-by: Gustaf <79180496+GGyll@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 20, 2025
…ythonGH-134281)

Let the system determine the correct tm_wday and tm_isdst.
(cherry picked from commit e3dda8f)

Co-authored-by: Gustaf <79180496+GGyll@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 20, 2025

3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 20, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 20, 2025

3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 20, 2025
gpshead pushed a commit that referenced this pull request May 20, 2025
#134302)

GH-134281)

Let the system determine the correct tm_wday and tm_isdst.
(cherry picked from commit e3dda8f)

Co-authored-by: Gustaf <79180496+GGyll@users.noreply.github.com>
gpshead pushed a commit that referenced this pull request May 20, 2025
#134301)

GH-134281)

Let the system determine the correct tm_wday and tm_isdst.
(cherry picked from commit e3dda8f)

Co-authored-by: Gustaf <79180496+GGyll@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 test-with-buildbots Test PR w/ buildbots; report in status section skip news sprint tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant

3 participants

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant