Skip to content

gh-137165: Standardized non-zero-padded date formatting for datetime.strftime#139088

Open
F0RRZZ wants to merge 19 commits intopython:mainfrom
F0RRZZ:issue-137165
Open

gh-137165: Standardized non-zero-padded date formatting for datetime.strftime#139088
F0RRZZ wants to merge 19 commits intopython:mainfrom
F0RRZZ:issue-137165

Conversation

@F0RRZZ
Copy link
Contributor

@F0RRZZ F0RRZZ commented Sep 18, 2025

Previously, using non-zero-padded directives (e.g., %-d) in strftime caused test failures on Windows and Android (x86_64), while other platforms worked as expected.
This has been fixed by manually handling such specifiers on these platforms.
Corresponding tests have been added to strftime tests.

On Windows using non-zero-padded directives raised ValueError.

On Android (x86_64) dicrectives were not replaced:
Screenshot 2025-09-18 at 03 45 28

@F0RRZZ F0RRZZ changed the title gh-137165: Add non-zero-padded Windows support for datetime.strftime gh-137165: Standardized non-zero-padded date formatting for datetime.strftime Sep 18, 2025
@mhsmith
Copy link
Member

mhsmith commented Sep 18, 2025

!buildbot iOS

@bedevere-bot

This comment was marked as outdated.

@mhsmith
Copy link
Member

mhsmith commented Sep 18, 2025

The implementation looks reasonable, but this should also be covered in the documentation, along with the fact that the - flag apparently has no effect on %y on Apple platforms.

@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Sep 18, 2025

@mhsmith I adapted the tests for iOS and added documentation in the strftime notes.

@F0RRZZ F0RRZZ requested a review from mhsmith September 18, 2025 14:39
@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Sep 18, 2025

@StanFromIreland Made all changes

@mhsmith

This comment was marked as resolved.

@bedevere-bot

This comment was marked as outdated.

@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Sep 19, 2025

@mhsmith All done, but TSan seems to be stuck

@F0RRZZ F0RRZZ requested a review from mhsmith September 19, 2025 05:46
@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 25, 2025
@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Sep 25, 2025

@mhsmith Fixed, lets test

@F0RRZZ F0RRZZ requested a review from mhsmith September 25, 2025 19:33
@mhsmith mhsmith added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Sep 26, 2025
@bedevere-bot

This comment was marked as outdated.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Sep 26, 2025
Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

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

I've started the refleaks tests, but I suggest you work out how to run them on your own machine rather than requiring a team member to rerun them on every commit. I don't know exactly how to do this, but it looks like it involves the -R option of python -m test. See the buildbot configuration for more details.

@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Sep 26, 2025

@mhsmith Thanks! I'm running them on my machine, I just thought they needed to be run here as well to make sure everything works

@F0RRZZ F0RRZZ requested a review from mhsmith September 27, 2025 21:29
Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

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

Thanks, this looks much better. Just a few stylistic comments:

@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Oct 1, 2025

@mhsmith All done

@F0RRZZ F0RRZZ requested a review from mhsmith October 1, 2025 21:05
@mhsmith mhsmith added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 1, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @mhsmith for commit 9212a5a 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F139088%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 1, 2025
Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

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

@pganssle: I think this is ready for final review.

@F0RRZZ
Copy link
Contributor Author

F0RRZZ commented Nov 5, 2025

@pganssle Just a gentle ping on this PR review🙏

def _make_dash_replacement(ch, timetuple):
fmt = '%' + ch
val = _time.strftime(fmt, timetuple)
return val.lstrip('0') or '0'
Copy link
Member

Choose a reason for hiding this comment

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

Will this not eat the dash for unsupported codes, e.g what will %-# do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an explicit check to ensure that only valid format specifiers (as documented in Doc/library/datetime.rst) are passed on Windows and Android.
For other platforms I didn’t add this validation because they currently handle unsupported specifiers silently—just echoing them back. For example for "%-#":

  • raises an error on Windows,
  • returns "#" on macOS/FreeBSD,
  • and returns "%-#" on Linux.

Copy link
Member

Choose a reason for hiding this comment

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

So, removing one inconsistency you introduce another? I would expect them all to be the same as on linux, why are you raising an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the ValueError and unified the behavior for unsupported specifiers like on Linux.
Now, for example, when entering "%-#" on all systems, "%-#" will be displayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement Proposal: Standardized Support for Non-Zero-Padded Day and Month Formatting in datetime.strftime

4 participants