@opentripplanner/core-utils 4.9.0 → 4.11.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/deprecated.js +9 -1
- package/esm/deprecated.js.map +1 -1
- package/esm/profile.js +1 -1
- package/esm/profile.js.map +1 -1
- package/esm/query-params.js +28 -6
- package/esm/query-params.js.map +1 -1
- package/esm/query.js +1 -1
- package/esm/query.js.map +1 -1
- package/esm/time.js +27 -4
- package/esm/time.js.map +1 -1
- package/lib/deprecated.js +8 -1
- package/lib/deprecated.js.map +1 -1
- package/lib/profile.js +1 -1
- package/lib/profile.js.map +1 -1
- package/lib/query-params.js +24 -6
- package/lib/query-params.js.map +1 -1
- package/lib/query.js +1 -1
- package/lib/query.js.map +1 -1
- package/lib/time.js +30 -3
- package/lib/time.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/query-params.js.snap +15 -6
- package/src/deprecated.js +8 -1
- package/src/profile.js +1 -1
- package/src/query-params.js +28 -7
- package/src/query.js +1 -0
- package/src/time.js +28 -3
package/src/query-params.js
CHANGED
|
@@ -168,7 +168,14 @@ const queryParams = [
|
|
|
168
168
|
name: "maxWalkDistance",
|
|
169
169
|
routingTypes: ["ITINERARY"],
|
|
170
170
|
applicable: query =>
|
|
171
|
-
|
|
171
|
+
/* Since this query variable isn't in this list, it's not included in the generated query
|
|
172
|
+
* It does however allow us to determine if we should show the OTP1 max walk distance
|
|
173
|
+
* dropdown or the OTP2 walk reluctance slider
|
|
174
|
+
*/
|
|
175
|
+
!query.otp2 &&
|
|
176
|
+
query.mode &&
|
|
177
|
+
hasTransit(query.mode) &&
|
|
178
|
+
query.mode.indexOf("WALK") !== -1,
|
|
172
179
|
default: 1207, // 3/4 mi.
|
|
173
180
|
selector: "DROPDOWN",
|
|
174
181
|
label: "Maximum Walk",
|
|
@@ -271,7 +278,8 @@ const queryParams = [
|
|
|
271
278
|
{
|
|
272
279
|
/* optimize -- how to optimize a trip (non-bike, non-micromobility trips) */
|
|
273
280
|
name: "optimize",
|
|
274
|
-
applicable: query =>
|
|
281
|
+
applicable: query =>
|
|
282
|
+
!query.otp2 && hasTransit(query.mode) && !hasBike(query.mode),
|
|
275
283
|
routingTypes: ["ITINERARY"],
|
|
276
284
|
default: "QUICK",
|
|
277
285
|
selector: "DROPDOWN",
|
|
@@ -291,7 +299,7 @@ const queryParams = [
|
|
|
291
299
|
{
|
|
292
300
|
/* optimizeBike -- how to optimize an bike-based trip */
|
|
293
301
|
name: "optimizeBike",
|
|
294
|
-
applicable: query => hasBike(query.mode),
|
|
302
|
+
applicable: query => !query.otp2 && hasBike(query.mode),
|
|
295
303
|
routingTypes: ["ITINERARY"],
|
|
296
304
|
default: "SAFE",
|
|
297
305
|
selector: "DROPDOWN",
|
|
@@ -390,6 +398,23 @@ const queryParams = [
|
|
|
390
398
|
]
|
|
391
399
|
},
|
|
392
400
|
|
|
401
|
+
{
|
|
402
|
+
name: "walkReluctance",
|
|
403
|
+
routingTypes: ["ITINERARY", "PROFILE"],
|
|
404
|
+
selector: "SLIDER",
|
|
405
|
+
low: 0.5,
|
|
406
|
+
high: 20,
|
|
407
|
+
step: 0.5,
|
|
408
|
+
label: "walk reluctance",
|
|
409
|
+
labelLow: "More Walking",
|
|
410
|
+
labelHigh: "More Transit",
|
|
411
|
+
applicable: query =>
|
|
412
|
+
/* Since this query variable isn't in this list, it's not included in the generated query
|
|
413
|
+
* It does however allow us to determine if we should show the OTP1 max walk distance
|
|
414
|
+
* dropdown or the OTP2 walk reluctance slider
|
|
415
|
+
*/
|
|
416
|
+
!!query.otp2 && query.mode && query.mode.indexOf("WALK") !== -1
|
|
417
|
+
},
|
|
393
418
|
{
|
|
394
419
|
/* maxBikeTime -- the maximum time the user will spend biking in minutes */
|
|
395
420
|
name: "maxBikeTime",
|
|
@@ -673,10 +698,6 @@ const queryParams = [
|
|
|
673
698
|
name: "maxPreTransitTime",
|
|
674
699
|
routingTypes: ["ITINERARY"]
|
|
675
700
|
},
|
|
676
|
-
{
|
|
677
|
-
name: "walkReluctance",
|
|
678
|
-
routingTypes: ["ITINERARY"]
|
|
679
|
-
},
|
|
680
701
|
{
|
|
681
702
|
name: "waitReluctance",
|
|
682
703
|
routingTypes: ["ITINERARY"]
|
package/src/query.js
CHANGED
package/src/time.js
CHANGED
|
@@ -65,6 +65,22 @@ function formatDurationLikeMoment(
|
|
|
65
65
|
}
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Breaks up a duration in seconds into hours, minutes, and seconds.
|
|
71
|
+
* @param {number} seconds The number of seconds to break up
|
|
72
|
+
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
73
|
+
*/
|
|
74
|
+
export function toHoursMinutesSeconds(seconds) {
|
|
75
|
+
const hours = Math.floor(seconds / 3600);
|
|
76
|
+
const minutes = Math.floor((seconds - hours * 3600) / 60);
|
|
77
|
+
return {
|
|
78
|
+
hours,
|
|
79
|
+
minutes,
|
|
80
|
+
seconds: seconds - hours * 3600 - minutes * 60
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
68
84
|
/**
|
|
69
85
|
* @param {[type]} config the OTP config object found in store
|
|
70
86
|
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
|
@@ -93,13 +109,22 @@ export function formatDuration(seconds) {
|
|
|
93
109
|
|
|
94
110
|
/**
|
|
95
111
|
* Formats an elapsed time in seconds, minutes, hours duration for display in narrative
|
|
96
|
-
* TODO: internationalization
|
|
97
112
|
* @param {number} seconds duration in seconds
|
|
98
|
-
* @
|
|
113
|
+
* @param {object} region an object that allows internationalization of the time
|
|
114
|
+
* @returns {string} formatted text representation
|
|
99
115
|
*/
|
|
100
116
|
export function formatDurationWithSeconds(seconds, region) {
|
|
101
117
|
return formatDurationLikeMoment(seconds, { enabled: true, code: region });
|
|
102
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Offsets a time according to the provided time options
|
|
122
|
+
* and returns the result.
|
|
123
|
+
*/
|
|
124
|
+
export function offsetTime(ms, options) {
|
|
125
|
+
return ms + (options?.offset || 0);
|
|
126
|
+
}
|
|
127
|
+
|
|
103
128
|
/**
|
|
104
129
|
* Formats a time value for display in narrative
|
|
105
130
|
* TODO: internationalization/timezone
|
|
@@ -108,7 +133,7 @@ export function formatDurationWithSeconds(seconds, region) {
|
|
|
108
133
|
*/
|
|
109
134
|
export function formatTime(ms, options) {
|
|
110
135
|
return format(
|
|
111
|
-
ms
|
|
136
|
+
offsetTime(ms, options),
|
|
112
137
|
options?.format || OTP_API_TIME_FORMAT
|
|
113
138
|
);
|
|
114
139
|
}
|