From ff775213a5346df6d3e98f9c4d46c9b1f46abf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 2 Sep 2019 21:18:54 +0200 Subject: [PATCH] calendar: Use GDateTime for selected-date-changed signal Since GObject derived classes can't use JS objects as signal parameters, let's go native and use GLib.DateTime instead. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559 --- js/ui/calendar.js | 5 ++++- js/ui/dateMenu.js | 18 +++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 6abc23e6c..ec89ebf00 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -373,7 +373,10 @@ var Calendar = class Calendar { this._selectedDate = date; this._update(); - this.emit('selected-date-changed', new Date(this._selectedDate)); + + let datetime = GLib.DateTime.new_from_unix_local( + this._selectedDate.getTime() / 1000); + this.emit('selected-date-changed', datetime); } updateTimeZone() { diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index 9a086de47..f3da28ff1 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -25,6 +25,10 @@ function _isToday(date) { now.getDate() == date.getDate(); } +function _gDateTimeToDate(datetime) { + return new Date(datetime.to_unix() * 1000 + datetime.get_microsecond() / 1000); +} + var TodayButton = class TodayButton { constructor(calendar) { // Having the ability to go to the current date if the user is already @@ -52,10 +56,10 @@ var TodayButton = class TodayButton { hbox.add_actor(this._dateLabel); this._calendar = calendar; - this._calendar.connect('selected-date-changed', (calendar, date) => { + this._calendar.connect('selected-date-changed', (_calendar, datetime) => { // Make the button reactive only if the selected date is not the // current date. - this.actor.reactive = !_isToday(date); + this.actor.reactive = !_isToday(_gDateTimeToDate(datetime)); }); } @@ -529,11 +533,11 @@ class DateMenuButton extends PanelMenu.Button { bin.add_actor(hbox); this._calendar = new Calendar.Calendar(); - this._calendar.connect('selected-date-changed', - (calendar, date) => { - layout.frozen = !_isToday(date); - this._messageList.setDate(date); - }); + this._calendar.connect('selected-date-changed', (_calendar, datetime) => { + let date = _gDateTimeToDate(datetime); + layout.frozen = !_isToday(date); + this._messageList.setDate(date); + }); this.menu.connect('open-state-changed', (menu, isOpen) => { // Whenever the menu is opened, select today