tkcalendar icon indicating copy to clipboard operation
tkcalendar copied to clipboard

DateEntry date_pattern parsing in yyyyMMdd format fails

Open skmagiik opened this issue 2 years ago • 2 comments

DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyyMMdd')

Other variants attempted: DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyy-MMdd') DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyyMM-dd')

Succeeds: DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyy-MM-dd')

Error message:

Exception in Tkinter callback Traceback (most recent call last): File "C:\Python38\lib\tkinter_init_.py", line 1883, in call return self.func(*args) File "C:\Python38\lib\site-packages\tkcalendar\dateentry.py", line 246, in on_b1_press self.drop_down() File "C:\Python38\lib\site-packages\tkcalendar\dateentry.py", line 331, in drop_down date = self.parse_date(self.get()) File "C:\Python38\lib\site-packages\tkcalendar\calendar.py", line 1229, in parse_date day = int(numbers[indexes['D']]) IndexError: list index out of range

skmagiik avatar Mar 18 '22 19:03 skmagiik

This appears to be an issue because the calendar parse date method is looking for regex groupings instead of matching the particular pattern exactly. Perhaps this could be improved by reading the length of digits == length of the number of letters matching (YY vs YYYY) and using those values instead of just the groupings.

skmagiik avatar Mar 18 '22 19:03 skmagiik

Alternatively, you can also use python tools to accomplish this via strptime: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

Formatting would be different, but could a good solution that is versatile without much effort required. The downside of this is combability breaking for users who update the library to use in existing projects.

skmagiik avatar Mar 18 '22 19:03 skmagiik