Skip to content
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

Non-zero padding formats #4

Open
jedzill4 opened this issue Jul 22, 2022 · 1 comment
Open

Non-zero padding formats #4

jedzill4 opened this issue Jul 22, 2022 · 1 comment

Comments

@jedzill4
Copy link

Hi and thank you for the nice work!
I'm having an issue with non-zero padding datetime extraction, for example matching a 1/11/2017 string with format %-d/%m/%Y. The RegexGenerator class match correctly the pattern, but the DatetimeExtractor cannot extract the pattern as datetime object.

My problem is in the __parse_match_into_maybe_datetime function, in the strptime conversion. I'm using python 3.10 on linux and strptime doesn't accept the %-d directive, but can handle correctly the %d even when there is no zero padding.
From what I have read may be a platform issue and work without problems on other python implementation (anaconda maybe?). The workaround that I found is to replace all %- to their standard version (e.i. %-d to %d)

@stephen-zhao
Copy link
Owner

Thanks for reporting this and taking a look.

Python's strptime basically calls the C library underneath the hood. We can take a look at the linux docs for their version: https://man7.org/linux/man-pages/man3/strftime.3.html

It seems that the - extension is available for Glibc implementation, but are not POSIX-compliant. Furthermore, this cheatsheet claims that the Windows implementation can handle # in its place. However, it would be best to avoid platform-specific directives if possible, and if not possible to handle them individually.

That being said, it seems like the python strptime does handle zero-padding automatically as you mention, according to Note 9 on this page: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

We're open to a PR if you would like to make the change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants