[gnome-calendar] date-chooser: Ensure selected day is contained in new month
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] date-chooser: Ensure selected day is contained in new month
- Date: Tue, 24 Jul 2018 22:41:17 +0000 (UTC)
commit 7e9ef5e055313ebe1c89f61dc7a6b5eb1a12b67a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Jul 24 19:36:43 2018 -0300
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]