[california] Avoid console warnings with GLib.Date and Gtk.Calendar
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Avoid console warnings with GLib.Date and Gtk.Calendar
- Date: Thu, 12 Feb 2015 01:59:37 +0000 (UTC)
commit ede239165b9e9e2695a9508099a6c923e0f70822
Author: Jim Nelson <jim yorba org>
Date: Wed Feb 11 17:37:58 2015 -0800
Avoid console warnings with GLib.Date and Gtk.Calendar
Situations arise due to February only having 28 days when adjusting
Gtk.Calendar that causes invalid dates (i.e. Feb 30) to be generated.
The code catches this as it should, but unnecessary console warnings
are being generated. This prevents two instances of them.
src/calendar/calendar-date.vala | 7 +++++--
.../event-editor-date-time-widget.vala | 6 ++++--
2 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/src/calendar/calendar-date.vala b/src/calendar/calendar-date.vala
index 7bf0532..92cdafd 100644
--- a/src/calendar/calendar-date.vala
+++ b/src/calendar/calendar-date.vala
@@ -102,12 +102,15 @@ public class Date : Unit<Date>, Gee.Comparable<Date>, Gee.Hashable<Date> {
public Date(DayOfMonth day_of_month, Month month, Year year) throws CalendarError {
base.uninitialized(DateUnit.DAY);
- gdate.set_dmy(day_of_month.to_date_day(), month.to_date_month(), year.to_date_year());
- if (!gdate.valid()) {
+ // Check validity before Date.set_dmy(), which will trigger a console assertion on bad dates
+ if (!GLib.Date.valid_dmy(day_of_month.to_date_day(), month.to_date_month(), year.to_date_year())) {
throw new CalendarError.INVALID("Invalid day/month/year %s/%s/%s", day_of_month.to_string(),
month.to_string(), year.to_string());
}
+ gdate.set_dmy(day_of_month.to_date_day(), month.to_date_month(), year.to_date_year());
+ assert(gdate.valid());
+
day_of_week = DayOfWeek.from_gdate(gdate);
this.day_of_month = day_of_month;
day_of_year = (int) gdate.get_day_of_year();
diff --git a/src/event-editor/event-editor-date-time-widget.vala
b/src/event-editor/event-editor-date-time-widget.vala
index 7c7a095..9849316 100644
--- a/src/event-editor/event-editor-date-time-widget.vala
+++ b/src/event-editor/event-editor-date-time-widget.vala
@@ -320,9 +320,11 @@ public class DateTimeWidget : Gtk.Box {
private void on_date_changed() {
disconnect_widget_signals();
- calendar.day = date.day_of_month.value;
- calendar.month = date.month.value - 1;
+ // set in y/m/d to avoid GTK+ assertions due to invalid day of months (i.e. setting day to
+ // 30 when month is still February)
calendar.year = date.year.value;
+ calendar.month = date.month.value - 1;
+ calendar.day = date.day_of_month.value;
connect_widget_signals();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]