dateMenu: Use intervals with non-inclusive ends for date ranges

The ical events, we are comparing these intervals to use the first point
in time after the end of the event as their end time, while the code in
gnome-shell was using the last point in time within the range. This was
causing multi-day events ranging from 0:00 to 0:00 to have a trailing
"..." shown on the last day.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2023>
This commit is contained in:
Sebastian Keller 2021-11-04 12:42:52 +01:00 committed by Marge Bot
parent 5eddcd3cf2
commit 2fffe91488
2 changed files with 9 additions and 11 deletions

View File

@ -47,11 +47,8 @@ function _getBeginningOfDay(date) {
} }
function _getEndOfDay(date) { function _getEndOfDay(date) {
let ret = new Date(date.getTime()); const ret = _getBeginningOfDay(date);
ret.setHours(23); ret.setDate(ret.getDate() + 1);
ret.setMinutes(59);
ret.setSeconds(59);
ret.setMilliseconds(999);
return ret; return ret;
} }

View File

@ -127,9 +127,10 @@ class EventsSection extends St.Button {
} }
setDate(date) { setDate(date) {
const day = [date.getFullYear(), date.getMonth(), date.getDate()]; this._startDate =
this._startDate = new Date(...day); new Date(date.getFullYear(), date.getMonth(), date.getDate());
this._endDate = new Date(...day, 23, 59, 59, 999); this._endDate =
new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
this._updateTitle(); this._updateTitle();
this._reloadEvents(); this._reloadEvents();
@ -156,11 +157,11 @@ class EventsSection extends St.Button {
const timeSpanDay = GLib.TIME_SPAN_DAY / 1000; const timeSpanDay = GLib.TIME_SPAN_DAY / 1000;
const now = new Date(); const now = new Date();
if (this._startDate <= now && now <= this._endDate) if (this._startDate <= now && now < this._endDate)
this._title.text = _('Today'); this._title.text = _('Today');
else if (this._endDate < now && now - this._endDate < timeSpanDay) else if (this._endDate <= now && now - this._endDate < timeSpanDay)
this._title.text = _('Yesterday'); this._title.text = _('Yesterday');
else if (this._startDate > now && this._startDate - now < timeSpanDay) else if (this._startDate > now && this._startDate - now <= timeSpanDay)
this._title.text = _('Tomorrow'); this._title.text = _('Tomorrow');
else if (this._startDate.getFullYear() === now.getFullYear()) else if (this._startDate.getFullYear() === now.getFullYear())
this._title.text = this._startDate.toLocaleFormat(sameYearFormat); this._title.text = this._startDate.toLocaleFormat(sameYearFormat);