Calendar Popup: Fix prev/next month for shorter months Jump to correct month if the prev/next month has fewer days (e.g. 28/29/30) than the currently selected day (e.g. 29/30/31) Based on a fix by Ludwig Reiter diff -r e328ffaa54ce roundup/cgi/templating.py --- a/roundup/cgi/templating.py Thu Sep 19 16:44:33 2019 +0200 +++ b/roundup/cgi/templating.py Thu Nov 14 13:00:49 2019 +0100 @@ -3121,13 +3121,32 @@ display = current_date day = display.day + def prev_month_interval(display): + # jump to correct month if the prev month has fewer days + # (e.g. 28/29/30) than the current display.day + return date.Interval("-%dd" % (display.day + 1)) + + def next_month_interval(display): + # jump to correct month if the next month has fewer days + # (e.g. 28/29/30) than the current display.day + year = display.year + month = display.month + if display.day > 28: + if month == 12: + year += 1 + month = 1 + else: + month += 1 + days = calendar.monthrange(year, month)[1] + return date.Interval("+%dd" % days) + # for navigation try: - date_prev_month = display + date.Interval("-1m") + date_prev_month = display + prev_month_interval(display) except ValueError: date_prev_month = None try: - date_next_month = display + date.Interval("+1m") + date_next_month = display + next_month_interval(display) except ValueError: date_next_month = None try: