From 82d4e0729b7419b058c84764792e008b551d313d Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Wed, 4 Oct 2023 11:22:35 -0600 Subject: [PATCH] Fix January display issue #98 and #99 Fixes issue #98 and #99 display problem occurs for any year where January 1 is a Sunday and firstweekday is set to "sunday". fixes code by checking if the current month is January and if January 1 of the current year falls on a Sunday. If so, it sets w to the week number returned by strftime instead of isocalendar and sets wn to zero. That fixes the January problem for years where January 1 is on a Sunday and the firstweekday = 'sunday' without messing up any other months. Code fix as proposed by @jemiele1 in #99 --- tkcalendar/calendar_.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tkcalendar/calendar_.py b/tkcalendar/calendar_.py index b3cecab..9b3b99f 100644 --- a/tkcalendar/calendar_.py +++ b/tkcalendar/calendar_.py @@ -963,6 +963,9 @@ def _get_day_coords(self, date): w += 1 if dn == 7: wn += 1 + if date.month == 1 and calendar.datetime.date(date.year,date.month,1).strftime("%A") == "Sunday": + w = int(date.strftime("%U")) - 1 + wn = 0 else: d -= 1 w -= wn