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:
Georges Basile Stavracas Neto
2019-09-14 11:14:01 -03:00
parent 450aa5e158
commit 9644c30eee
+1 -1
View File
@@ -83,7 +83,7 @@ gcal_date_time_get_start_of_week (GDateTime *date)
g_assert (date != NULL);
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;
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);