From 7e9ef5e055313ebe1c89f61dc7a6b5eb1a12b67a Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 24 Jul 2018 19:36:43 -0300 Subject: [PATCH] date-chooser: Ensure selected day is contained in new month When navigating through the dates of GcalDateChooser, if we select a day (e.g. 31) that is not contained inside the next or previous month, Calendar crashes. Fix that by ensuring that the selected day is always contained in the new month. https://gitlab.gnome.org/GNOME/gnome-calendar/issues/284 --- src/gcal-date-chooser.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gcal-date-chooser.c b/src/gcal-date-chooser.c index 238e1633..4e8688ca 100644 --- a/src/gcal-date-chooser.c +++ b/src/gcal-date-chooser.c @@ -396,16 +396,18 @@ calendar_get_property (GObject *obj, static void multi_choice_changed (GcalDateChooser *self) { - GDateTime *date; + g_autoptr (GDateTime) date = NULL; gint year, month, day; year = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->year_choice)); month = gcal_multi_choice_get_value (GCAL_MULTI_CHOICE (self->month_choice)) + 1; - g_date_time_get_ymd (self->date, NULL, NULL, &day); + day = g_date_time_get_day_of_month (self->date); + + /* Make sure the day is valid at that month */ + day = MIN (day, month_length[leap (year)][month]); date = g_date_time_new_local (year, month, day, 1, 1, 1); gcal_date_chooser_set_date (self, date); - g_date_time_unref (date); } static void