cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-121237: Add %:z directive to strptime

Open LucasEsposito opened this issue 1 year ago • 2 comments

  • Issue: gh-121237

The directive %:z was introduced in Python 3.12. It works as expected on strftime but fails on strptime, since it was not explicitely implemented there as a new directive.

This PR adds consistency across strftime and strptime (by implementing %:z on the later), while keeping backwards compatibility.

  • %z and %:z work as expected in strftime, so nothing was changed there.
  • %z does what it should in strptime (accepting strings formatted according to that directive), while in addition allowing %:z-formatted strings too. The later part of the behavior is a bug but at this point we should keep this behavior for backwards compatibility. I documented the issue in the docs, code and tests.
  • %:z failed when used in strptime. I implemented %:z directive to parse %:z-formatted strings and added the appropiate tests and changes in the docs.

📚 Documentation preview 📚: https://cpython-previews--122142.org.readthedocs.build/

LucasEsposito avatar Jul 22 '24 22:07 LucasEsposito

  • The later part of the behavior is a bug but at this point we should keep this behavior for backwards compatibility. I documented the issue in the docs, code and tests.

I don't think it's a bug. IMHO it's a legitimate part of the module's interface and behavior (even if not to be so useful after merging this PR).

And I agree that this PR brings an improvement. :)

zuo avatar Oct 04 '24 19:10 zuo

What do all the itertools changes have to do with strptime?

StanFromIreland avatar Mar 20 '25 20:03 StanFromIreland

@LucasEsposito Thank you for PR, but could you please reply if you're going to continue working on it? (it's just been exactly a year since your last activity in current thread) To clarify that other people can continue working.

donbarbos avatar Jul 21 '25 10:07 donbarbos

@donBarbos

I've been meaning to continue working on this for a while, but it just hasn’t happened.

Given that I’m currently short on time and this seems to be blocking others from contributing, I’ll step back and leave the issue open so that anyone interested can pick it up.

LucasEsposito avatar Jul 21 '25 12:07 LucasEsposito

Closing this in favor of #136961, which is now merged! Thanks everyone! 🎉

pganssle avatar Sep 19 '25 09:09 pganssle