date-time-utils: Fix weekday calculation
GNOME Calendar needs to deal with two different weekday ranges: 1. Sunday → 0 ... Saturday → 6 2. Monday → 1 ... Sunday → 7 (used by GDateTime) When converting (2) into (1), the correct calculation is `weekday % 7`. However, gcal_date_time_get_start_of_week() was doing `weekday - 1` instead. Fix it and do the correct calculation instead. https://gitlab.gnome.org/GNOME/gnome-calendar/issues/451
This commit is contained in:
@@ -83,7 +83,7 @@ gcal_date_time_get_start_of_week (GDateTime *date)
|
|||||||
g_assert (date != NULL);
|
g_assert (date != NULL);
|
||||||
|
|
||||||
first_weekday = get_first_weekday ();
|
first_weekday = get_first_weekday ();
|
||||||
weekday = g_date_time_get_day_of_week (date) - 1;
|
weekday = g_date_time_get_day_of_week (date) % 7;
|
||||||
n_days_after_week_start = (weekday - first_weekday) % 7;
|
n_days_after_week_start = (weekday - first_weekday) % 7;
|
||||||
|
|
||||||
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
|
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
|
||||||
|
|||||||
Reference in New Issue
Block a user