views/week-header: Avoid setting date when dates share the same start-of-week
Instead of checking `g_date_time_get_week_of_year()`, which doesn't care about "first day of week" settings, we use our `gcal_date_time_get_start_of_week()` utility function. This function determines the first day of the week the passed date belongs to, constructs a new `GDateTime` object that represents the first day of week as 'Y-M-D 00:00:00' in local timezone, all while taking into account the "first day of week" Desktop setting. Fixes: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1212> Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/868>
This commit is contained in:
@@ -1849,17 +1849,21 @@ void
|
|||||||
gcal_week_header_set_date (GcalWeekHeader *self,
|
gcal_week_header_set_date (GcalWeekHeader *self,
|
||||||
GDateTime *date)
|
GDateTime *date)
|
||||||
{
|
{
|
||||||
|
g_autoptr (GDateTime) start_of_week_1 = NULL;
|
||||||
|
g_autoptr (GDateTime) start_of_week_2 = NULL;
|
||||||
gboolean had_date;
|
gboolean had_date;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the active date changed, but we're still in the same week,
|
* If the active date changed, but we're still in the same week,
|
||||||
* there's no need to recalculate visible events.
|
* there's no need to recalculate visible events.
|
||||||
*/
|
*/
|
||||||
if (self->active_date && date &&
|
if (self->active_date && date)
|
||||||
g_date_time_get_year (self->active_date) == g_date_time_get_year (date) &&
|
|
||||||
g_date_time_get_week_of_year (self->active_date) == g_date_time_get_week_of_year (date))
|
|
||||||
{
|
{
|
||||||
return;
|
start_of_week_1 = gcal_date_time_get_start_of_week (self->active_date);
|
||||||
|
start_of_week_2 = gcal_date_time_get_start_of_week (date);
|
||||||
|
|
||||||
|
if (g_date_time_equal (start_of_week_1, start_of_week_2))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
had_date = self->active_date != NULL;
|
had_date = self->active_date != NULL;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ gcal_date_time_get_start_of_week (GDateTime *date)
|
|||||||
g_assert (date != NULL);
|
g_assert (date != NULL);
|
||||||
|
|
||||||
first_weekday = gcal_context_get_week_start_day (context);
|
first_weekday = gcal_context_get_week_start_day (context);
|
||||||
weekday = g_date_time_get_day_of_week (date) % GCAL_N_WEEKDAYS;
|
weekday = g_date_time_get_day_of_week (date);
|
||||||
n_days_after_week_start = GCAL_NTH_WEEKDAY (weekday, first_weekday);
|
n_days_after_week_start = GCAL_NTH_WEEKDAY (weekday, first_weekday);
|
||||||
|
|
||||||
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