[gnome-calendar] event: Fix multiday detection for all-day events
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] event: Fix multiday detection for all-day events
- Date: Tue, 11 May 2021 19:52:09 +0000 (UTC)
commit af7a17ef017c94cc4d94750692401b80f8e7f51f
Author: Sebastian Keller <skeller gnome org>
Date: Sat Apr 3 19:05:16 2021 +0200
event: Fix multiday detection for all-day events
All-day events always use UTC, so when the multiday detection code was
converting them to the local timezone, they span an additional day if
the local timezone is not the same as UTC. This was leading to all-day
events always being considered multiday events.
Fix this by ignoring the timezone for all-day events, like all other
comparisons do. Also don't consider all-day events spanning 1 day to be
multiday since as per RFC 5545 the end date is non-inclusive and if
omitted to be start + 1 day.
src/core/gcal-event.c | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index d92f01a0..e752abfe 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -1480,31 +1480,43 @@ gcal_event_get_uid (GcalEvent *self)
gboolean
gcal_event_is_multiday (GcalEvent *self)
{
- g_autoptr (GDateTime) inclusive_end_date = NULL;
- g_autoptr (GDateTime) local_start_date = NULL;
- g_autoptr (GDateTime) local_end_date = NULL;
+ g_autoptr (GDateTime) start_date = NULL;
+ g_autoptr (GDateTime) end_date = NULL;
GDate start_dt;
GDate end_dt;
+ gint n_days;
g_return_val_if_fail (GCAL_IS_EVENT (self), FALSE);
- inclusive_end_date = g_date_time_add_seconds (gcal_event_get_date_end (self), -1);
- local_start_date = g_date_time_to_local (self->dt_start);
- local_end_date = g_date_time_to_local (inclusive_end_date);
+ if (self->all_day)
+ {
+ start_date = g_date_time_ref (self->dt_start);
+ end_date = g_date_time_ref (gcal_event_get_date_end (self));
+ n_days = 1;
+ }
+ else
+ {
+ g_autoptr (GDateTime) inclusive_end_date = NULL;
+
+ inclusive_end_date = g_date_time_add_seconds (gcal_event_get_date_end (self), -1);
+ start_date = g_date_time_to_local (self->dt_start);
+ end_date = g_date_time_to_local (inclusive_end_date);
+ n_days = 0;
+ }
g_date_clear (&start_dt, 1);
g_date_set_dmy (&start_dt,
- g_date_time_get_day_of_month (local_start_date),
- g_date_time_get_month (local_start_date),
- g_date_time_get_year (local_start_date));
+ g_date_time_get_day_of_month (start_date),
+ g_date_time_get_month (start_date),
+ g_date_time_get_year (start_date));
g_date_clear (&end_dt, 1);
g_date_set_dmy (&end_dt,
- g_date_time_get_day_of_month (local_end_date),
- g_date_time_get_month (local_end_date),
- g_date_time_get_year (local_end_date));
+ g_date_time_get_day_of_month (end_date),
+ g_date_time_get_month (end_date),
+ g_date_time_get_year (end_date));
- return g_date_days_between (&start_dt, &end_dt) > 0;
+ return g_date_days_between (&start_dt, &end_dt) > n_days;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]