[gnome-calendar/gnome-3-36] gcal-date-time-utils: Fix week start
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gnome-3-36] gcal-date-time-utils: Fix week start
- Date: Mon, 15 Jun 2020 19:19:23 +0000 (UTC)
commit 18e31d5f55c8151e72d5919ff941180a910aaf68
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date: Sun Jun 7 12:55:34 2020 +0000
gcal-date-time-utils: Fix week start
In locales where the first weekday is a monday, the previous code
had a off by one error determining the week a sunday is in.
The problem ultimately arose because in the
`gcal_date_time_get_start_of_week()` function the variable
`n_days_after_week_start` would become negative (-1 in this case) making
the following `g_date_time_add_days (date, -n_days_after_week_start)`
add 1 day resulting in `start_of_week` being set to the start of the
following week.
The solution was to make sure `n_days_after_week_start` would be
positive by adding 7 to it. The variable is taken modulo 7 hence this
should not introduce any bugs.
Fixes #583
(cherry picked from commit 07f544b78d3c6c2808bdb9bbcf9d3927630033eb)
src/utils/gcal-date-time-utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/src/utils/gcal-date-time-utils.c b/src/utils/gcal-date-time-utils.c
index 733e4109..658bf6fd 100644
--- a/src/utils/gcal-date-time-utils.c
+++ b/src/utils/gcal-date-time-utils.c
@@ -84,7 +84,7 @@ gcal_date_time_get_start_of_week (GDateTime *date)
first_weekday = get_first_weekday ();
weekday = g_date_time_get_day_of_week (date) % 7;
- n_days_after_week_start = (weekday - first_weekday) % 7;
+ n_days_after_week_start = (7 + weekday - first_weekday) % 7;
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]