@opentripplanner/core-utils 11.4.3-mobility-profile → 11.4.4
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/bike-rental-itinerary.json +863 -0
- package/esm/config.json +54 -0
- package/esm/fare-products-itinerary.json +1299 -0
- package/esm/graphql.d.js +2 -0
- package/esm/graphql.d.js.map +1 -0
- package/esm/index.js +26 -0
- package/esm/index.js.map +1 -0
- package/esm/itinerary.js +688 -0
- package/esm/itinerary.js.map +1 -0
- package/esm/map.js +53 -0
- package/esm/map.js.map +1 -0
- package/esm/otpSchema.json +13373 -0
- package/esm/planQuery.graphql +281 -0
- package/esm/profile.js +172 -0
- package/esm/profile.js.map +1 -0
- package/esm/query-gen.js +233 -0
- package/esm/query-gen.js.map +1 -0
- package/esm/query-params.js +786 -0
- package/esm/query-params.js.map +1 -0
- package/esm/query.js +538 -0
- package/esm/query.js.map +1 -0
- package/esm/route.js +460 -0
- package/esm/route.js.map +1 -0
- package/esm/routes.json +107 -0
- package/esm/storage.js +46 -0
- package/esm/storage.js.map +1 -0
- package/esm/suspense.js +13 -0
- package/esm/suspense.js.map +1 -0
- package/esm/time.js +94 -0
- package/esm/time.js.map +1 -0
- package/esm/tnc-itinerary.json +1726 -0
- package/esm/ui.js +48 -0
- package/esm/ui.js.map +1 -0
- package/lib/otpSchema.json +0 -10
- package/lib/planQuery.graphql +0 -2
- package/lib/query-gen.d.ts +1 -2
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +1 -3
- package/lib/query-gen.js.map +1 -1
- package/package.json +3 -3
- package/src/otpSchema.json +0 -10
- package/src/planQuery.graphql +0 -2
- package/src/query-gen.ts +0 -3
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/core-utils.story.d.ts +0 -21
- package/lib/core-utils.story.d.ts.map +0 -1
- package/lib/core-utils.story.js +0 -69
- package/lib/core-utils.story.js.map +0 -1
- /package/{lib → esm/__tests__/__mocks__}/bike-rental-itinerary.json +0 -0
- /package/{lib → esm/__tests__/__mocks__}/config.json +0 -0
- /package/{lib → esm/__tests__/__mocks__}/fare-products-itinerary.json +0 -0
- /package/{lib → esm/__tests__/__mocks__}/routes.json +0 -0
- /package/{lib → esm/__tests__/__mocks__}/tnc-itinerary.json +0 -0
package/esm/routes.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"route1": {
|
|
3
|
+
"longName": "Across town",
|
|
4
|
+
"mode": "BUS",
|
|
5
|
+
"shortName": "10",
|
|
6
|
+
"sortOrder": 10
|
|
7
|
+
},
|
|
8
|
+
"route2": {
|
|
9
|
+
"longName": "Around town",
|
|
10
|
+
"mode": "BUS",
|
|
11
|
+
"shortName": "20",
|
|
12
|
+
"sortOrder": 2
|
|
13
|
+
},
|
|
14
|
+
"route3": {
|
|
15
|
+
"longName": "Around another town",
|
|
16
|
+
"shortName": "3",
|
|
17
|
+
"sortOrder": -999,
|
|
18
|
+
"type": 3
|
|
19
|
+
},
|
|
20
|
+
"route4": {
|
|
21
|
+
"longName": "Loop route",
|
|
22
|
+
"mode": "BUS",
|
|
23
|
+
"shortName": "2",
|
|
24
|
+
"sortOrder": -999
|
|
25
|
+
},
|
|
26
|
+
"route5": {
|
|
27
|
+
"longName": "A-line",
|
|
28
|
+
"mode": "BUS",
|
|
29
|
+
"shortName": "A",
|
|
30
|
+
"sortOrder": -999
|
|
31
|
+
},
|
|
32
|
+
"route6": {
|
|
33
|
+
"longName": "B-line",
|
|
34
|
+
"mode": "BUS",
|
|
35
|
+
"shortName": "B",
|
|
36
|
+
"sortOrder": -999
|
|
37
|
+
},
|
|
38
|
+
"route7": {
|
|
39
|
+
"longName": "A meandering route",
|
|
40
|
+
"mode": "BUS",
|
|
41
|
+
"sortOrder": -999
|
|
42
|
+
},
|
|
43
|
+
"route8": {
|
|
44
|
+
"longName": "Zig-zagging route",
|
|
45
|
+
"mode": "BUS",
|
|
46
|
+
"shortName": "30",
|
|
47
|
+
"sortOrder": 2
|
|
48
|
+
},
|
|
49
|
+
"route9": {
|
|
50
|
+
"longName": "Express route",
|
|
51
|
+
"mode": "BUS",
|
|
52
|
+
"shortName": "30",
|
|
53
|
+
"sortOrder": 2
|
|
54
|
+
},
|
|
55
|
+
"route10": {
|
|
56
|
+
"longName": "Variation of express route",
|
|
57
|
+
"mode": "BUS",
|
|
58
|
+
"shortName": "30",
|
|
59
|
+
"sortOrder": 2
|
|
60
|
+
},
|
|
61
|
+
"route11": {
|
|
62
|
+
"longName": "Local route",
|
|
63
|
+
"mode": "BUS",
|
|
64
|
+
"shortName": "6",
|
|
65
|
+
"sortOrder": 2
|
|
66
|
+
},
|
|
67
|
+
"route12": {
|
|
68
|
+
"longName": "Intercity Train",
|
|
69
|
+
"mode": "RAIL",
|
|
70
|
+
"shortName": "IC",
|
|
71
|
+
"sortOrder": 2
|
|
72
|
+
},
|
|
73
|
+
"route13": {
|
|
74
|
+
"longName": "Yellow line Subway",
|
|
75
|
+
"mode": "SUBWAY",
|
|
76
|
+
"shortName": "Yellow",
|
|
77
|
+
"sortOrder": 2
|
|
78
|
+
},
|
|
79
|
+
"route14": {
|
|
80
|
+
"longName": "Xpress route C",
|
|
81
|
+
"mode": "BUS",
|
|
82
|
+
"shortName": "30C",
|
|
83
|
+
"sortOrder": 2
|
|
84
|
+
},
|
|
85
|
+
"route15": {
|
|
86
|
+
"longName": "Express route X",
|
|
87
|
+
"mode": "BUS",
|
|
88
|
+
"shortName": "30X",
|
|
89
|
+
"sortOrder": 2
|
|
90
|
+
},
|
|
91
|
+
"route16": {
|
|
92
|
+
"agencyId": "abc",
|
|
93
|
+
"agencyName": "Agency 1",
|
|
94
|
+
"longName": "Intercity Train 2",
|
|
95
|
+
"mode": "RAIL",
|
|
96
|
+
"routeId": "1:it2",
|
|
97
|
+
"shortName": "IC"
|
|
98
|
+
},
|
|
99
|
+
"route17": {
|
|
100
|
+
"agencyId": "abc",
|
|
101
|
+
"agencyName": "Acclaimed agency 1",
|
|
102
|
+
"longName": "Express route X",
|
|
103
|
+
"mode": "BUS",
|
|
104
|
+
"routeId": "2:erx",
|
|
105
|
+
"shortName": "30X"
|
|
106
|
+
}
|
|
107
|
+
}
|
package/esm/storage.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// Prefix to use with local storage keys.
|
|
3
|
+
var STORAGE_PREFIX = "otp";
|
|
4
|
+
/**
|
|
5
|
+
* Store a javascript object at the specified key.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function storeItem(key, object) {
|
|
9
|
+
window.localStorage.setItem("".concat(STORAGE_PREFIX, ".").concat(key), JSON.stringify(object));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a javascript object at the specified key. If not found, defaults to
|
|
13
|
+
* null or, the optionally provided notFoundValue.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function getItem(key) {
|
|
17
|
+
var notFoundValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
18
|
+
var itemAsString;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
itemAsString = window.localStorage.getItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
22
|
+
var json = JSON.parse(itemAsString);
|
|
23
|
+
if (json) return json;
|
|
24
|
+
return notFoundValue;
|
|
25
|
+
} catch (e) {
|
|
26
|
+
// Catch any errors associated with parsing bad JSON.
|
|
27
|
+
console.warn(e, itemAsString);
|
|
28
|
+
return notFoundValue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Remove item at specified key.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export function removeItem(key) {
|
|
36
|
+
window.localStorage.removeItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate a random ID. This might not quite be a UUID, but it serves our
|
|
40
|
+
* purposes for now.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export function randId() {
|
|
44
|
+
return Math.random().toString(36).substr(2, 9);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storage.ts"],"names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","JSON","stringify","getItem","notFoundValue","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"mappings":"AAAA;AACA;AACA,IAAMA,cAAc,GAAG,KAAvB;AAEA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAmBC,GAAnB,EAAgCC,MAAhC,EAAuD;AAC5DC,EAAAA,MAAM,CAACC,YAAP,CAAoBC,OAApB,WACKN,cADL,cACuBE,GADvB,GAEEK,IAAI,CAACC,SAAL,CAAeL,MAAf,CAFF;AAID;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASM,OAAT,CAAiBP,GAAjB,EAAsE;AAAA,MAAxCQ,aAAwC,uEAAf,IAAe;AAC3E,MAAIC,YAAJ;;AACA,MAAI;AACFA,IAAAA,YAAY,GAAGP,MAAM,CAACC,YAAP,CAAoBI,OAApB,WAA+BT,cAA/B,cAAiDE,GAAjD,EAAf;AACA,QAAMU,IAAI,GAAGL,IAAI,CAACM,KAAL,CAAWF,YAAX,CAAb;AACA,QAAIC,IAAJ,EAAU,OAAOA,IAAP;AACV,WAAOF,aAAP;AACD,GALD,CAKE,OAAOI,CAAP,EAAU;AACV;AACAC,IAAAA,OAAO,CAACC,IAAR,CAAaF,CAAb,EAAgBH,YAAhB;AACA,WAAOD,aAAP;AACD;AACF;AAED;AACA;AACA;;AACA,OAAO,SAASO,UAAT,CAAoBf,GAApB,EAAuC;AAC5CE,EAAAA,MAAM,CAACC,YAAP,CAAoBY,UAApB,WAAkCjB,cAAlC,cAAoDE,GAApD;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASgB,MAAT,GAA0B;AAC/B,SAAOC,IAAI,CAACC,MAAL,GACJC,QADI,CACK,EADL,EAEJC,MAFI,CAEG,CAFH,EAEM,CAFN,CAAP;AAGD","sourcesContent":["/* eslint-disable no-console */\n// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key: string, object: unknown): void {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key: string, notFoundValue: unknown = null): unknown {\n let itemAsString: string;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key: string): void {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId(): string {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"file":"storage.js"}
|
package/esm/suspense.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { Suspense } from "react";
|
|
2
|
+
|
|
3
|
+
var SafeSuspense = function SafeSuspense(_ref) {
|
|
4
|
+
var children = _ref.children,
|
|
5
|
+
fallback = _ref.fallback;
|
|
6
|
+
var IS_TEST_RUNNER = window.navigator.userAgent.match(/StorybookTestRunner/);
|
|
7
|
+
return IS_TEST_RUNNER ? /*#__PURE__*/React.createElement(React.Fragment, null, fallback) : /*#__PURE__*/React.createElement(Suspense, {
|
|
8
|
+
fallback: fallback
|
|
9
|
+
}, children);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default SafeSuspense;
|
|
13
|
+
//# sourceMappingURL=suspense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/suspense.tsx"],"names":["React","Suspense","SafeSuspense","children","fallback","IS_TEST_RUNNER","window","navigator","userAgent","match"],"mappings":"AAAA,OAAOA,KAAP,IAAyCC,QAAzC,QAAyD,OAAzD;;AAOA,IAAMC,YAAY,GAAG,SAAfA,YAAe,OAAiD;AAAA,MAA9CC,QAA8C,QAA9CA,QAA8C;AAAA,MAApCC,QAAoC,QAApCA,QAAoC;AACpE,MAAMC,cAAc,GAAGC,MAAM,CAACC,SAAP,CAAiBC,SAAjB,CAA2BC,KAA3B,CACrB,qBADqB,CAAvB;AAGA,SAAOJ,cAAc,gBACnB,0CAAGD,QAAH,CADmB,gBAGnB,oBAAC,QAAD;AAAU,IAAA,QAAQ,EAAEA;AAApB,KAA+BD,QAA/B,CAHF;AAKD,CATD;;AAWA,eAAeD,YAAf","sourcesContent":["import React, { ReactElement, ReactNode, Suspense } from \"react\";\n\ntype Props = {\n children: ReactNode;\n fallback: ReactNode;\n};\n\nconst SafeSuspense = ({ children, fallback }: Props): ReactElement => {\n const IS_TEST_RUNNER = window.navigator.userAgent.match(\n /StorybookTestRunner/\n );\n return IS_TEST_RUNNER ? (\n <>{fallback}</>\n ) : (\n <Suspense fallback={fallback}>{children}</Suspense>\n );\n};\n\nexport default SafeSuspense;\n"],"file":"suspense.js"}
|
package/esm/time.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { startOfDay, add, format } from "date-fns";
|
|
2
|
+
import { utcToZonedTime } from "date-fns-tz"; // Date/time formats (per date-fns) when sending/receiving date from OTP
|
|
3
|
+
// regardless of whatever the user has configured as the display format.
|
|
4
|
+
|
|
5
|
+
export var OTP_API_DATE_FORMAT = "yyyy-MM-dd";
|
|
6
|
+
export var OTP_API_TIME_FORMAT = "HH:mm";
|
|
7
|
+
/**
|
|
8
|
+
* Breaks up a duration in seconds into hours, minutes, and seconds.
|
|
9
|
+
* @param {number} seconds The number of seconds to break up
|
|
10
|
+
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function toHoursMinutesSeconds(seconds) {
|
|
14
|
+
return {
|
|
15
|
+
hours: Math.floor(seconds / 3600),
|
|
16
|
+
minutes: Math.floor(seconds / 60) % 60,
|
|
17
|
+
seconds: seconds % 60
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @param {[type]} config the OTP config object found in store
|
|
22
|
+
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function getTimeFormat(config) {
|
|
26
|
+
var _config$dateTime;
|
|
27
|
+
|
|
28
|
+
return (config === null || config === void 0 ? void 0 : (_config$dateTime = config.dateTime) === null || _config$dateTime === void 0 ? void 0 : _config$dateTime.timeFormat) || OTP_API_TIME_FORMAT;
|
|
29
|
+
}
|
|
30
|
+
export function getDateFormat(config) {
|
|
31
|
+
var _config$dateTime2;
|
|
32
|
+
|
|
33
|
+
return (config === null || config === void 0 ? void 0 : (_config$dateTime2 = config.dateTime) === null || _config$dateTime2 === void 0 ? void 0 : _config$dateTime2.dateFormat) || OTP_API_DATE_FORMAT;
|
|
34
|
+
}
|
|
35
|
+
/** @deprecated */
|
|
36
|
+
|
|
37
|
+
export function getLongDateFormat(config) {
|
|
38
|
+
var _config$dateTime3;
|
|
39
|
+
|
|
40
|
+
return (config === null || config === void 0 ? void 0 : (_config$dateTime3 = config.dateTime) === null || _config$dateTime3 === void 0 ? void 0 : _config$dateTime3.longDateFormat) || "D MMMM YYYY";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Offsets a time according to the provided time options
|
|
44
|
+
* and returns the result.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export function offsetTime(ms, options) {
|
|
48
|
+
return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Formats a seconds after midnight value for display in narrative
|
|
52
|
+
* @param {number} seconds time since midnight in seconds
|
|
53
|
+
* @param {string} timeFormat A valid date-fns time format
|
|
54
|
+
* @return {string} formatted text representation
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export function formatSecondsAfterMidnight(seconds, timeFormat) {
|
|
58
|
+
var time = add(startOfDay(new Date()), {
|
|
59
|
+
seconds: seconds
|
|
60
|
+
});
|
|
61
|
+
return format(time, timeFormat);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Uses Intl.DateTimeFormat() api to get the user's time zone. In a test
|
|
65
|
+
* environment, pulls timezone information from an env variable. Default to
|
|
66
|
+
* GMT+0 if the Intl API is unavailable.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export function getUserTimezone() {
|
|
70
|
+
var _Intl;
|
|
71
|
+
|
|
72
|
+
var fallbackTimezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "Etc/Greenwich";
|
|
73
|
+
if (process.env.NODE_ENV === "test") return process.env.TZ;
|
|
74
|
+
return ((_Intl = Intl) === null || _Intl === void 0 ? void 0 : _Intl.DateTimeFormat().resolvedOptions().timeZone) || fallbackTimezone;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Formats current time for use in OTP query
|
|
78
|
+
* The conversion to the user's timezone is needed for testing purposes.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export function getCurrentTime() {
|
|
82
|
+
var timezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getUserTimezone();
|
|
83
|
+
return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Formats current date for use in OTP query
|
|
87
|
+
* The conversion to the user's timezone is needed for testing purposes.
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export function getCurrentDate() {
|
|
91
|
+
var timezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getUserTimezone();
|
|
92
|
+
return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=time.js.map
|
package/esm/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AACA,SAASA,UAAT,EAAqBC,GAArB,EAA0BC,MAA1B,QAAwC,UAAxC;AACA,SAASC,cAAT,QAA+B,aAA/B,C,CAEA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAA5B;AACP,OAAO,IAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CACLC,OADK,EAML;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEC,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,IAArB,CADF;AAELI,IAAAA,OAAO,EAAEF,IAAI,CAACC,KAAL,CAAWH,OAAO,GAAG,EAArB,IAA2B,EAF/B;AAGLA,IAAAA,OAAO,EAAEA,OAAO,GAAG;AAHd,GAAP;AAKD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASK,aAAT,CAAuBC,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,gCAAAA,MAAM,CAAEC,QAAR,sEAAkBC,UAAlB,KAAgCV,mBAAvC;AACD;AAED,OAAO,SAASW,aAAT,CAAuBH,MAAvB,EAA+C;AAAA;;AACpD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,iCAAAA,MAAM,CAAEC,QAAR,wEAAkBG,UAAlB,KAAgCb,mBAAvC;AACD;AAED;;AACA,OAAO,SAASc,iBAAT,CAA2BL,MAA3B,EAAmD;AAAA;;AACxD,SAAO,CAAAA,MAAM,SAAN,IAAAA,MAAM,WAAN,iCAAAA,MAAM,CAAEC,QAAR,wEAAkBK,cAAlB,KAAoC,aAA3C;AACD;AACD;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAoBC,EAApB,EAAwBC,OAAxB,EAAiC;AACtC,SAAOD,EAAE,IAAI,CAAAC,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,MAAT,KAAmB,CAAvB,CAAT;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,0BAAT,CACLjB,OADK,EAELQ,UAFK,EAGG;AACR,MAAMU,IAAI,GAAGxB,GAAG,CAACD,UAAU,CAAC,IAAI0B,IAAJ,EAAD,CAAX,EAAyB;AAAEnB,IAAAA,OAAO,EAAPA;AAAF,GAAzB,CAAhB;AACA,SAAOL,MAAM,CAACuB,IAAD,EAAOV,UAAP,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASY,eAAT,GAAqE;AAAA;;AAAA,MAA5CC,gBAA4C,uEAAzB,eAAyB;AAC1E,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC,OAAOF,OAAO,CAACC,GAAR,CAAYE,EAAnB;AACrC,SAAO,UAAAC,IAAI,UAAJ,sCAAMC,cAAN,GAAuBC,eAAvB,GAAyCC,QAAzC,KAAqDR,gBAA5D;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASS,cAAT,GAA8D;AAAA,MAAtCC,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAOzB,MAAM,CAACC,cAAc,CAACuB,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuCjC,mBAAvC,CAAb;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASmC,cAAT,GAA8D;AAAA,MAAtCF,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAOzB,MAAM,CAACC,cAAc,CAACuB,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuClC,mBAAvC,CAAb;AACD","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\n/** @deprecated */\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"file":"time.js"}
|