diff options
Diffstat (limited to 'src/dialogs/AdjustDateTimeDialog.vala')
-rw-r--r-- | src/dialogs/AdjustDateTimeDialog.vala | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/src/dialogs/AdjustDateTimeDialog.vala b/src/dialogs/AdjustDateTimeDialog.vala index fc08a3f..f475773 100644 --- a/src/dialogs/AdjustDateTimeDialog.vala +++ b/src/dialogs/AdjustDateTimeDialog.vala @@ -14,7 +14,7 @@ public class AdjustDateTimeDialog : Gtk.Dialog { private const int CALENDAR_THUMBNAIL_SCALE = 1; - time_t original_time; + DateTime? original_time; Gtk.Label original_time_label; Gtk.Calendar calendar; Gtk.SpinButton hour; @@ -182,32 +182,33 @@ public class AdjustDateTimeDialog : Gtk.Dialog { original_time = source.get_exposure_time(); - if (original_time == 0) { - original_time = time_t(); + if (original_time == null) { + // This came from + original_time = new DateTime.now_utc(); no_original_time = true; } - set_time(Time.local(original_time)); + set_time(original_time.to_local()); set_original_time_label(Config.Facade.get_instance().get_use_24_hour_time()); } - private void set_time(Time time) { - calendar.select_month(time.month, time.year + YEAR_OFFSET); - calendar.select_day(time.day); + private void set_time(DateTime time) { + calendar.select_month(time.get_month() - 1, time.get_year()); + calendar.select_day(time.get_day_of_month()); calendar.notify_property("year"); calendar.notify_property("month"); if (Config.Facade.get_instance().get_use_24_hour_time()) { system.set_active(TimeSystem.24HR); - hour.set_value(time.hour); + hour.set_value(time.get_hour()); } else { - int AMPM_hour = time.hour % 12; + int AMPM_hour = time.get_hour() % 12; hour.set_value((AMPM_hour == 0) ? 12 : AMPM_hour); - system.set_active((time.hour >= 12) ? TimeSystem.PM : TimeSystem.AM); + system.set_active((time.get_hour() >= 12) ? TimeSystem.PM : TimeSystem.AM); } - minute.set_value(time.minute); - second.set_value(time.second); + minute.set_value(time.get_minute()); + second.set_value(time.get_second()); previous_time_system = (TimeSystem) system.get_active(); } @@ -217,43 +218,35 @@ public class AdjustDateTimeDialog : Gtk.Dialog { return; original_time_label.set_text(_("Original: ") + - Time.local(original_time).format(use_24_hr_format ? _("%m/%d/%Y, %H:%M:%S") : + original_time.to_local().format(use_24_hr_format ? _("%m/%d/%Y, %H:%M:%S") : _("%m/%d/%Y, %I:%M:%S %p"))); } - private time_t get_time() { - Time time = Time(); - - time.second = (int) second.get_value(); - time.minute = (int) minute.get_value(); - + private DateTime get_time() { // convert to 24 hr int hour = (int) hour.get_value(); - time.hour = (hour == 12 && system.get_active() != TimeSystem.24HR) ? 0 : hour; - time.hour += ((system.get_active() == TimeSystem.PM) ? 12 : 0); + hour = (hour == 12 && system.get_active() != TimeSystem.24HR) ? 0 : hour; + hour += ((system.get_active() == TimeSystem.PM) ? 12 : 0); uint year, month, day; calendar.get_date(out year, out month, out day); - time.year = ((int) year) - YEAR_OFFSET; - time.month = (int) month; - time.day = (int) day; - time.isdst = -1; - - return time.mktime(); + return new DateTime.local((int)year, (int)month + 1, (int)day, hour, (int)minute.get_value(), (int)second.get_value()); } - public bool execute(out int64 time_shift, out bool keep_relativity, + public bool execute(out TimeSpan time_shift, out bool keep_relativity, out bool modify_originals) { show_all(); bool response = false; if (run() == Gtk.ResponseType.OK) { - if (no_original_time) - time_shift = (int64) get_time(); - else - time_shift = (int64) (get_time() - original_time); + // Difference returns microseconds, so divide by 1000000, we need seconds + if (no_original_time) { + time_shift = get_time().difference(new DateTime.from_unix_utc(0)) / 1000 / 1000; + } else { + time_shift = (get_time().difference(original_time)) / 1000 / 1000; + } keep_relativity = relativity_radio_button.get_active(); @@ -286,7 +279,7 @@ public class AdjustDateTimeDialog : Gtk.Dialog { } private void on_time_changed() { - int64 time_shift = ((int64) get_time() - (int64) original_time); + var time_shift = get_time().difference (original_time); calendar.notify_property("year"); calendar.notify_property("month"); @@ -301,12 +294,12 @@ public class AdjustDateTimeDialog : Gtk.Dialog { time_shift = time_shift.abs(); - days = (int) (time_shift / SECONDS_IN_DAY); - time_shift = time_shift % SECONDS_IN_DAY; - hours = (int) (time_shift / SECONDS_IN_HOUR); - time_shift = time_shift % SECONDS_IN_HOUR; - minutes = (int) (time_shift / SECONDS_IN_MINUTE); - seconds = (int) (time_shift % SECONDS_IN_MINUTE); + days = (int) (time_shift / TimeSpan.DAY); + time_shift = time_shift % TimeSpan.DAY; + hours = (int) (time_shift / TimeSpan.HOUR); + time_shift = time_shift % TimeSpan.HOUR; + minutes = (int) (time_shift / TimeSpan.MINUTE); + seconds = (int) ((time_shift % TimeSpan.MINUTE) / TimeSpan.SECOND); string shift_status = (forward) ? _("Exposure time will be shifted forward by\n%d %s, %d %s, %d %s, and %d %s.") : |