@opentripplanner/core-utils 4.8.1-alpha → 4.10.0
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 +309 -0
- package/esm/deprecated.js.map +1 -0
- package/esm/itinerary.js +16 -247
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +9 -25
- package/esm/map.js.map +1 -1
- package/esm/messages.js +4 -0
- package/esm/messages.js.map +1 -1
- package/esm/profile.js +7 -12
- package/esm/profile.js.map +1 -1
- package/esm/query-params.js +10 -7
- package/esm/query-params.js.map +1 -1
- package/esm/query.js +4 -19
- package/esm/query.js.map +1 -1
- package/esm/time.js +36 -6
- package/esm/time.js.map +1 -1
- package/lib/deprecated.js +338 -0
- package/lib/deprecated.js.map +1 -0
- package/lib/itinerary.js +64 -258
- package/lib/itinerary.js.map +1 -1
- package/lib/map.js +26 -32
- package/lib/map.js.map +1 -1
- package/lib/messages.js +5 -0
- package/lib/messages.js.map +1 -1
- package/lib/profile.js +7 -12
- package/lib/profile.js.map +1 -1
- package/lib/query-params.js +11 -6
- package/lib/query-params.js.map +1 -1
- package/lib/query.js +9 -14
- package/lib/query.js.map +1 -1
- package/lib/time.js +39 -5
- package/lib/time.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/query-params.js.snap +1 -1
- package/src/__tests__/__snapshots__/query.js.snap +6 -6
- package/src/deprecated.js +310 -0
- package/src/itinerary.js +33 -221
- package/src/map.js +13 -25
- package/src/messages.js +4 -0
- package/src/profile.js +6 -16
- package/src/query-params.js +13 -5
- package/src/query.js +6 -26
- package/src/time.js +35 -5
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import moment from "moment"; // Need to avoid cyclic dependency resolution
|
|
2
|
+
|
|
3
|
+
/* eslint-disable global-require */
|
|
4
|
+
|
|
5
|
+
export function logDeprecationWarning(method, alternative) {
|
|
6
|
+
console.warn("".concat(method || "This method", " is deprecated and will be removed in a future otp-ui release. All language functionality should be handled using react-intl.\n ").concat(alternative ? "\n\n Use ".concat(alternative, " instead, which provides a new interface that doesn't return English strings.") : ""));
|
|
7
|
+
} // itinerary.js
|
|
8
|
+
|
|
9
|
+
export function getStepDirection(step) {
|
|
10
|
+
logDeprecationWarning("getStepDirection");
|
|
11
|
+
|
|
12
|
+
switch (step.relativeDirection) {
|
|
13
|
+
case "DEPART":
|
|
14
|
+
return "Head ".concat(step.absoluteDirection.toLowerCase());
|
|
15
|
+
|
|
16
|
+
case "LEFT":
|
|
17
|
+
return "Left";
|
|
18
|
+
|
|
19
|
+
case "HARD_LEFT":
|
|
20
|
+
return "Hard left";
|
|
21
|
+
|
|
22
|
+
case "SLIGHTLY_LEFT":
|
|
23
|
+
return "Slight left";
|
|
24
|
+
|
|
25
|
+
case "CONTINUE":
|
|
26
|
+
return "Continue";
|
|
27
|
+
|
|
28
|
+
case "SLIGHTLY_RIGHT":
|
|
29
|
+
return "Slight right";
|
|
30
|
+
|
|
31
|
+
case "RIGHT":
|
|
32
|
+
return "Right";
|
|
33
|
+
|
|
34
|
+
case "HARD_RIGHT":
|
|
35
|
+
return "Hard right";
|
|
36
|
+
|
|
37
|
+
case "CIRCLE_CLOCKWISE":
|
|
38
|
+
return "Follow circle clockwise";
|
|
39
|
+
|
|
40
|
+
case "CIRCLE_COUNTERCLOCKWISE":
|
|
41
|
+
return "Follow circle counterclockwise";
|
|
42
|
+
|
|
43
|
+
case "ELEVATOR":
|
|
44
|
+
return "Take elevator";
|
|
45
|
+
|
|
46
|
+
case "UTURN_LEFT":
|
|
47
|
+
return "Left U-turn";
|
|
48
|
+
|
|
49
|
+
case "UTURN_RIGHT":
|
|
50
|
+
return "Right U-turn";
|
|
51
|
+
|
|
52
|
+
default:
|
|
53
|
+
return step.relativeDirection;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function getStepInstructions(step) {
|
|
57
|
+
logDeprecationWarning("getStepInstructions");
|
|
58
|
+
var conjunction = step.relativeDirection === "ELEVATOR" ? "to" : "on";
|
|
59
|
+
return "".concat(getStepDirection(step), " ").concat(conjunction, " ").concat(step.streetName);
|
|
60
|
+
}
|
|
61
|
+
export function getStepStreetName(step) {
|
|
62
|
+
logDeprecationWarning("getStepStreetName");
|
|
63
|
+
if (step.streetName === "road") return "Unnamed Road";
|
|
64
|
+
if (step.streetName === "path") return "Unnamed Path";
|
|
65
|
+
return step.streetName;
|
|
66
|
+
}
|
|
67
|
+
export function getLegModeLabel(leg) {
|
|
68
|
+
logDeprecationWarning("getLegModeLabel");
|
|
69
|
+
|
|
70
|
+
switch (leg.mode) {
|
|
71
|
+
case "BICYCLE_RENT":
|
|
72
|
+
return "Biketown";
|
|
73
|
+
|
|
74
|
+
case "CAR":
|
|
75
|
+
return leg.hailedCar ? "Ride" : "Drive";
|
|
76
|
+
|
|
77
|
+
case "GONDOLA":
|
|
78
|
+
return "Aerial Tram";
|
|
79
|
+
|
|
80
|
+
case "TRAM":
|
|
81
|
+
if (leg.routeLongName.toLowerCase().indexOf("streetcar") !== -1) return "Streetcar";
|
|
82
|
+
return "Light Rail";
|
|
83
|
+
|
|
84
|
+
case "MICROMOBILITY":
|
|
85
|
+
return "Ride";
|
|
86
|
+
|
|
87
|
+
default:
|
|
88
|
+
return require("./itinerary").toSentenceCase(leg.mode);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns mode name by checking the vertex type (VertexType class in OTP) for
|
|
93
|
+
* the provided place. NOTE: this is currently only intended for vehicles at
|
|
94
|
+
* the moment (not transit or walking).
|
|
95
|
+
*
|
|
96
|
+
* @param {string} place place from itinerary leg
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
export function getModeForPlace(place) {
|
|
100
|
+
logDeprecationWarning("getModeForPlace");
|
|
101
|
+
|
|
102
|
+
switch (place.vertexType) {
|
|
103
|
+
case "CARSHARE":
|
|
104
|
+
return "car";
|
|
105
|
+
|
|
106
|
+
case "VEHICLERENTAL":
|
|
107
|
+
return "E-scooter";
|
|
108
|
+
// TODO: Should the type change depending on bike vertex type?
|
|
109
|
+
|
|
110
|
+
case "BIKESHARE":
|
|
111
|
+
case "BIKEPARK":
|
|
112
|
+
return "bike";
|
|
113
|
+
// If company offers more than one mode, default to `vehicle` string.
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
return "vehicle";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function getPlaceName(place, companies) {
|
|
120
|
+
logDeprecationWarning("getPlaceName"); // If address is provided (i.e. for carshare station, use it)
|
|
121
|
+
|
|
122
|
+
if (place.address) return place.address.split(",")[0];
|
|
123
|
+
|
|
124
|
+
if (place.networks && place.vertexType === "VEHICLERENTAL") {
|
|
125
|
+
// For vehicle rental pick up, do not use the place name. Rather, use
|
|
126
|
+
// company name + vehicle type (e.g., SPIN E-scooter). Place name is often just
|
|
127
|
+
// a UUID that has no relevance to the actual vehicle. For bikeshare, however,
|
|
128
|
+
// there are often hubs or bikes that have relevant names to the user.
|
|
129
|
+
var company = require("./itinerary").getCompanyForNetwork(place.networks[0], companies);
|
|
130
|
+
|
|
131
|
+
if (company) {
|
|
132
|
+
return "".concat(company.label, " ").concat(getModeForPlace(place));
|
|
133
|
+
}
|
|
134
|
+
} // Default to place name
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
return place.name;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* For a given fare component (either total fare or component parts), returns
|
|
141
|
+
* an object with string formatters and the fare value (in cents).
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
export function getTransitFare(fareComponent) {
|
|
145
|
+
logDeprecationWarning("getTransitFare", "the fare object and getTncFare"); // Default values (if fare component is not valid).
|
|
146
|
+
|
|
147
|
+
var digits = 2;
|
|
148
|
+
var transitFare = 0;
|
|
149
|
+
var symbol = "$";
|
|
150
|
+
var currencyCode = "USD";
|
|
151
|
+
|
|
152
|
+
if (fareComponent) {
|
|
153
|
+
// Assign values without declaration. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
|
|
154
|
+
var _fareComponent$curren = fareComponent.currency;
|
|
155
|
+
currencyCode = _fareComponent$curren.currencyCode;
|
|
156
|
+
digits = _fareComponent$curren.defaultFractionDigits;
|
|
157
|
+
symbol = _fareComponent$curren.symbol;
|
|
158
|
+
transitFare = fareComponent.cents;
|
|
159
|
+
} // For cents to string conversion, use digits from fare component.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
var centsToString = function centsToString(cents) {
|
|
163
|
+
var dollars = (cents / Math.pow(10, digits)).toFixed(digits);
|
|
164
|
+
return "".concat(symbol).concat(dollars);
|
|
165
|
+
}; // For dollars to string conversion, assume we're rounding to two digits.
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
var dollarsToString = function dollarsToString(dollars) {
|
|
169
|
+
return "".concat(symbol).concat(dollars.toFixed(2));
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
centsToString: centsToString,
|
|
174
|
+
currencyCode: currencyCode,
|
|
175
|
+
dollarsToString: dollarsToString,
|
|
176
|
+
transitFare: transitFare
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* For an itinerary, calculates the transit/TNC fares and returns an object with
|
|
181
|
+
* these values, currency info, as well as string formatters.
|
|
182
|
+
* It is assumed that the same currency is used for transit and TNC legs.
|
|
183
|
+
*
|
|
184
|
+
* multiple being set to true will change the output behavior:
|
|
185
|
+
* - dollarsToString and centsToString will be returned as part of each fare
|
|
186
|
+
* - currencyCode will be returned separately for each fare
|
|
187
|
+
* - tnc currency code will be returned separately
|
|
188
|
+
* - each fare type will be returned separately within a new transitFares property
|
|
189
|
+
*
|
|
190
|
+
* FIXME: a new approach to fare calculation must be found:
|
|
191
|
+
* the current approach is not sustainable, as centsToString and DollarsToString
|
|
192
|
+
* must be replaced by i18n anyway.
|
|
193
|
+
*
|
|
194
|
+
* However, the current behavior should ideally be kept to avoid a breaking change.
|
|
195
|
+
* The "multiple" mode is helpful, but only prevents tnc fare calculation from being duplicated.
|
|
196
|
+
* This method could be split out into a new one, along with tnc fare calculation.
|
|
197
|
+
* If this is done, the individual fare calculation should also be modified to support
|
|
198
|
+
* a default fare not being called "regular". However, this again would be a breaking change.
|
|
199
|
+
* This breaking change is avoided by adding the "multiple" parameter.
|
|
200
|
+
*
|
|
201
|
+
* When centsToString and dollarsToString are removed, this method should be split into
|
|
202
|
+
* individual fare calculation on a variable fare key, fare calculation of an entire leg,
|
|
203
|
+
* which will get fares for every fare key in the leg, and a method to calculate the fare of
|
|
204
|
+
* a tnc ride within the leg. This will make typescripting easier, as the types will be cleaner.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
export function calculateFares(itinerary) {
|
|
208
|
+
var multiple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
209
|
+
logDeprecationWarning("calculateFares", "the fare object and getTncFare"); // Process any TNC fares
|
|
210
|
+
|
|
211
|
+
var minTNCFare = 0;
|
|
212
|
+
var maxTNCFare = 0;
|
|
213
|
+
var tncCurrencyCode;
|
|
214
|
+
itinerary.legs.forEach(function (leg) {
|
|
215
|
+
if (leg.mode === "CAR" && leg.hailedCar && leg.tncData) {
|
|
216
|
+
var _leg$tncData = leg.tncData,
|
|
217
|
+
currency = _leg$tncData.currency,
|
|
218
|
+
maxCost = _leg$tncData.maxCost,
|
|
219
|
+
minCost = _leg$tncData.minCost; // TODO: Support non-USD
|
|
220
|
+
|
|
221
|
+
minTNCFare += minCost;
|
|
222
|
+
maxTNCFare += maxCost;
|
|
223
|
+
tncCurrencyCode = currency;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (multiple) {
|
|
228
|
+
// Return object of fares
|
|
229
|
+
var transitFares = {};
|
|
230
|
+
|
|
231
|
+
if (itinerary && itinerary.fare && itinerary.fare.fare) {
|
|
232
|
+
Object.keys(itinerary.fare.fare).forEach(function (fareKey) {
|
|
233
|
+
var fareComponent = itinerary.fare.fare[fareKey];
|
|
234
|
+
transitFares[fareKey] = getTransitFare(fareComponent);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
maxTNCFare: maxTNCFare,
|
|
240
|
+
minTNCFare: minTNCFare,
|
|
241
|
+
tncCurrencyCode: tncCurrencyCode,
|
|
242
|
+
transitFares: transitFares
|
|
243
|
+
};
|
|
244
|
+
} // Extract fare total from itinerary fares.
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
var fareComponent = itinerary.fare && itinerary.fare.fare && itinerary.fare.fare.regular; // Get string formatters and itinerary fare.
|
|
248
|
+
|
|
249
|
+
var _getTransitFare = getTransitFare(fareComponent),
|
|
250
|
+
centsToString = _getTransitFare.centsToString,
|
|
251
|
+
transitCurrencyCode = _getTransitFare.currencyCode,
|
|
252
|
+
dollarsToString = _getTransitFare.dollarsToString,
|
|
253
|
+
transitFare = _getTransitFare.transitFare;
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
centsToString: centsToString,
|
|
257
|
+
currencyCode: transitCurrencyCode || tncCurrencyCode,
|
|
258
|
+
dollarsToString: dollarsToString,
|
|
259
|
+
maxTNCFare: maxTNCFare,
|
|
260
|
+
minTNCFare: minTNCFare,
|
|
261
|
+
transitFare: transitFare
|
|
262
|
+
};
|
|
263
|
+
} // map.js
|
|
264
|
+
|
|
265
|
+
export function latlngToString(latlng) {
|
|
266
|
+
logDeprecationWarning("latlngToString", "the latlng object");
|
|
267
|
+
return latlng && "".concat(latlng.lat.toFixed(5), ", ").concat((latlng.lng || latlng.lon).toFixed(5));
|
|
268
|
+
}
|
|
269
|
+
export function coordsToString(coords) {
|
|
270
|
+
logDeprecationWarning("coordsToString", "the coords object");
|
|
271
|
+
return coords.length && coords.map(function (c) {
|
|
272
|
+
return (+c).toFixed(5);
|
|
273
|
+
}).join(", ");
|
|
274
|
+
}
|
|
275
|
+
export function getDetailText(location) {
|
|
276
|
+
var detailText;
|
|
277
|
+
|
|
278
|
+
if (location.type === "home" || location.type === "work") {
|
|
279
|
+
detailText = location.name;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (location.type === "stop") {
|
|
283
|
+
detailText = location.id;
|
|
284
|
+
} else if (location.type === "recent" && location.timestamp) {
|
|
285
|
+
detailText = moment(location.timestamp).fromNow();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return detailText;
|
|
289
|
+
} // query.js
|
|
290
|
+
|
|
291
|
+
export function summarizeQuery(query) {
|
|
292
|
+
var locations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
293
|
+
logDeprecationWarning("summarizeQuery");
|
|
294
|
+
|
|
295
|
+
function findLocationType(location) {
|
|
296
|
+
var ls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
297
|
+
var types = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ["home", "work", "suggested"];
|
|
298
|
+
var match = ls.find(function (l) {
|
|
299
|
+
return require("./map").matchLatLon(l, location);
|
|
300
|
+
});
|
|
301
|
+
return match && types.indexOf(match.type) !== -1 ? match.type : null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
var from = findLocationType(query.from, locations) || query.from.name.split(",")[0];
|
|
305
|
+
var to = findLocationType(query.to, locations) || query.to.name.split(",")[0];
|
|
306
|
+
var mode = require("./itinerary").hasTransit(query.mode) ? "Transit" : require("./itinerary").toSentenceCase(query.mode);
|
|
307
|
+
return "".concat(mode, " from ").concat(from, " to ").concat(to);
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=deprecated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deprecated.js"],"names":["moment","logDeprecationWarning","method","alternative","console","warn","getStepDirection","step","relativeDirection","absoluteDirection","toLowerCase","getStepInstructions","conjunction","streetName","getStepStreetName","getLegModeLabel","leg","mode","hailedCar","routeLongName","indexOf","require","toSentenceCase","getModeForPlace","place","vertexType","getPlaceName","companies","address","split","networks","company","getCompanyForNetwork","label","name","getTransitFare","fareComponent","digits","transitFare","symbol","currencyCode","currency","defaultFractionDigits","cents","centsToString","dollars","toFixed","dollarsToString","calculateFares","itinerary","multiple","minTNCFare","maxTNCFare","tncCurrencyCode","legs","forEach","tncData","maxCost","minCost","transitFares","fare","Object","keys","fareKey","regular","transitCurrencyCode","latlngToString","latlng","lat","lng","lon","coordsToString","coords","length","map","c","join","getDetailText","location","detailText","type","id","timestamp","fromNow","summarizeQuery","query","locations","findLocationType","ls","types","match","find","l","matchLatLon","from","to","hasTransit"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,QAAnB,C,CAEA;;AACA;;AACA,OAAO,SAASC,qBAAT,CAA+BC,MAA/B,EAAuCC,WAAvC,EAAoD;AACzDC,EAAAA,OAAO,CAACC,IAAR,WACKH,MAAM,IACP,aAFJ,oJAIQC,WAAW,6BAGPA,WAHO,qFAIP,EARZ;AAWD,C,CAED;;AAEA,OAAO,SAASG,gBAAT,CAA0BC,IAA1B,EAAgC;AACrCN,EAAAA,qBAAqB,CAAC,kBAAD,CAArB;;AAEA,UAAQM,IAAI,CAACC,iBAAb;AACE,SAAK,QAAL;AACE,4BAAeD,IAAI,CAACE,iBAAL,CAAuBC,WAAvB,EAAf;;AACF,SAAK,MAAL;AACE,aAAO,MAAP;;AACF,SAAK,WAAL;AACE,aAAO,WAAP;;AACF,SAAK,eAAL;AACE,aAAO,aAAP;;AACF,SAAK,UAAL;AACE,aAAO,UAAP;;AACF,SAAK,gBAAL;AACE,aAAO,cAAP;;AACF,SAAK,OAAL;AACE,aAAO,OAAP;;AACF,SAAK,YAAL;AACE,aAAO,YAAP;;AACF,SAAK,kBAAL;AACE,aAAO,yBAAP;;AACF,SAAK,yBAAL;AACE,aAAO,gCAAP;;AACF,SAAK,UAAL;AACE,aAAO,eAAP;;AACF,SAAK,YAAL;AACE,aAAO,aAAP;;AACF,SAAK,aAAL;AACE,aAAO,c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AUA,IAAV,mBAAuB6E,IAAvB,iBAAkCC,EAAlC;AACD","sourcesContent":["import moment from \"moment\";\n\n// Need to avoid cyclic dependency resolution\n/* eslint-disable global-require */\nexport function logDeprecationWarning(method, alternative) {\n console.warn(\n `${method ||\n \"This method\"} is deprecated and will be removed in a future otp-ui release. All language functionality should be handled using react-intl.\n ${\n alternative\n ? `\n\n Use ${alternative} instead, which provides a new interface that doesn't return English strings.`\n : \"\"\n }`\n );\n}\n\n// itinerary.js\n\nexport function getStepDirection(step) {\n logDeprecationWarning(\"getStepDirection\");\n\n switch (step.relativeDirection) {\n case \"DEPART\":\n return `Head ${step.absoluteDirection.toLowerCase()}`;\n case \"LEFT\":\n return \"Left\";\n case \"HARD_LEFT\":\n return \"Hard left\";\n case \"SLIGHTLY_LEFT\":\n return \"Slight left\";\n case \"CONTINUE\":\n return \"Continue\";\n case \"SLIGHTLY_RIGHT\":\n return \"Slight right\";\n case \"RIGHT\":\n return \"Right\";\n case \"HARD_RIGHT\":\n return \"Hard right\";\n case \"CIRCLE_CLOCKWISE\":\n return \"Follow circle clockwise\";\n case \"CIRCLE_COUNTERCLOCKWISE\":\n return \"Follow circle counterclockwise\";\n case \"ELEVATOR\":\n return \"Take elevator\";\n case \"UTURN_LEFT\":\n return \"Left U-turn\";\n case \"UTURN_RIGHT\":\n return \"Right U-turn\";\n default:\n return step.relativeDirection;\n }\n}\n\nexport function getStepInstructions(step) {\n logDeprecationWarning(\"getStepInstructions\");\n\n const conjunction = step.relativeDirection === \"ELEVATOR\" ? \"to\" : \"on\";\n return `${getStepDirection(step)} ${conjunction} ${step.streetName}`;\n}\n\nexport function getStepStreetName(step) {\n logDeprecationWarning(\"getStepStreetName\");\n\n if (step.streetName === \"road\") return \"Unnamed Road\";\n if (step.streetName === \"path\") return \"Unnamed Path\";\n return step.streetName;\n}\n\nexport function getLegModeLabel(leg) {\n logDeprecationWarning(\"getLegModeLabel\");\n\n switch (leg.mode) {\n case \"BICYCLE_RENT\":\n return \"Biketown\";\n case \"CAR\":\n return leg.hailedCar ? \"Ride\" : \"Drive\";\n case \"GONDOLA\":\n return \"Aerial Tram\";\n case \"TRAM\":\n if (leg.routeLongName.toLowerCase().indexOf(\"streetcar\") !== -1)\n return \"Streetcar\";\n return \"Light Rail\";\n case \"MICROMOBILITY\":\n return \"Ride\";\n default:\n return require(\"./itinerary\").toSentenceCase(leg.mode);\n }\n}\n\n/**\n * Returns mode name by checking the vertex type (VertexType class in OTP) for\n * the provided place. NOTE: this is currently only intended for vehicles at\n * the moment (not transit or walking).\n *\n * @param {string} place place from itinerary leg\n */\nexport function getModeForPlace(place) {\n logDeprecationWarning(\"getModeForPlace\");\n\n switch (place.vertexType) {\n case \"CARSHARE\":\n return \"car\";\n case \"VEHICLERENTAL\":\n return \"E-scooter\";\n // TODO: Should the type change depending on bike vertex type?\n case \"BIKESHARE\":\n case \"BIKEPARK\":\n return \"bike\";\n // If company offers more than one mode, default to `vehicle` string.\n default:\n return \"vehicle\";\n }\n}\n\nexport function getPlaceName(place, companies) {\n logDeprecationWarning(\"getPlaceName\");\n\n // If address is provided (i.e. for carshare station, use it)\n if (place.address) return place.address.split(\",\")[0];\n if (place.networks && place.vertexType === \"VEHICLERENTAL\") {\n // For vehicle rental pick up, do not use the place name. Rather, use\n // company name + vehicle type (e.g., SPIN E-scooter). Place name is often just\n // a UUID that has no relevance to the actual vehicle. For bikeshare, however,\n // there are often hubs or bikes that have relevant names to the user.\n const company = require(\"./itinerary\").getCompanyForNetwork(\n place.networks[0],\n companies\n );\n if (company) {\n return `${company.label} ${getModeForPlace(place)}`;\n }\n }\n // Default to place name\n return place.name;\n}\n\n/**\n * For a given fare component (either total fare or component parts), returns\n * an object with string formatters and the fare value (in cents).\n */\nexport function getTransitFare(fareComponent) {\n logDeprecationWarning(\"getTransitFare\", \"the fare object and getTncFare\");\n\n // Default values (if fare component is not valid).\n let digits = 2;\n let transitFare = 0;\n let symbol = \"$\";\n let currencyCode = \"USD\";\n if (fareComponent) {\n // Assign values without declaration. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration\n ({\n currencyCode,\n defaultFractionDigits: digits,\n symbol\n } = fareComponent.currency);\n transitFare = fareComponent.cents;\n }\n // For cents to string conversion, use digits from fare component.\n const centsToString = cents => {\n const dollars = (cents / 10 ** digits).toFixed(digits);\n return `${symbol}${dollars}`;\n };\n // For dollars to string conversion, assume we're rounding to two digits.\n const dollarsToString = dollars => `${symbol}${dollars.toFixed(2)}`;\n return {\n centsToString,\n currencyCode,\n dollarsToString,\n transitFare\n };\n}\n\n/**\n * For an itinerary, calculates the transit/TNC fares and returns an object with\n * these values, currency info, as well as string formatters.\n * It is assumed that the same currency is used for transit and TNC legs.\n *\n * multiple being set to true will change the output behavior:\n * - dollarsToString and centsToString will be returned as part of each fare\n * - currencyCode will be returned separately for each fare\n * - tnc currency code will be returned separately\n * - each fare type will be returned separately within a new transitFares property\n *\n * FIXME: a new approach to fare calculation must be found:\n * the current approach is not sustainable, as centsToString and DollarsToString\n * must be replaced by i18n anyway.\n *\n * However, the current behavior should ideally be kept to avoid a breaking change.\n * The \"multiple\" mode is helpful, but only prevents tnc fare calculation from being duplicated.\n * This method could be split out into a new one, along with tnc fare calculation.\n * If this is done, the individual fare calculation should also be modified to support\n * a default fare not being called \"regular\". However, this again would be a breaking change.\n * This breaking change is avoided by adding the \"multiple\" parameter.\n *\n * When centsToString and dollarsToString are removed, this method should be split into\n * individual fare calculation on a variable fare key, fare calculation of an entire leg,\n * which will get fares for every fare key in the leg, and a method to calculate the fare of\n * a tnc ride within the leg. This will make typescripting easier, as the types will be cleaner.\n */\nexport function calculateFares(itinerary, multiple = false) {\n logDeprecationWarning(\"calculateFares\", \"the fare object and getTncFare\");\n\n // Process any TNC fares\n let minTNCFare = 0;\n let maxTNCFare = 0;\n let tncCurrencyCode;\n itinerary.legs.forEach(leg => {\n if (leg.mode === \"CAR\" && leg.hailedCar && leg.tncData) {\n const { currency, maxCost, minCost } = leg.tncData;\n // TODO: Support non-USD\n minTNCFare += minCost;\n maxTNCFare += maxCost;\n tncCurrencyCode = currency;\n }\n });\n\n if (multiple) {\n // Return object of fares\n const transitFares = {};\n if (itinerary && itinerary.fare && itinerary.fare.fare) {\n Object.keys(itinerary.fare.fare).forEach(fareKey => {\n const fareComponent = itinerary.fare.fare[fareKey];\n transitFares[fareKey] = getTransitFare(fareComponent);\n });\n }\n\n return {\n maxTNCFare,\n minTNCFare,\n tncCurrencyCode,\n transitFares\n };\n }\n\n // Extract fare total from itinerary fares.\n const fareComponent =\n itinerary.fare && itinerary.fare.fare && itinerary.fare.fare.regular;\n // Get string formatters and itinerary fare.\n const {\n centsToString,\n currencyCode: transitCurrencyCode,\n dollarsToString,\n transitFare\n } = getTransitFare(fareComponent);\n\n return {\n centsToString,\n currencyCode: transitCurrencyCode || tncCurrencyCode,\n dollarsToString,\n maxTNCFare,\n minTNCFare,\n transitFare\n };\n}\n\n// map.js\n\nexport function latlngToString(latlng) {\n logDeprecationWarning(\"latlngToString\", \"the latlng object\");\n\n return (\n latlng &&\n `${latlng.lat.toFixed(5)}, ${(latlng.lng || latlng.lon).toFixed(5)}`\n );\n}\n\nexport function coordsToString(coords) {\n logDeprecationWarning(\"coordsToString\", \"the coords object\");\n\n return coords.length && coords.map(c => (+c).toFixed(5)).join(\", \");\n}\n\nexport function getDetailText(location) {\n let detailText;\n if (location.type === \"home\" || location.type === \"work\") {\n detailText = location.name;\n }\n if (location.type === \"stop\") {\n detailText = location.id;\n } else if (location.type === \"recent\" && location.timestamp) {\n detailText = moment(location.timestamp).fromNow();\n }\n return detailText;\n}\n\n// query.js\n\nexport function summarizeQuery(query, locations = []) {\n logDeprecationWarning(\"summarizeQuery\");\n\n function findLocationType(\n location,\n ls = [],\n types = [\"home\", \"work\", \"suggested\"]\n ) {\n const match = ls.find(l => require(\"./map\").matchLatLon(l, location));\n return match && types.indexOf(match.type) !== -1 ? match.type : null;\n }\n\n const from =\n findLocationType(query.from, locations) || query.from.name.split(\",\")[0];\n const to =\n findLocationType(query.to, locations) || query.to.name.split(\",\")[0];\n const mode = require(\"./itinerary\").hasTransit(query.mode)\n ? \"Transit\"\n : require(\"./itinerary\").toSentenceCase(query.mode);\n return `${mode} from ${from} to ${to}`;\n}\n"],"file":"deprecated.js"}
|
package/esm/itinerary.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import polyline from "@mapbox/polyline";
|
|
3
|
-
import turfAlong from "@turf/along";
|
|
3
|
+
import turfAlong from "@turf/along";
|
|
4
|
+
import { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTransitFare } from "./deprecated";
|
|
5
|
+
export { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTransitFare }; // All OTP transit modes
|
|
4
6
|
|
|
5
7
|
export var transitModes = ["TRAM", "BUS", "SUBWAY", "FERRY", "RAIL", "GONDOLA"];
|
|
6
8
|
/**
|
|
@@ -146,61 +148,6 @@ export function getMapColor(mode) {
|
|
|
146
148
|
if (mode === "CAR") return "#444";
|
|
147
149
|
if (mode === "MICROMOBILITY") return "#f5a729";
|
|
148
150
|
return "#aaa";
|
|
149
|
-
} // TODO: temporary code; handle via migrated OTP i18n language table
|
|
150
|
-
|
|
151
|
-
export function getStepDirection(step) {
|
|
152
|
-
switch (step.relativeDirection) {
|
|
153
|
-
case "DEPART":
|
|
154
|
-
return "Head ".concat(step.absoluteDirection.toLowerCase());
|
|
155
|
-
|
|
156
|
-
case "LEFT":
|
|
157
|
-
return "Left";
|
|
158
|
-
|
|
159
|
-
case "HARD_LEFT":
|
|
160
|
-
return "Hard left";
|
|
161
|
-
|
|
162
|
-
case "SLIGHTLY_LEFT":
|
|
163
|
-
return "Slight left";
|
|
164
|
-
|
|
165
|
-
case "CONTINUE":
|
|
166
|
-
return "Continue";
|
|
167
|
-
|
|
168
|
-
case "SLIGHTLY_RIGHT":
|
|
169
|
-
return "Slight right";
|
|
170
|
-
|
|
171
|
-
case "RIGHT":
|
|
172
|
-
return "Right";
|
|
173
|
-
|
|
174
|
-
case "HARD_RIGHT":
|
|
175
|
-
return "Hard right";
|
|
176
|
-
|
|
177
|
-
case "CIRCLE_CLOCKWISE":
|
|
178
|
-
return "Follow circle clockwise";
|
|
179
|
-
|
|
180
|
-
case "CIRCLE_COUNTERCLOCKWISE":
|
|
181
|
-
return "Follow circle counterclockwise";
|
|
182
|
-
|
|
183
|
-
case "ELEVATOR":
|
|
184
|
-
return "Take elevator";
|
|
185
|
-
|
|
186
|
-
case "UTURN_LEFT":
|
|
187
|
-
return "Left U-turn";
|
|
188
|
-
|
|
189
|
-
case "UTURN_RIGHT":
|
|
190
|
-
return "Right U-turn";
|
|
191
|
-
|
|
192
|
-
default:
|
|
193
|
-
return step.relativeDirection;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
export function getStepInstructions(step) {
|
|
197
|
-
var conjunction = step.relativeDirection === "ELEVATOR" ? "to" : "on";
|
|
198
|
-
return "".concat(getStepDirection(step), " ").concat(conjunction, " ").concat(step.streetName);
|
|
199
|
-
}
|
|
200
|
-
export function getStepStreetName(step) {
|
|
201
|
-
if (step.streetName === "road") return "Unnamed Road";
|
|
202
|
-
if (step.streetName === "path") return "Unnamed Path";
|
|
203
|
-
return step.streetName;
|
|
204
151
|
}
|
|
205
152
|
export function toSentenceCase(str) {
|
|
206
153
|
if (str == null) {
|
|
@@ -241,28 +188,6 @@ export function getCompanyFromLeg(leg) {
|
|
|
241
188
|
|
|
242
189
|
return null;
|
|
243
190
|
}
|
|
244
|
-
export function getLegModeLabel(leg) {
|
|
245
|
-
switch (leg.mode) {
|
|
246
|
-
case "BICYCLE_RENT":
|
|
247
|
-
return "Biketown";
|
|
248
|
-
|
|
249
|
-
case "CAR":
|
|
250
|
-
return leg.hailedCar ? "Ride" : "Drive";
|
|
251
|
-
|
|
252
|
-
case "GONDOLA":
|
|
253
|
-
return "Aerial Tram";
|
|
254
|
-
|
|
255
|
-
case "TRAM":
|
|
256
|
-
if (leg.routeLongName.toLowerCase().indexOf("streetcar") !== -1) return "Streetcar";
|
|
257
|
-
return "Light Rail";
|
|
258
|
-
|
|
259
|
-
case "MICROMOBILITY":
|
|
260
|
-
return "Ride";
|
|
261
|
-
|
|
262
|
-
default:
|
|
263
|
-
return toSentenceCase(leg.mode);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
191
|
export function getItineraryBounds(itinerary) {
|
|
267
192
|
var coords = [];
|
|
268
193
|
itinerary.legs.forEach(function (leg) {
|
|
@@ -417,7 +342,7 @@ export function getTextWidth(text) {
|
|
|
417
342
|
* has been defined in the provided companies array config.
|
|
418
343
|
*/
|
|
419
344
|
|
|
420
|
-
function getCompanyForNetwork(networkString) {
|
|
345
|
+
export function getCompanyForNetwork(networkString) {
|
|
421
346
|
var companies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
422
347
|
var company = companies.find(function (co) {
|
|
423
348
|
return co.id === networkString;
|
|
@@ -437,7 +362,6 @@ function getCompanyForNetwork(networkString) {
|
|
|
437
362
|
* @return {string} A label for use in presentation on a website.
|
|
438
363
|
*/
|
|
439
364
|
|
|
440
|
-
|
|
441
365
|
export function getCompaniesLabelFromNetworks(networks) {
|
|
442
366
|
var companies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
443
367
|
return networks.map(function (network) {
|
|
@@ -448,52 +372,6 @@ export function getCompaniesLabelFromNetworks(networks) {
|
|
|
448
372
|
return co.label;
|
|
449
373
|
}).join("/");
|
|
450
374
|
}
|
|
451
|
-
/**
|
|
452
|
-
* Returns mode name by checking the vertex type (VertexType class in OTP) for
|
|
453
|
-
* the provided place. NOTE: this is currently only intended for vehicles at
|
|
454
|
-
* the moment (not transit or walking).
|
|
455
|
-
*
|
|
456
|
-
* TODO: I18N
|
|
457
|
-
* @param {string} place place from itinerary leg
|
|
458
|
-
*/
|
|
459
|
-
|
|
460
|
-
export function getModeForPlace(place) {
|
|
461
|
-
switch (place.vertexType) {
|
|
462
|
-
case "CARSHARE":
|
|
463
|
-
return "car";
|
|
464
|
-
|
|
465
|
-
case "VEHICLERENTAL":
|
|
466
|
-
return "E-scooter";
|
|
467
|
-
// TODO: Should the type change depending on bike vertex type?
|
|
468
|
-
|
|
469
|
-
case "BIKESHARE":
|
|
470
|
-
case "BIKEPARK":
|
|
471
|
-
return "bike";
|
|
472
|
-
// If company offers more than one mode, default to `vehicle` string.
|
|
473
|
-
|
|
474
|
-
default:
|
|
475
|
-
return "vehicle";
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
export function getPlaceName(place, companies) {
|
|
479
|
-
// If address is provided (i.e. for carshare station, use it)
|
|
480
|
-
if (place.address) return place.address.split(",")[0];
|
|
481
|
-
|
|
482
|
-
if (place.networks && place.vertexType === "VEHICLERENTAL") {
|
|
483
|
-
// For vehicle rental pick up, do not use the place name. Rather, use
|
|
484
|
-
// company name + vehicle type (e.g., SPIN E-scooter). Place name is often just
|
|
485
|
-
// a UUID that has no relevance to the actual vehicle. For bikeshare, however,
|
|
486
|
-
// there are often hubs or bikes that have relevant names to the user.
|
|
487
|
-
var company = getCompanyForNetwork(place.networks[0], companies);
|
|
488
|
-
|
|
489
|
-
if (company) {
|
|
490
|
-
return "".concat(company.label, " ").concat(getModeForPlace(place));
|
|
491
|
-
}
|
|
492
|
-
} // Default to place name
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
return place.name;
|
|
496
|
-
}
|
|
497
375
|
export function getTNCLocation(leg, type) {
|
|
498
376
|
var location = leg[type];
|
|
499
377
|
return "".concat(location.lat.toFixed(5), ",").concat(location.lon.toFixed(5));
|
|
@@ -512,133 +390,24 @@ export function calculatePhysicalActivity(itinerary) {
|
|
|
512
390
|
walkDuration: walkDuration
|
|
513
391
|
};
|
|
514
392
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
* an object with string formatters and the fare value (in cents).
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
export function getTransitFare(fareComponent) {
|
|
521
|
-
// Default values (if fare component is not valid).
|
|
522
|
-
var digits = 2;
|
|
523
|
-
var transitFare = 0;
|
|
524
|
-
var symbol = "$";
|
|
525
|
-
var currencyCode = "USD";
|
|
526
|
-
|
|
527
|
-
if (fareComponent) {
|
|
528
|
-
// Assign values without declaration. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_without_declaration
|
|
529
|
-
var _fareComponent$curren = fareComponent.currency;
|
|
530
|
-
currencyCode = _fareComponent$curren.currencyCode;
|
|
531
|
-
digits = _fareComponent$curren.defaultFractionDigits;
|
|
532
|
-
symbol = _fareComponent$curren.symbol;
|
|
533
|
-
transitFare = fareComponent.cents;
|
|
534
|
-
} // For cents to string conversion, use digits from fare component.
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
var centsToString = function centsToString(cents) {
|
|
538
|
-
var dollars = (cents / Math.pow(10, digits)).toFixed(digits);
|
|
539
|
-
return "".concat(symbol).concat(dollars);
|
|
540
|
-
}; // For dollars to string conversion, assume we're rounding to two digits.
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
var dollarsToString = function dollarsToString(dollars) {
|
|
544
|
-
return "".concat(symbol).concat(dollars.toFixed(2));
|
|
545
|
-
};
|
|
393
|
+
export function getTimeZoneOffset(itinerary) {
|
|
394
|
+
if (!itinerary.legs || !itinerary.legs.length) return 0; // Determine if there is a DST offset between now and the itinerary start date
|
|
546
395
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
currencyCode: currencyCode,
|
|
550
|
-
dollarsToString: dollarsToString,
|
|
551
|
-
transitFare: transitFare
|
|
552
|
-
};
|
|
396
|
+
var dstOffset = new Date(itinerary.startTime).getTimezoneOffset() - new Date().getTimezoneOffset();
|
|
397
|
+
return itinerary.legs[0].agencyTimeZoneOffset + (new Date().getTimezoneOffset() + dstOffset) * 60000;
|
|
553
398
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
* - currencyCode will be returned separately for each fare
|
|
562
|
-
* - tnc currency code will be returned separately
|
|
563
|
-
* - each fare type will be returned separately within a new transitFares property
|
|
564
|
-
*
|
|
565
|
-
* FIXME: a new approach to fare calculation must be found:
|
|
566
|
-
* the current approach is not sustainable, as centsToString and DollarsToString
|
|
567
|
-
* must be replaced by i18n anyway.
|
|
568
|
-
*
|
|
569
|
-
* However, the current behavior should ideally be kept to avoid a breaking change.
|
|
570
|
-
* The "multiple" mode is helpful, but only prevents tnc fare calculation from being duplicated.
|
|
571
|
-
* This method could be split out into a new one, along with tnc fare calculation.
|
|
572
|
-
* If this is done, the individual fare calculation should also be modified to support
|
|
573
|
-
* a default fare not being called "regular". However, this again would be a breaking change.
|
|
574
|
-
* This breaking change is avoided by adding the "multiple" parameter.
|
|
575
|
-
*
|
|
576
|
-
* When centsToString and dollarsToString are removed, this method should be split into
|
|
577
|
-
* individual fare calculation on a variable fare key, fare calculation of an entire leg,
|
|
578
|
-
* which will get fares for every fare key in the leg, and a method to calculate the fare of
|
|
579
|
-
* a tnc ride within the leg. This will make typescripting easier, as the types will be cleaner.
|
|
580
|
-
*/
|
|
581
|
-
|
|
582
|
-
export function calculateFares(itinerary) {
|
|
583
|
-
var multiple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
584
|
-
// Process any TNC fares
|
|
585
|
-
var minTNCFare = 0;
|
|
586
|
-
var maxTNCFare = 0;
|
|
587
|
-
var tncCurrencyCode;
|
|
588
|
-
itinerary.legs.forEach(function (leg) {
|
|
589
|
-
if (leg.mode === "CAR" && leg.hailedCar && leg.tncData) {
|
|
590
|
-
var _leg$tncData = leg.tncData,
|
|
591
|
-
currency = _leg$tncData.currency,
|
|
592
|
-
maxCost = _leg$tncData.maxCost,
|
|
593
|
-
minCost = _leg$tncData.minCost; // TODO: Support non-USD
|
|
594
|
-
|
|
595
|
-
minTNCFare += minCost;
|
|
596
|
-
maxTNCFare += maxCost;
|
|
597
|
-
tncCurrencyCode = currency;
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
if (multiple) {
|
|
602
|
-
// Return object of fares
|
|
603
|
-
var transitFares = {};
|
|
604
|
-
|
|
605
|
-
if (itinerary && itinerary.fare && itinerary.fare.fare) {
|
|
606
|
-
Object.keys(itinerary.fare.fare).forEach(function (fareKey) {
|
|
607
|
-
var fareComponent = itinerary.fare.fare[fareKey];
|
|
608
|
-
transitFares[fareKey] = getTransitFare(fareComponent);
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
return {
|
|
613
|
-
maxTNCFare: maxTNCFare,
|
|
614
|
-
minTNCFare: minTNCFare,
|
|
615
|
-
tncCurrencyCode: tncCurrencyCode,
|
|
616
|
-
transitFares: transitFares
|
|
617
|
-
};
|
|
618
|
-
} // Extract fare total from itinerary fares.
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
var fareComponent = itinerary.fare && itinerary.fare.fare && itinerary.fare.fare.regular; // Get string formatters and itinerary fare.
|
|
622
|
-
|
|
623
|
-
var _getTransitFare = getTransitFare(fareComponent),
|
|
624
|
-
centsToString = _getTransitFare.centsToString,
|
|
625
|
-
transitCurrencyCode = _getTransitFare.currencyCode,
|
|
626
|
-
dollarsToString = _getTransitFare.dollarsToString,
|
|
627
|
-
transitFare = _getTransitFare.transitFare;
|
|
399
|
+
export function calculateTncFares(itinerary) {
|
|
400
|
+
// TODO: don't rely on deprecated methods!
|
|
401
|
+
// At the moment this is safe as none of these exported variables contain strings
|
|
402
|
+
var _calculateFares = calculateFares(itinerary, true),
|
|
403
|
+
maxTNCFare = _calculateFares.maxTNCFare,
|
|
404
|
+
minTNCFare = _calculateFares.minTNCFare,
|
|
405
|
+
tncCurrencyCode = _calculateFares.tncCurrencyCode;
|
|
628
406
|
|
|
629
407
|
return {
|
|
630
|
-
centsToString: centsToString,
|
|
631
|
-
currencyCode: transitCurrencyCode || tncCurrencyCode,
|
|
632
|
-
dollarsToString: dollarsToString,
|
|
633
408
|
maxTNCFare: maxTNCFare,
|
|
634
409
|
minTNCFare: minTNCFare,
|
|
635
|
-
|
|
410
|
+
tncCurrencyCode: tncCurrencyCode
|
|
636
411
|
};
|
|
637
412
|
}
|
|
638
|
-
export function getTimeZoneOffset(itinerary) {
|
|
639
|
-
if (!itinerary.legs || !itinerary.legs.length) return 0; // Determine if there is a DST offset between now and the itinerary start date
|
|
640
|
-
|
|
641
|
-
var dstOffset = new Date(itinerary.startTime).getTimezoneOffset() - new Date().getTimezoneOffset();
|
|
642
|
-
return itinerary.legs[0].agencyTimeZoneOffset + (new Date().getTimezoneOffset() + dstOffset) * 60000;
|
|
643
|
-
}
|
|
644
413
|
//# sourceMappingURL=itinerary.js.map
|