[gnome-maps/wip/mlundblad/redesign-opening-hours: 1/3] transitPlan: Use time utility function
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/redesign-opening-hours: 1/3] transitPlan: Use time utility function
- Date: Mon, 21 Dec 2020 22:00:23 +0000 (UTC)
commit 5d578028ee77458437be6b0856f4769e7f5a2e89
Author: Marcus Lundblad <ml update uu se>
Date: Tue Dec 15 22:58:38 2020 +0100
transitPlan: Use time utility function
Use util function from the Time module
to format times with offset relative to UTC.
src/transitPlan.js | 44 +++++++++++++-------------------------------
1 file changed, 13 insertions(+), 31 deletions(-)
---
diff --git a/src/transitPlan.js b/src/transitPlan.js
index 46fc246d..c6d96ddb 100644
--- a/src/transitPlan.js
+++ b/src/transitPlan.js
@@ -23,19 +23,13 @@ const _ = imports.gettext.gettext;
const ngettext = imports.gettext.ngettext;
const Champlain = imports.gi.Champlain;
-const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const HVT = imports.hvt;
+const Time = imports.time;
const Utils = imports.utils;
-// in org.gnome.desktop.interface
-const CLOCK_FORMAT_KEY = 'clock-format';
-
-let _desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
-let clockFormat = _desktopSettings.get_string(CLOCK_FORMAT_KEY);
-
/*
* These constants corresponds to the routeType attribute of transit legs
* in original GTFS specification.
@@ -74,20 +68,6 @@ var RouteType = {
/* extra time to add to the first itinerary leg when it's a walking leg */
const WALK_SLACK = 120;
-const _timeFormat = new Intl.DateTimeFormat([], { hour: '2-digit',
- minute: '2-digit',
- hour12: clockFormat === '12h',
- timeZone: 'UTC'});
-
-function _printTimeWithTZOffset(time, offset) {
- let utcTimeWithOffset = time + offset;
- let date = new Date();
-
- date.setTime(utcTimeWithOffset);
-
- return _timeFormat.format(date);
-}
-
var DEFAULT_ROUTE_COLOR = '4c4c4c';
var DEFAULT_ROUTE_TEXT_COLOR = 'ffffff';
@@ -326,16 +306,16 @@ class Itinerary extends GObject.Object {
_getDepartureTime() {
/* take the itinerary departure time and offset using the timezone
* offset of the first leg */
- return _printTimeWithTZOffset(this.departure,
- this.legs[0].agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this.departure,
+ this.legs[0].agencyTimezoneOffset);
}
_getArrivalTime() {
/* take the itinerary departure time and offset using the timezone
* offset of the last leg */
let lastLeg = this.legs[this.legs.length - 1];
- return _printTimeWithTZOffset(this.arrival,
- lastLeg.agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this.arrival,
+ lastLeg.agencyTimezoneOffset);
}
prettyPrintDuration() {
@@ -770,14 +750,16 @@ var Leg = class Leg {
/* take the itinerary departure time and offset using the timezone
* offset of the first leg
*/
- return _printTimeWithTZOffset(this.departure, this.agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this.departure,
+ this.agencyTimezoneOffset);
}
prettyPrintArrivalTime() {
/* take the itinerary departure time and offset using the timezone
* offset of the last leg
*/
- return _printTimeWithTZOffset(this.arrival, this.agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this.arrival,
+ this.agencyTimezoneOffset);
}
};
@@ -813,14 +795,14 @@ var Stop = class Stop {
/* take the stop arrival time and offset using the timezone
* offset of the last leg
*/
- return _printTimeWithTZOffset(this._arrival,
- this._agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this._arrival,
+ this._agencyTimezoneOffset);
} else {
/* take the stop departure time and offset using the timezone
* offset of the first leg
*/
- return _printTimeWithTZOffset(this._departure,
- this._agencyTimezoneOffset);
+ return Time.formatTimeWithTZOffset(this._departure,
+ this._agencyTimezoneOffset);
}
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]