[gnome-shell] calendar: Use GDateTime for selected-date-changed signal
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] calendar: Use GDateTime for selected-date-changed signal
- Date: Wed, 16 Oct 2019 15:31:47 +0000 (UTC)
commit ff775213a5346df6d3e98f9c4d46c9b1f46abf92
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date: Mon Sep 2 21:18:54 2019 +0200
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 6abc23e6ca..ec89ebf00d 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 9a086de477..f3da28ff1d 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]