slashmili / python-jalali

Jalali calendar binding for Python based on Python's datetime module
http://pypi.python.org/pypi/jdatetime/
Other
335 stars 46 forks source link

feat(strptime): handle `%y` and `%f` directives #106

Closed 5j9 closed 2 years ago

5j9 commented 2 years ago

Rewrite strptime to make the code more clear.

This implementation assumes 14th century for 00 <= %y <= 68 and 13th century for 69 <= %y <= 99.

This patch also fixes a bug in strptime where it could not handle special characters ? in the format string.

Tests where added.

closes #100

5j9 commented 2 years ago

If you're curious, testing on python 3.10, there is no performance degradation after this patch:

$ # on main branch
$ python -m timeit 'import jdatetime; jdatetime.datetime.strptime("[1363-6-6] (12-13-14)", "[%Y-%m-%d] (%H-%M-%S)")'
10000 loops, best of 5: 37 usec per loop

$ # on this branch
$ python -m timeit 'import jdatetime; jdatetime.datetime.strptime("[1363-6-6] (12-13-14)", "[%Y-%m-%d] (%H-%M-%S)")'
10000 loops, best of 5: 35.3 usec per loop
5j9 commented 2 years ago

I found a bug. I'll reopen when it's ready.