[gnome-contacts] birthday: Ensure we're editing in local time zone



commit 91dd7b3e71d60df28eb35aa3ce38aab4091c68ba
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Jan 12 23:18:24 2022 +0100

    birthday: Ensure we're editing in local time zone
    
    Otherwise, there's a good chance the birthday will be off by a day.

 src/contacts-editor-property.vala | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/src/contacts-editor-property.vala b/src/contacts-editor-property.vala
index 8be766ff..ccf84caf 100644
--- a/src/contacts-editor-property.vala
+++ b/src/contacts-editor-property.vala
@@ -95,9 +95,11 @@ public class Contacts.BirthdayEditor : Gtk.Dialog {
   public BirthdayEditor (Gtk.Window window, DateTime birthday) {
     Object (transient_for: window, use_header_bar: 1);
 
-    this.day_spin.set_value ((double) birthday.get_day_of_month ());
-    this.month_combo.set_active (birthday.get_month () - 1);
-    this.year_spin.set_value ((double) birthday.get_year ());
+    // Don't forget to change to local timezone first
+    var bday_local = birthday.to_local ();
+    this.day_spin.set_value ((double) bday_local.get_day_of_month ());
+    this.month_combo.set_active (bday_local.get_month () - 1);
+    this.year_spin.set_value ((double) bday_local.get_year ());
 
     update_date ();
     month_combo.changed.connect (() => {
@@ -108,6 +110,9 @@ public class Contacts.BirthdayEditor : Gtk.Dialog {
     });
   }
 
+  /**
+   * Returns the selected birthday (in UTC timezone)
+   */
   public GLib.DateTime get_birthday () {
     return new GLib.DateTime.local (year_spin.get_value_as_int (),
                                     month_combo.get_active () + 1,
@@ -607,7 +612,7 @@ public class Contacts.EditorProperty : Object, ListModel {
         dialog.changed.connect (() => {
           if (dialog.is_set) {
             details.birthday = dialog.get_birthday ();
-            button.set_label (details.birthday.format ("%x"));
+            button.set_label (details.birthday.to_local ().format ("%x"));
             box.is_empty = false;
           }
         });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]