[california] Properly handle day rollover in date/time adjust widget: Bug #739327
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Properly handle day rollover in date/time adjust widget: Bug #739327
- Date: Wed, 29 Oct 2014 21:01:22 +0000 (UTC)
commit 7ac86208f45f67bda579ade72f04e1416bd3e054
Author: Jim Nelson <jim yorba org>
Date: Wed Oct 29 13:58:28 2014 -0700
Properly handle day rollover in date/time adjust widget: Bug #739327
The date/time adjustment widget ignored rollover in the hours from
11pm to 12am, meaning the adjusted date would become (say) Oct 1 11pm
to Oct 1 12am. This is not what the user expects, so now the hour
widget is "locked" to the date when rollover occurs.
src/calendar/calendar-wall-time.vala | 11 ++++++++---
src/host/host-date-time-widget.vala | 26 ++++++++++++++++++++++++--
2 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/src/calendar/calendar-wall-time.vala b/src/calendar/calendar-wall-time.vala
index 781a79b..a16f3f4 100644
--- a/src/calendar/calendar-wall-time.vala
+++ b/src/calendar/calendar-wall-time.vala
@@ -448,16 +448,21 @@ public class WallTime : BaseObject, Gee.Comparable<WallTime>, Gee.Hashable<WallT
* from the others. That is, if the minutes setting is adjusted from 59 to 0, the hour remains
* unchanged.
*
+ * rollover is returned just as it is with { link adjust}.
+ *
* An amount of zero returns the current { link WallTime}.
*
* @see adjust
*/
- public WallTime free_adjust(int amount, TimeUnit time_unit) {
- if (amount == 0)
+ public WallTime free_adjust(int amount, TimeUnit time_unit, out bool rollover) {
+ if (amount == 0) {
+ rollover = false;
+
return this;
+ }
// piggyback on adjust() to do the heavy lifting, then rearrange its results
- WallTime adjusted = adjust(amount, time_unit, null);
+ WallTime adjusted = adjust(amount, time_unit, out rollover);
switch (time_unit) {
case TimeUnit.HOUR:
return new WallTime(adjusted.hour, minute, second);
diff --git a/src/host/host-date-time-widget.vala b/src/host/host-date-time-widget.vala
index 3f43a56..fdc49da 100644
--- a/src/host/host-date-time-widget.vala
+++ b/src/host/host-date-time-widget.vala
@@ -195,12 +195,34 @@ public class DateTimeWidget : Gtk.Box {
return Toolkit.PROPAGATE;
// use free_adjust() to adjust each unit individually without affecting others
- Calendar.WallTime new_wall_time = wall_time.free_adjust(amount, time_unit);
+ bool rollover;
+ Calendar.WallTime new_wall_time = wall_time.free_adjust(amount, time_unit, out rollover);
+
+ // if rolled-over, adjust the date ... note that this only happens when adjusting the
+ // hour, as the other free-adjust widgets aren't designed to change the date (that is, only
+ // the hour widget is locked to the date)
+ Calendar.Date new_date = date;
+ if (rollover) {
+ int date_amount;
+ if (details.widget == hour_up)
+ date_amount = 1;
+ else if (details.widget == hour_down)
+ date_amount = -1;
+ else
+ date_amount = 0;
+
+ new_date = date.adjust(date_amount);
+ }
// ensure it's clamped ... this assignment will update the entry fields, so don't
// disconnect widget signals
- if (is_valid_date_time(date, new_wall_time))
+ if (is_valid_date_time(new_date, new_wall_time)) {
+ freeze_notify();
wall_time = new_wall_time;
+ if (!date.equal_to(new_date))
+ date = new_date;
+ thaw_notify();
+ }
return Toolkit.STOP;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]