@opentripplanner/core-utils 14.2.4 → 14.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/esm/itinerary.js +20 -25
- package/esm/itinerary.js.map +1 -1
- package/esm/otpSchema.json +17765 -14884
- package/esm/planQuery.graphql +1 -3
- package/esm/query-gen.js +1 -1
- package/esm/query-gen.js.map +1 -1
- package/esm/three-transfer-itinerary.json +2195 -0
- package/lib/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/lib/index.js +13 -42
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +75 -134
- package/lib/itinerary.js.map +1 -1
- package/lib/map.js +11 -25
- package/lib/map.js.map +1 -1
- package/lib/otpSchema.json +17765 -14884
- package/lib/planQuery.graphql +1 -3
- package/lib/query-gen.js +12 -21
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +26 -44
- package/lib/route.js.map +1 -1
- package/lib/storage.js +4 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -28
- package/lib/suspense.js.map +1 -1
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +20 -33
- package/lib/time.js.map +1 -1
- package/lib/ui.js +2 -7
- package/lib/ui.js.map +1 -1
- package/package.json +2 -2
- package/src/__snapshots__/core-utils.story.tsx.snap +1 -1
- package/src/__tests__/__mocks__/three-transfer-itinerary.json +2195 -0
- package/src/__tests__/itinerary.ts +9 -0
- package/src/itinerary.ts +21 -21
- package/src/otpSchema.json +17765 -14884
- package/src/planQuery.graphql +1 -3
- package/tsconfig.tsbuildinfo +1 -1
package/lib/time.js
CHANGED
|
@@ -1,97 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getCurrentDate = exports.getCurrentTime = exports.getUserTimezone = exports.formatSecondsAfterMidnight = exports.offsetTime = exports.getLongDateFormat = exports.getDateFormat = exports.getTimeFormat = exports.ensureAtLeastOneMinute = exports.toHoursMinutesSeconds = exports.OTP_API_TIME_FORMAT = exports.OTP_API_DATE_FORMAT = void 0;
|
|
4
|
-
const date_fns_1 = require("date-fns");
|
|
5
|
-
const date_fns_tz_1 = require("date-fns-tz");
|
|
1
|
+
import { startOfDay, add, format } from "date-fns";
|
|
2
|
+
import { utcToZonedTime } from "date-fns-tz";
|
|
6
3
|
// Date/time formats (per date-fns) when sending/receiving date from OTP
|
|
7
4
|
// regardless of whatever the user has configured as the display format.
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export const OTP_API_DATE_FORMAT = "yyyy-MM-dd";
|
|
6
|
+
export const OTP_API_TIME_FORMAT = "HH:mm";
|
|
10
7
|
/**
|
|
11
8
|
* Breaks up a duration in seconds into hours, minutes, and seconds.
|
|
12
9
|
* @param {number} seconds The number of seconds to break up
|
|
13
10
|
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
14
11
|
*/
|
|
15
|
-
function toHoursMinutesSeconds(seconds) {
|
|
12
|
+
export function toHoursMinutesSeconds(seconds) {
|
|
16
13
|
return {
|
|
17
14
|
hours: Math.floor(seconds / 3600),
|
|
18
15
|
minutes: Math.floor(seconds / 60) % 60,
|
|
19
16
|
seconds: seconds % 60
|
|
20
17
|
};
|
|
21
18
|
}
|
|
22
|
-
exports.toHoursMinutesSeconds = toHoursMinutesSeconds;
|
|
23
19
|
/**
|
|
24
20
|
* If a duration is less than 60 seconds, round it to one minute, to avoid a duration
|
|
25
21
|
* of 0 minutes on a leg.
|
|
26
22
|
* @param {number} duration The leg or trip duration in seconds
|
|
27
23
|
* @returns a duration in seconds of at least 60 seconds.
|
|
28
24
|
*/
|
|
29
|
-
const ensureAtLeastOneMinute = (duration) => duration < 60 ? 60 : duration;
|
|
30
|
-
exports.ensureAtLeastOneMinute = ensureAtLeastOneMinute;
|
|
25
|
+
export const ensureAtLeastOneMinute = (duration) => duration < 60 ? 60 : duration;
|
|
31
26
|
/**
|
|
32
27
|
* @param {[type]} config the OTP config object found in store
|
|
33
28
|
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
|
34
29
|
*/
|
|
35
|
-
function getTimeFormat(config) {
|
|
30
|
+
export function getTimeFormat(config) {
|
|
36
31
|
var _a;
|
|
37
|
-
return ((_a = config === null || config === void 0 ? void 0 : config.dateTime) === null || _a === void 0 ? void 0 : _a.timeFormat) ||
|
|
32
|
+
return ((_a = config === null || config === void 0 ? void 0 : config.dateTime) === null || _a === void 0 ? void 0 : _a.timeFormat) || OTP_API_TIME_FORMAT;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
function getDateFormat(config) {
|
|
34
|
+
export function getDateFormat(config) {
|
|
41
35
|
var _a;
|
|
42
|
-
return ((_a = config === null || config === void 0 ? void 0 : config.dateTime) === null || _a === void 0 ? void 0 : _a.dateFormat) ||
|
|
36
|
+
return ((_a = config === null || config === void 0 ? void 0 : config.dateTime) === null || _a === void 0 ? void 0 : _a.dateFormat) || OTP_API_DATE_FORMAT;
|
|
43
37
|
}
|
|
44
|
-
exports.getDateFormat = getDateFormat;
|
|
45
38
|
/** @deprecated */
|
|
46
|
-
function getLongDateFormat(config) {
|
|
39
|
+
export function getLongDateFormat(config) {
|
|
47
40
|
var _a;
|
|
48
41
|
return ((_a = config === null || config === void 0 ? void 0 : config.dateTime) === null || _a === void 0 ? void 0 : _a.longDateFormat) || "D MMMM YYYY";
|
|
49
42
|
}
|
|
50
|
-
exports.getLongDateFormat = getLongDateFormat;
|
|
51
43
|
/**
|
|
52
44
|
* Offsets a time according to the provided time options
|
|
53
45
|
* and returns the result.
|
|
54
46
|
*/
|
|
55
|
-
function offsetTime(ms, options) {
|
|
47
|
+
export function offsetTime(ms, options) {
|
|
56
48
|
return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
|
|
57
49
|
}
|
|
58
|
-
exports.offsetTime = offsetTime;
|
|
59
50
|
/**
|
|
60
51
|
* Formats a seconds after midnight value for display in narrative
|
|
61
52
|
* @param {number} seconds time since midnight in seconds
|
|
62
53
|
* @param {string} timeFormat A valid date-fns time format
|
|
63
54
|
* @return {string} formatted text representation
|
|
64
55
|
*/
|
|
65
|
-
function formatSecondsAfterMidnight(seconds, timeFormat) {
|
|
66
|
-
const time =
|
|
67
|
-
return
|
|
56
|
+
export function formatSecondsAfterMidnight(seconds, timeFormat) {
|
|
57
|
+
const time = add(startOfDay(new Date()), { seconds });
|
|
58
|
+
return format(time, timeFormat);
|
|
68
59
|
}
|
|
69
|
-
exports.formatSecondsAfterMidnight = formatSecondsAfterMidnight;
|
|
70
60
|
/**
|
|
71
61
|
* Uses Intl.DateTimeFormat() api to get the user's time zone. In a test
|
|
72
62
|
* environment, pulls timezone information from an env variable. Default to
|
|
73
63
|
* GMT+0 if the Intl API is unavailable.
|
|
74
64
|
*/
|
|
75
|
-
function getUserTimezone(fallbackTimezone = "Etc/Greenwich") {
|
|
65
|
+
export function getUserTimezone(fallbackTimezone = "Etc/Greenwich") {
|
|
76
66
|
if (process.env.NODE_ENV === "test")
|
|
77
67
|
return process.env.TZ;
|
|
78
68
|
return (Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat().resolvedOptions().timeZone) || fallbackTimezone;
|
|
79
69
|
}
|
|
80
|
-
exports.getUserTimezone = getUserTimezone;
|
|
81
70
|
/**
|
|
82
71
|
* Formats current time for use in OTP query
|
|
83
72
|
* The conversion to the user's timezone is needed for testing purposes.
|
|
84
73
|
*/
|
|
85
|
-
function getCurrentTime(timezone = getUserTimezone()) {
|
|
86
|
-
return
|
|
74
|
+
export function getCurrentTime(timezone = getUserTimezone()) {
|
|
75
|
+
return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);
|
|
87
76
|
}
|
|
88
|
-
exports.getCurrentTime = getCurrentTime;
|
|
89
77
|
/**
|
|
90
78
|
* Formats current date for use in OTP query
|
|
91
79
|
* The conversion to the user's timezone is needed for testing purposes.
|
|
92
80
|
*/
|
|
93
|
-
function getCurrentDate(timezone = getUserTimezone()) {
|
|
94
|
-
return
|
|
81
|
+
export function getCurrentDate(timezone = getUserTimezone()) {
|
|
82
|
+
return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);
|
|
95
83
|
}
|
|
96
|
-
exports.getCurrentDate = getCurrentDate;
|
|
97
84
|
//# sourceMappingURL=time.js.map
|
package/lib/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,wEAAwE;AACxE,wEAAwE;AACxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe;IAMf,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;QACjC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;QACtC,OAAO,EAAE,OAAO,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAAU,EAAE,CACjE,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;;IAC1C,OAAO,CAAA,MAAA,MAAM,aAAN,MAAM,u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QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAQ,GAAG,eAAe,EAAE;IACzD,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAC3E,CAAC"}
|
package/lib/ui.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enableScrollForSelector = exports.isMobile = void 0;
|
|
4
|
-
function isMobile() {
|
|
1
|
+
export function isMobile() {
|
|
5
2
|
// TODO: consider using 3rd-party library?
|
|
6
3
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7
4
|
}
|
|
8
|
-
exports.isMobile = isMobile;
|
|
9
5
|
/**
|
|
10
6
|
* Enables scrolling for a specified selector, while disabling scrolling for all
|
|
11
7
|
* other targets. This is adapted from https://stackoverflow.com/a/41601290/915811
|
|
12
8
|
* and intended to fix issues with iOS elastic scrolling, e.g.,
|
|
13
9
|
* https://github.com/conveyal/trimet-mod-otp/issues/92.
|
|
14
10
|
*/
|
|
15
|
-
function enableScrollForSelector(selector) {
|
|
11
|
+
export function enableScrollForSelector(selector) {
|
|
16
12
|
const overlay = document.querySelector(selector);
|
|
17
13
|
let clientY = null; // remember Y position on touch start
|
|
18
14
|
function isOverlayTotallyScrolled() {
|
|
@@ -43,5 +39,4 @@ function enableScrollForSelector(selector) {
|
|
|
43
39
|
}
|
|
44
40
|
}, false);
|
|
45
41
|
}
|
|
46
|
-
exports.enableScrollForSelector = enableScrollForSelector;
|
|
47
42
|
//# sourceMappingURL=ui.js.map
|
package/lib/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[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AAI,KAAK,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,sBAAsB;YACtB,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EACD,KAAK,CACN,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/core-utils",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.3.1",
|
|
4
4
|
"description": "Core functionality that is shared among numerous UI components",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=13"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"gitHead": "0af1b7cda60bd4252b219dcf893e01c2acb2ed5d",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@opentripplanner/types": "8.
|
|
29
|
+
"@opentripplanner/types": "8.3.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"tsc": "tsc"
|