From eeb7038c134dbe623feb1bf7a6c4549e54343e0f Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Tue, 3 Oct 2017 21:52:19 +0200 Subject: Do not tie ISO 8601 week numbering to Monday The week number in the calendar panel is calculated according to ISO 8601. Hence, Monday is the first day of the week and the week number changes from Sunday to Monday. However, calcurse ties the week number not to Monday, but to the first day of the week as configured for display. Thus, when Sunday is shown as first day of the week, the week number is correct for Sunday, but wrong for the rest of the week (one behind). With this patch the week number always follows the mon-sun week as required by ISO 8601. A side effect is that when Sunday is displayed as first day of the week, and Sunday is the selected day, the week number displayed is invalid for the rest of the week (but changes to the correct one when the selected day moves forward). This raises the question whether the week numbering scheme should follow the "first day of the week" choice and use the American week numbering scheme instead of ISO 8601 when Sunday is the first day of the week. But that is for the future. Signed-off-by: Lukas Fleischer --- src/ui-calendar.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui-calendar.c b/src/ui-calendar.c index a2a0e8b..93115da 100644 --- a/src/ui-calendar.c +++ b/src/ui-calendar.c @@ -356,7 +356,7 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day, unsigned yr, mo; int w, ofs_x, ofs_y; int item_this_day = 0; - struct tm t = get_first_weekday(sunday_first); + struct tm t; char *cp; mo = slctd_day.mm; @@ -380,7 +380,8 @@ draw_monthly_view(struct scrollwin *sw, struct date *current_day, (int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L); - /* Print the week number. */ + /* Print the week number, calculated from monday. */ + t = get_first_weekday(0); draw_week_number(sw, t); /* Write the current month and year on top of the calendar */ @@ -468,17 +469,24 @@ draw_weekly_view(struct scrollwin *sw, struct date *current_day, { #define DAYSLICESNO 6 const int WCALWIDTH = 28; - struct tm t = get_first_weekday(sunday_first); + struct tm t; int OFFY, OFFX, j; OFFY = 0; OFFX = (wins_sbar_width() - 2 - WCALWIDTH) / 2; - /* Print the week number. */ + /* Print the week number, calculated from monday. */ + t = get_first_weekday(0); draw_week_number(sw, t); /* Now draw calendar view. */ for (j = 0; j < WEEKINDAYS; j++) { + /* get next day */ + if (j == 0) + t = get_first_weekday(sunday_first); + else + date_change(&t, 0, 1); + struct date date; unsigned attr, item_this_day; int i, slices[DAYSLICESNO]; @@ -554,9 +562,6 @@ draw_weekly_view(struct scrollwin *sw, struct date *current_day, } } } - - /* get next day */ - date_change(&t, 0, 1); } /* Draw marks to indicate midday on the sides of the calendar. */ -- cgit v1.2.3-70-g09d2