slashmili / python-jalali

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

[strptime] Invalid regex for format detection #41

Closed alimo closed 6 years ago

alimo commented 6 years ago

Currently ([%a-zA-Z]{2}) regex is used to find format codes. It detects any two consecutive English characters (including percent sign) which will cause an error if the format contains another English character as separator (Like how javascript Date object uses 'T' to separate date from time). This method should be using (%[a-zA-Z]) regex to detect %-char pairs.

slashmili commented 6 years ago

@alimo thanks for reporting it. Could you create a failing test case?

alimo commented 6 years ago

This fails:

date_string = "1363-6-6T12:13:14"
date_format = "%Y-%m-%dT%H:%M:%S"
dt1 = jdatetime.datetime.strptime(date_string, date_format)
dt2 = jdatetime.datetime(1363, 6, 6, 12, 13, 14)

self.assertEqual(dt1, dt2)

I can submit a PR if that's ok with you.