week-grid: consider daylight when calculating event position
There are some weird cases around the globe where the timezone changes in the middle of the day. In GMT-8:00, for example, the DST changes at 2:00 am. This makes the timezone of thestart of the week different from the event's timezone, and somehow the GLib API doesn't take that into account when calculating the diff between two dates. Fix that by also considering different timezones when calculating the event start and end positions. https://bugzilla.gnome.org/show_bug.cgi?id=780079
This commit is contained in:
@@ -138,20 +138,26 @@ get_event_range (GcalWeekGrid *self,
|
||||
{
|
||||
GDateTime *week_start;
|
||||
GTimeSpan diff;
|
||||
gboolean week_start_dst;
|
||||
|
||||
if (!self->active_date)
|
||||
return;
|
||||
|
||||
week_start = get_start_of_week (self->active_date);
|
||||
week_start_dst = g_date_time_is_daylight_savings (week_start);
|
||||
|
||||
if (start)
|
||||
{
|
||||
GDateTime *event_start;
|
||||
gboolean event_start_dst;
|
||||
|
||||
event_start = g_date_time_to_local (gcal_event_get_date_start (event));
|
||||
event_start_dst = g_date_time_is_daylight_savings (event_start);
|
||||
|
||||
diff = g_date_time_difference (event_start, week_start);
|
||||
|
||||
*start = CLAMP (diff / G_TIME_SPAN_MINUTE, 0, MAX_MINUTES);
|
||||
*start += 60 * (event_start_dst - week_start_dst);
|
||||
|
||||
g_clear_pointer (&event_start, g_date_time_unref);
|
||||
}
|
||||
@@ -160,11 +166,15 @@ get_event_range (GcalWeekGrid *self,
|
||||
{
|
||||
|
||||
GDateTime *event_end;
|
||||
gboolean event_end_dst;
|
||||
|
||||
event_end = g_date_time_to_local (gcal_event_get_date_end (event));
|
||||
event_end_dst = g_date_time_is_daylight_savings (event_end);
|
||||
|
||||
diff = g_date_time_difference (event_end, week_start);
|
||||
|
||||
*end = CLAMP (diff / G_TIME_SPAN_MINUTE, 0, MAX_MINUTES);
|
||||
*end += 60 * (event_end_dst - week_start_dst);
|
||||
|
||||
/*
|
||||
* XXX: it may happen that the event has the same start and end
|
||||
|
||||
Reference in New Issue
Block a user