@opentripplanner/core-utils 13.0.0-alpha.4 → 13.0.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/README.md +0 -4
- package/esm/__mocks__/fake-route-data.story.json +5425 -0
- package/esm/__mocks__/fake-transit-operators.story.json +97 -0
- package/esm/__tests__/__mocks__/routes.json +234 -105
- package/esm/itinerary.js +4 -2
- package/esm/itinerary.js.map +1 -1
- package/esm/otpSchema.json +0 -12
- package/esm/profile.js +1 -1
- package/esm/profile.js.map +1 -1
- package/esm/query-gen.js +2 -4
- package/esm/query-gen.js.map +1 -1
- package/esm/query.js +1 -4
- package/esm/query.js.map +1 -1
- package/esm/route.js +36 -21
- package/esm/route.js.map +1 -1
- package/esm/routes.json +234 -105
- package/esm/storage.js +2 -6
- package/esm/storage.js.map +1 -1
- package/esm/time.js +10 -0
- package/esm/time.js.map +1 -1
- package/lib/__mocks__/fake-route-data.story.json +5425 -0
- package/lib/__mocks__/fake-transit-operators.story.json +97 -0
- package/lib/__tests__/__mocks__/routes.json +234 -105
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +4 -2
- package/lib/itinerary.js.map +1 -1
- package/lib/otpSchema.json +0 -12
- package/lib/profile.js +1 -1
- package/lib/profile.js.map +1 -1
- package/lib/query-gen.js +2 -2
- package/lib/query-gen.js.map +1 -1
- package/lib/query.js +1 -4
- package/lib/query.js.map +1 -1
- package/lib/route.d.ts +35 -1
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +38 -17
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js +2 -6
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +7 -0
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +10 -1
- package/lib/time.js.map +1 -1
- package/package.json +4 -4
- package/src/__mocks__/fake-route-data.story.json +5425 -0
- package/src/__mocks__/fake-transit-operators.story.json +97 -0
- package/src/__snapshots__/core-utils.story.tsx.snap +8382 -0
- package/src/__tests__/__mocks__/routes.json +234 -105
- package/src/__tests__/__snapshots__/route.js.snap +285 -95
- package/src/__tests__/route.js +27 -55
- package/src/core-utils.story.tsx +201 -2
- package/src/itinerary.ts +3 -2
- package/src/otpSchema.json +0 -12
- package/src/profile.js +1 -1
- package/src/query-gen.ts +2 -2
- package/src/query.js +1 -4
- package/src/route.ts +41 -21
- package/src/storage.ts +5 -9
- package/src/time.ts +9 -0
- package/tsconfig.tsbuildinfo +1 -1
package/esm/routes.json
CHANGED
|
@@ -1,107 +1,236 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
2
|
+
"otp1Routes": [
|
|
3
|
+
{
|
|
4
|
+
"agencyId": "bcd",
|
|
5
|
+
"longName": "Across town",
|
|
6
|
+
"mode": "BUS",
|
|
7
|
+
"shortName": "10",
|
|
8
|
+
"sortOrder": 10
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"agencyId": "bcd",
|
|
12
|
+
"longName": "Around town",
|
|
13
|
+
"mode": "BUS",
|
|
14
|
+
"shortName": "20",
|
|
15
|
+
"sortOrder": 2
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"agencyId": "bcd",
|
|
19
|
+
"longName": "Around another town",
|
|
20
|
+
"shortName": "3",
|
|
21
|
+
"sortOrder": -999,
|
|
22
|
+
"type": 3
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"agencyId": "bcd",
|
|
26
|
+
"longName": "Loop route",
|
|
27
|
+
"mode": "BUS",
|
|
28
|
+
"shortName": "2",
|
|
29
|
+
"sortOrder": -999
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"agencyId": "bcd",
|
|
33
|
+
"longName": "A-line",
|
|
34
|
+
"mode": "BUS",
|
|
35
|
+
"shortName": "A",
|
|
36
|
+
"sortOrder": -999
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"agencyId": "bcd",
|
|
40
|
+
"longName": "B-line",
|
|
41
|
+
"mode": "BUS",
|
|
42
|
+
"shortName": "B",
|
|
43
|
+
"sortOrder": -999
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"agencyId": "bcd",
|
|
47
|
+
"longName": "A meandering route",
|
|
48
|
+
"mode": "BUS",
|
|
49
|
+
"sortOrder": -999
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"agencyId": "bcd",
|
|
53
|
+
"longName": "Zig-zagging route",
|
|
54
|
+
"mode": "BUS",
|
|
55
|
+
"shortName": "30",
|
|
56
|
+
"sortOrder": 2
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"agencyId": "bcd",
|
|
60
|
+
"longName": "Express route",
|
|
61
|
+
"mode": "BUS",
|
|
62
|
+
"shortName": "30",
|
|
63
|
+
"sortOrder": 2
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"agencyId": "bcd",
|
|
67
|
+
"longName": "Variation of express route",
|
|
68
|
+
"mode": "BUS",
|
|
69
|
+
"shortName": "30",
|
|
70
|
+
"sortOrder": 2
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"agencyId": "bcd",
|
|
74
|
+
"longName": "Local route",
|
|
75
|
+
"mode": "BUS",
|
|
76
|
+
"shortName": "6",
|
|
77
|
+
"sortOrder": 2
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"agencyId": "bcd",
|
|
81
|
+
"longName": "Intercity Train",
|
|
82
|
+
"mode": "RAIL",
|
|
83
|
+
"shortName": "IC",
|
|
84
|
+
"sortOrder": 2
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"agencyId": "bcd",
|
|
88
|
+
"longName": "Yellow line Subway",
|
|
89
|
+
"mode": "SUBWAY",
|
|
90
|
+
"shortName": "Yellow",
|
|
91
|
+
"sortOrder": 2
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"agencyId": "bcd",
|
|
95
|
+
"longName": "Xpress route C",
|
|
96
|
+
"mode": "BUS",
|
|
97
|
+
"shortName": "30C",
|
|
98
|
+
"sortOrder": 2
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"agencyId": "bcd",
|
|
102
|
+
"longName": "Express route X",
|
|
103
|
+
"mode": "BUS",
|
|
104
|
+
"shortName": "30X"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"agencyId": "abc",
|
|
108
|
+
"agencyName": "Agency 1",
|
|
109
|
+
"longName": "Intercity Train 2",
|
|
110
|
+
"mode": "RAIL",
|
|
111
|
+
"routeId": "1:it2",
|
|
112
|
+
"shortName": "IC",
|
|
113
|
+
"sortOrder": 10
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"agencyId": "abc",
|
|
117
|
+
"agencyName": "Acclaimed agency 1",
|
|
118
|
+
"longName": "Express route X",
|
|
119
|
+
"mode": "BUS",
|
|
120
|
+
"routeId": "2:erx",
|
|
121
|
+
"shortName": "30X",
|
|
122
|
+
"sortOrder": 10
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"otp2Routes": [
|
|
126
|
+
{
|
|
127
|
+
"longName": "Across town",
|
|
128
|
+
"mode": "BUS",
|
|
129
|
+
"shortName": "10",
|
|
130
|
+
"sortOrder": 10
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"longName": "Around town",
|
|
134
|
+
"mode": "BUS",
|
|
135
|
+
"shortName": "20",
|
|
136
|
+
"sortOrder": 2
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"longName": "Around another town",
|
|
140
|
+
"shortName": "3",
|
|
141
|
+
"sortOrder": null,
|
|
142
|
+
"type": 3
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"longName": "Loop route",
|
|
146
|
+
"mode": "BUS",
|
|
147
|
+
"shortName": "2",
|
|
148
|
+
"sortOrder": -999
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"longName": "A-line",
|
|
152
|
+
"mode": "BUS",
|
|
153
|
+
"shortName": "A",
|
|
154
|
+
"sortOrder": -999
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"longName": "B-line",
|
|
158
|
+
"mode": "BUS",
|
|
159
|
+
"shortName": "B"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"longName": "A meandering route",
|
|
163
|
+
"mode": "BUS"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"longName": "Zig-zagging route",
|
|
167
|
+
"mode": "BUS",
|
|
168
|
+
"shortName": "30",
|
|
169
|
+
"sortOrder": 2
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"longName": "Express route",
|
|
173
|
+
"mode": "BUS",
|
|
174
|
+
"shortName": "30",
|
|
175
|
+
"sortOrder": 2
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"longName": "Variation of express route",
|
|
179
|
+
"mode": "BUS",
|
|
180
|
+
"shortName": "30",
|
|
181
|
+
"sortOrder": 2
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"longName": "Local route",
|
|
185
|
+
"mode": "BUS",
|
|
186
|
+
"shortName": "6",
|
|
187
|
+
"sortOrder": 2
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"longName": "Intercity Train",
|
|
191
|
+
"mode": "RAIL",
|
|
192
|
+
"shortName": "IC",
|
|
193
|
+
"sortOrder": 2
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"longName": "Yellow line Subway",
|
|
197
|
+
"mode": "SUBWAY",
|
|
198
|
+
"shortName": "Yellow",
|
|
199
|
+
"sortOrder": 2
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"longName": "Xpress route C",
|
|
203
|
+
"mode": "BUS",
|
|
204
|
+
"shortName": "30C",
|
|
205
|
+
"sortOrder": 2
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"longName": "Express route X",
|
|
209
|
+
"mode": "BUS",
|
|
210
|
+
"shortName": "30X",
|
|
211
|
+
"sortOrder": 2
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"agency": {
|
|
215
|
+
"name": "Agency 1",
|
|
216
|
+
"id": "abc"
|
|
217
|
+
},
|
|
218
|
+
"longName": "Intercity Train 2",
|
|
219
|
+
"mode": "RAIL",
|
|
220
|
+
"routeId": "1:it2",
|
|
221
|
+
"shortName": "IC",
|
|
222
|
+
"sortOrder": 2
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"agency": {
|
|
226
|
+
"name": "Acclaimed agency 1",
|
|
227
|
+
"id": "abc"
|
|
228
|
+
},
|
|
229
|
+
"longName": "Express route X",
|
|
230
|
+
"mode": "BUS",
|
|
231
|
+
"routeId": "2:erx",
|
|
232
|
+
"shortName": "30X",
|
|
233
|
+
"sortOrder": 2
|
|
234
|
+
}
|
|
235
|
+
]
|
|
107
236
|
}
|
package/esm/storage.js
CHANGED
|
@@ -6,9 +6,7 @@ var STORAGE_PREFIX = "otp";
|
|
|
6
6
|
* Store a javascript object at the specified key.
|
|
7
7
|
*/
|
|
8
8
|
export function storeItem(key, object) {
|
|
9
|
-
|
|
10
|
-
window.localStorage.setItem("".concat(STORAGE_PREFIX, ".").concat(key), JSON.stringify(object));
|
|
11
|
-
}
|
|
9
|
+
window.localStorage.setItem("".concat(STORAGE_PREFIX, ".").concat(key), JSON.stringify(object));
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -34,9 +32,7 @@ export function getItem(key) {
|
|
|
34
32
|
* Remove item at specified key.
|
|
35
33
|
*/
|
|
36
34
|
export function removeItem(key) {
|
|
37
|
-
|
|
38
|
-
window.localStorage.removeItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
39
|
-
}
|
|
35
|
+
window.localStorage.removeItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
/**
|
package/esm/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","concat","JSON","stringify","getItem","notFoundValue","arguments","length","undefined","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"sources":["../src/storage.ts"],"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
|
|
1
|
+
{"version":3,"file":"storage.js","names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","concat","JSON","stringify","getItem","notFoundValue","arguments","length","undefined","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"sources":["../src/storage.ts"],"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"],"mappings":"AAAA;AACA;AACA,IAAMA,cAAc,GAAG,KAAK;;AAE5B;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,GAAW,EAAEC,MAAe,EAAQ;EAC5DC,MAAM,CAACC,YAAY,CAACC,OAAO,IAAAC,MAAA,CACtBP,cAAc,OAAAO,MAAA,CAAIL,GAAG,GACxBM,IAAI,CAACC,SAAS,CAACN,MAAM,CACvB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASO,OAAOA,CAACR,GAAW,EAA0C;EAAA,IAAxCS,aAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAChE,IAAIG,YAAoB;EACxB,IAAI;IACFA,YAAY,GAAGX,MAAM,CAACC,YAAY,CAACK,OAAO,IAAAH,MAAA,CAAIP,cAAc,OAAAO,MAAA,CAAIL,GAAG,CAAE,CAAC;IACtE,IAAMc,IAAI,GAAGR,IAAI,CAACS,KAAK,CAACF,YAAY,CAAC;IACrC,IAAIC,IAAI,EAAE,OAAOA,IAAI;IACrB,OAAOL,aAAa;EACtB,CAAC,CAAC,OAAOO,CAAC,EAAE;IACV;IACAC,OAAO,CAACC,IAAI,CAACF,CAAC,EAAEH,YAAY,CAAC;IAC7B,OAAOJ,aAAa;EACtB;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASU,UAAUA,CAACnB,GAAW,EAAQ;EAC5CE,MAAM,CAACC,YAAY,CAACgB,UAAU,IAAAd,MAAA,CAAIP,cAAc,OAAAO,MAAA,CAAIL,GAAG,CAAE,CAAC;AAC5D;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASoB,MAAMA,CAAA,EAAW;EAC/B,OAAOC,IAAI,CAACC,MAAM,CAAC,CAAC,CACjBC,QAAQ,CAAC,EAAE,CAAC,CACZC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACjB","ignoreList":[]}
|
package/esm/time.js
CHANGED
|
@@ -19,6 +19,16 @@ export function toHoursMinutesSeconds(seconds) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* If a duration is less than 60 seconds, round it to one minute, to avoid a duration
|
|
24
|
+
* of 0 minutes on a leg.
|
|
25
|
+
* @param {number} duration The leg or trip duration in seconds
|
|
26
|
+
* @returns a duration in seconds of at least 60 seconds.
|
|
27
|
+
*/
|
|
28
|
+
export var ensureAtLeastOneMinute = function ensureAtLeastOneMinute(duration) {
|
|
29
|
+
return duration < 60 ? 60 : duration;
|
|
30
|
+
};
|
|
31
|
+
|
|
22
32
|
/**
|
|
23
33
|
* @param {[type]} config the OTP config object found in store
|
|
24
34
|
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","_config$dateTime","dateTime","timeFormat","getDateFormat","_config$dateTime2","dateFormat","getLongDateFormat","_config$dateTime3","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","_Intl","fallbackTimezone","arguments","length","undefined","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"sources":["../src/time.ts"],"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"],"mappings":"AACA,SAASA,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,UAAU;AAClD,SAASC,cAAc,QAAQ,aAAa;;AAE5C;AACA;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAAY;AAC/C,OAAO,IAAMC,mBAAmB,GAAG,OAAO;;AAE1C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,OAAe,EAKf;EACA,OAAO;IACLC,KAAK,EAAEC,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,IAAI,CAAC;IACjCI,OAAO,EAAEF,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;IACtCA,OAAO,EAAEA,OAAO,GAAG;EACrB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"time.js","names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","ensureAtLeastOneMinute","duration","getTimeFormat","config","_config$dateTime","dateTime","timeFormat","getDateFormat","_config$dateTime2","dateFormat","getLongDateFormat","_config$dateTime3","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","_Intl","fallbackTimezone","arguments","length","undefined","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"sources":["../src/time.ts"],"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 * If a duration is less than 60 seconds, round it to one minute, to avoid a duration\n * of 0 minutes on a leg.\n * @param {number} duration The leg or trip duration in seconds\n * @returns a duration in seconds of at least 60 seconds.\n */\nexport const ensureAtLeastOneMinute = (duration: number): number =>\n duration < 60 ? 60 : duration;\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"],"mappings":"AACA,SAASA,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,UAAU;AAClD,SAASC,cAAc,QAAQ,aAAa;;AAE5C;AACA;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAAY;AAC/C,OAAO,IAAMC,mBAAmB,GAAG,OAAO;;AAE1C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,OAAe,EAKf;EACA,OAAO;IACLC,KAAK,EAAEC,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,IAAI,CAAC;IACjCI,OAAO,EAAEF,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;IACtCA,OAAO,EAAEA,OAAO,GAAG;EACrB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMK,sBAAsB,GAAG,SAAzBA,sBAAsBA,CAAIC,QAAgB;EAAA,OACrDA,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAGA,QAAQ;AAAA;;AAE/B;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,MAAc,EAAU;EAAA,IAAAC,gBAAA;EACpD,OAAO,CAAAD,MAAM,aAANA,MAAM,gBAAAC,gBAAA,GAAND,MAAM,CAAEE,QAAQ,cAAAD,gBAAA,uBAAhBA,gBAAA,CAAkBE,UAAU,KAAIb,mBAAmB;AAC5D;AAEA,OAAO,SAASc,aAAaA,CAACJ,MAAc,EAAU;EAAA,IAAAK,iBAAA;EACpD,OAAO,CAAAL,MAAM,aAANA,MAAM,gBAAAK,iBAAA,GAANL,MAAM,CAAEE,QAAQ,cAAAG,iBAAA,uBAAhBA,iBAAA,CAAkBC,UAAU,KAAIjB,mBAAmB;AAC5D;;AAEA;AACA,OAAO,SAASkB,iBAAiBA,CAACP,MAAc,EAAU;EAAA,IAAAQ,iBAAA;EACxD,OAAO,CAAAR,MAAM,aAANA,MAAM,gBAAAQ,iBAAA,GAANR,MAAM,CAAEE,QAAQ,cAAAM,iBAAA,uBAAhBA,iBAAA,CAAkBC,cAAc,KAAI,aAAa;AAC1D;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,EAAE,EAAEC,OAAO,EAAE;EACtC,OAAOD,EAAE,IAAI,CAAAC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,MAAM,KAAI,CAAC,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,0BAA0BA,CACxCtB,OAAe,EACfW,UAAkB,EACV;EACR,IAAMY,IAAI,GAAG7B,GAAG,CAACD,UAAU,CAAC,IAAI+B,IAAI,CAAC,CAAC,CAAC,EAAE;IAAExB,OAAO,EAAPA;EAAQ,CAAC,CAAC;EACrD,OAAOL,MAAM,CAAC4B,IAAI,EAAEZ,UAAU,CAAC;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASc,eAAeA,CAAA,EAA6C;EAAA,IAAAC,KAAA;EAAA,IAA5CC,gBAAgB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,eAAe;EAChE,IAAIG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,EAAE,OAAOF,OAAO,CAACC,GAAG,CAACE,EAAE;EAC1D,OAAO,EAAAR,KAAA,GAAAS,IAAI,cAAAT,KAAA,uBAAJA,KAAA,CAAMU,cAAc,CAAC,CAAC,CAACC,eAAe,CAAC,CAAC,CAACC,QAAQ,KAAIX,gBAAgB;AAC9E;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASY,cAAcA,CAAA,EAAuC;EAAA,IAAtCC,QAAQ,GAAAZ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGH,eAAe,CAAC,CAAC;EACzD,OAAO9B,MAAM,CAACC,cAAc,CAAC4B,IAAI,CAACiB,GAAG,CAAC,CAAC,EAAED,QAAQ,CAAC,EAAE1C,mBAAmB,CAAC;AAC1E;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAAS4C,cAAcA,CAAA,EAAuC;EAAA,IAAtCF,QAAQ,GAAAZ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGH,eAAe,CAAC,CAAC;EACzD,OAAO9B,MAAM,CAACC,cAAc,CAAC4B,IAAI,CAACiB,GAAG,CAAC,CAAC,EAAED,QAAQ,CAAC,EAAE3C,mBAAmB,CAAC;AAC1E","ignoreList":[]}
|