@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/lib/query.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/query.js"],"names":["defaultParams","TIME_FORMATS","OTP_API_TIME_FORMAT","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","qs","parse","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","findLocationType","locations","types","match","l","indexOf","type","summarizeQuery","from","name","to","mode","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","reduce","prev","cur","newModes","expandOtpFlexMode","map","join","isNotDefaultQuery","activeModes","sort","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","parsedTime","isValid","format","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAOA;;AACA;;AACA;;AAOA;AAEO,MAAMA,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,aAH2B,EAI3B,WAJ2B,EAK3B,iBAL2B,EAM3B,aAN2B,EAO3B,WAP2B,EAQ3B,UAR2B,EAS3B,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e,OAAf;AACD,GApF2E,CAsF5E;;;AACA,MAAI0D,MAAM,CAAC1D,IAAX,EAAiB;AACf;AACA,UAAMwF,WAAW,GAAGlE,kBAAkB,CAACoC,MAAM,CAAC1D,IAAP,CAAYjB,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2C+C,IAA3C,CAAgD,GAAhD,CAApB;AACA4B,IAAAA,MAAM,CAAC1D,IAAP,GAAc4B,iBAAiB,CAAC4D,WAAD,CAA/B;AACD;;AAED,SAAO9B,MAAP;AACD","sourcesContent":["import moment from \"moment\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport {\n getTransitModes,\n hasCar,\n hasTransit,\n isAccessMode,\n toSentenceCase\n} from \"./itinerary\";\nimport { coordsToString, matchLatLon, stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nfunction findLocationType(\n location,\n locations = [],\n types = [\"home\", \"work\", \"suggested\"]\n) {\n const match = locations.find(l => matchLatLon(l, location));\n return match && types.indexOf(match.type) !== -1 ? match.type : null;\n}\n\nexport function summarizeQuery(query, locations = []) {\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 = hasTransit(query.mode) ? \"Transit\" : toSentenceCase(query.mode);\n return `${mode} from ${from} to ${to}`;\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes) {\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(query.mode.split(\",\").sort());\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n const parsedTime = moment(params.time, TIME_FORMATS);\n query.time = parsedTime.isValid()\n ? parsedTime.format(OTP_API_TIME_FORMAT)\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = moment(params.date, OTP_API_DATE_FORMAT).isValid();\n const timeValid = moment(params.time, OTP_API_TIME_FORMAT).isValid();\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = moment(\n params.startTime,\n OTP_API_TIME_FORMAT\n ).isValid();\n const endTimeValid = moment(params.endTime, OTP_API_TIME_FORMAT).isValid();\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n if (params.mode) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
1
+ {"version":3,"sources":["../src/query.js"],"names":["defaultParams","TIME_FORMATS","OTP_API_TIME_FORMAT","getQueryParamProperty","paramInfo","property","query","ensureSingleAccessMode","queryModes","accessCount","filter","m","length","firstAccess","find","push","getUrlParams","qs","parse","window","location","href","split","getOtpUrlParams","Object","keys","key","startsWith","getTripOptionsFromQuery","keepPlace","options","time","departArrive","date","from","to","getDefaultQueryParamValue","param","default","getDefaultQuery","config","defaultQuery","routingType","queryParams","qp","forEach","name","routingTypes","defaultQueryParams","isParamApplicable","applicable","includes","reduceOtpFlexModes","modes","reduce","prev","cur","newModes","expandOtpFlexMode","mode","map","join","isNotDefaultQuery","activeModes","sort","defaultModes","concat","modesEqual","every","value","index","i","getFirstGeocodeResult","text","geocoderConfig","geocoder","search","then","result","firstResult","features","getLocationFromGeocodedFeature","parseLocationString","parts","coordinates","lat","lon","queryParamToLocation","planParamsToQuery","params","fromPlace","toPlace","arriveBy","parsedTime","isValid","format","intermediatePlaces","maybeNumber","Number","isNaN","planParamsToQueryAsync","getRoutingParams","currentQuery","ignoreRealtimeUpdates","isItinerary","indexOf","rewriteFunction","itineraryRewrite","profileRewrite","assign","dateValid","OTP_API_DATE_FORMAT","timeValid","minTransitDistance","searchTimeout","onlyTransitTrips","startTimeValid","startTime","endTimeValid","endTime","reducedMode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAOA;;AAIA;AAEO,MAAMA,aAAa,GAAG,CAC3B,YAD2B,EAE3B,iBAF2B,EAG3B,aAH2B,EAI3B,WAJ2B,EAK3B,iBAL2B,EAM3B,aAN2B,EAO3B,WAP2B,EAQ3B,UAR2B,EAS3B,cAT2B,EAU3B,qBAV2B,EAW3B,OAX2B,CAAtB;AAcP;AACA;AACA;;;AACA,MAAMC,YAAY,GAAG,CACnB,UADmB,EAEnB,WAFmB,EAGnB,UAHmB,EAInB,QAJmB,EAKnB,OALmB,EAMnB,MANmB,EAOnB,MAPmB,EAQnB,KARmB,EASnB,IATmB,EAUnBC,yBAVmB,CAUC;AAVD,CAArB;AAaA;AACA;;AAEO,SAASC,qBAAT,CAA+BC,SAA/B,EAA0CC,QAA1C,EAAoDC,KAApD,EAA2D;AAChE,SAAO,OAAOF,SAAS,CAACC,QAAD,CAAhB,KAA+B,UAA/B,GACHD,SAAS,CAACC,QAAD,CAAT,CAAoBC,KAApB,CADG,GAEHF,SAAS,CAACC,QAAD,CAFb;AAGD;;AAEM,SAASE,sBAAT,CAAgCC,UAAhC,EAA4C;AACjD;AACA,QAAMC,WAAW,GAAGD,UAAU,CAACE,MAAX,CAAkBC,CAAC,IAAI,6BAAaA,CAAb,CAAvB,EAAwCC,MAA5D,CAFiD,CAIjD;;AACA,MAAIH,WAAW,GAAG,CAAlB,EAAqB;AACnB,UAAMI,WAAW,GAAGL,UAAU,CAAC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B,CADrC,CADF,EAGE;AACAsC,MAAAA,MAAM,CAACwB,kBAAP,GAA4B,KAA5B,CADA,CAEA;;AACAxB,MAAAA,MAAM,CAACyB,aAAP,GAAuB,KAAvB;AACD,KAvBc,CAyBf;;;AACA,QAAIzB,MAAM,CAAC9B,IAAP,IAAe8B,MAAM,CAAC9B,IAAP,CAAYR,QAAZ,CAAqB,UAArB,CAAnB,EAAqD;AACnDsC,MAAAA,MAAM,CAAC0B,gBAAP,GAA0B,IAA1B;AACD,KA5Bc,CA8Bf;;AACD,GA/BD,MA+BO;AACL;AACA,UAAMC,cAAc,GAAG,qBACrB3B,MAAM,CAAC4B,SADc,EAErBnH,yBAFqB,EAGrB4F,OAHqB,EAAvB;AAIA,UAAMwB,YAAY,GAAG,qBAAO7B,MAAM,CAAC8B,OAAd,EAAuBrH,yBAAvB,EAA4C4F,OAA5C,EAArB;;AAEA,QAAI,CAACsB,cAAD,IAAmB,CAACE,YAAxB,EAAsC;AACpC,aAAO7B,MAAM,CAAC2B,cAAd;AACA,aAAO3B,MAAM,CAAC6B,YAAd;AACD;AACF,GA7E2E,CA+E5E;AAEA;;;AACA,MAAI,uBAAO7B,MAAM,CAAC9B,IAAd,CAAJ,EAAyB;AACvB8B,IAAAA,MAAM,CAAC9B,IAAP,IAAe,OAAf;AACD,GApF2E,CAsF5E;;;AACA,MAAI8B,MAAM,CAAC9B,IAAX,EAAiB;AACf;AACA,UAAM6D,WAAW,GAAGpE,kBAAkB,CAACqC,MAAM,CAAC9B,IAAP,CAAYrC,KAAZ,CAAkB,GAAlB,CAAD,CAAlB,CAA2CuC,IAA3C,CAAgD,GAAhD,CAApB;AACA4B,IAAAA,MAAM,CAAC9B,IAAP,GAAcD,iBAAiB,CAAC8D,WAAD,CAA/B;AACD;;AAED,SAAO/B,MAAP;AACD","sourcesContent":["import moment from \"moment\";\nimport getGeocoder from \"@opentripplanner/geocoder/lib\";\nimport qs from \"qs\";\n\nimport { getTransitModes, hasCar, isAccessMode } from \"./itinerary\";\nimport { stringToCoords } from \"./map\";\nimport queryParams from \"./query-params\";\nimport {\n getCurrentTime,\n getCurrentDate,\n OTP_API_DATE_FORMAT,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\nimport { coordsToString, summarizeQuery } from \"./deprecated\";\n\nexport { summarizeQuery };\n\n/* The list of default parameters considered in the settings panel */\n\nexport const defaultParams = [\n \"wheelchair\",\n \"maxWalkDistance\",\n \"maxWalkTime\",\n \"walkSpeed\",\n \"maxBikeDistance\",\n \"maxBikeTime\",\n \"bikeSpeed\",\n \"optimize\",\n \"optimizeBike\",\n \"maxEScooterDistance\",\n \"watts\"\n];\n\n/**\n * List of time formats to parse when reading query params.\n */\nconst TIME_FORMATS = [\n \"HH:mm:ss\",\n \"h:mm:ss a\",\n \"h:mm:ssa\",\n \"h:mm a\",\n \"h:mma\",\n \"h:mm\",\n \"HHmm\",\n \"hmm\",\n \"ha\",\n OTP_API_TIME_FORMAT // 'HH:mm'\n];\n\n/* A function to retrieve a property value from an entry in the query-params\n * table, checking for either a static value or a function */\n\nexport function getQueryParamProperty(paramInfo, property, query) {\n return typeof paramInfo[property] === \"function\"\n ? paramInfo[property](query)\n : paramInfo[property];\n}\n\nexport function ensureSingleAccessMode(queryModes) {\n // Count the number of access modes\n const accessCount = queryModes.filter(m => isAccessMode(m)).length;\n\n // If multiple access modes are specified, keep only the first one\n if (accessCount > 1) {\n const firstAccess = queryModes.find(m => isAccessMode(m));\n queryModes = queryModes.filter(m => !isAccessMode(m) || m === firstAccess);\n\n // If no access modes are specified, add 'WALK' as the default\n } else if (accessCount === 0) {\n queryModes.push(\"WALK\");\n }\n\n return queryModes;\n}\n\nexport function getUrlParams() {\n return qs.parse(window.location.href.split(\"?\")[1]);\n}\n\nexport function getOtpUrlParams() {\n return Object.keys(getUrlParams()).filter(key => !key.startsWith(\"ui_\"));\n}\n\nexport function getTripOptionsFromQuery(query, keepPlace = false) {\n const options = { ...query };\n // Delete time/date options and from/to\n delete options.time;\n delete options.departArrive;\n delete options.date;\n if (!keepPlace) {\n delete options.from;\n delete options.to;\n }\n return options;\n}\n\n/**\n * Gets the query param's default value that is either a constant or by\n * executing the default value function.\n */\nfunction getDefaultQueryParamValue(param) {\n return typeof param.default === \"function\" ? param.default() : param.default;\n}\n\n/**\n * Get the default query to OTP based on the given config.\n */\nexport function getDefaultQuery(config = null) {\n const defaultQuery = { routingType: \"ITINERARY\" };\n queryParams\n .filter(qp => \"default\" in qp)\n .forEach(qp => {\n defaultQuery[qp.name] = getDefaultQueryParamValue(qp);\n });\n if (config) {\n if (config.routingTypes && config.routingTypes.length > 0) {\n defaultQuery.routingType = config.routingTypes[0].key;\n }\n if (config.defaultQueryParams) {\n Object.keys(config.defaultQueryParams).forEach(key => {\n defaultQuery[key] = config.defaultQueryParams[key];\n });\n }\n }\n return defaultQuery;\n}\n\n/**\n * Determine if the specified query param applies to the given query (based on\n * routing type and the param's own applicable function).\n * @param paramInfo an entry from query-params.js\n * @param query the query against which to check if the param applies\n * @param config OTP config\n * @return {Boolean}\n */\nfunction isParamApplicable(paramInfo, query, config) {\n const { applicable, routingTypes } = paramInfo;\n if (!routingTypes.includes(query.routingType)) return false;\n if (typeof applicable === \"function\" && !applicable(query, config)) {\n return false;\n }\n return true;\n}\n\n/**\n * Helper method which replaces OTP flex modes with single FLEX mode that's\n * more useful and easier to work with.\n */\nexport function reduceOtpFlexModes(modes) {\n return modes.reduce((prev, cur) => {\n const newModes = prev;\n // Add the current mode if it is not a flex mode\n if (!cur.includes(\"FLEX\")) {\n newModes.push(cur);\n // If it is a flex mode, do not add it but rather add the custom flex mode\n // if not already present\n } else if (!newModes.includes(\"FLEX\")) {\n newModes.push(\"FLEX\");\n }\n return newModes;\n }, []);\n}\n\n/**\n * Helper method to process a mode string, replacing all instances of FLEX\n * with the full set of FLEX modes used by otp-2\n * @param {*} mode a mode String, not an array\n * @returns a mode String, not an array (with flex modes expanded)\n */\nexport function expandOtpFlexMode(mode) {\n const modes = reduceOtpFlexModes(mode.split(\",\"));\n return modes\n .map(m => {\n // If both the expanded and shrunk modes are included, remove the exapnded one\n if (m === \"FLEX_EGRESS\" || m === \"FLEX_ACCESS\" || m === \"FLEX_DIRECT\") {\n if (mode.includes(\"FLEX\")) return \"\";\n }\n if (m === \"FLEX\") {\n return \"FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT\";\n }\n return m;\n })\n .join(\",\");\n}\n\n/**\n * Determines whether the specified query differs from the default query, i.e.,\n * whether the user has modified any trip options (including mode) from their\n * default values.\n */\nexport function isNotDefaultQuery(query, config) {\n const activeModes = reduceOtpFlexModes(query.mode.split(\",\").sort());\n if (\n activeModes.length !== 2 ||\n activeModes[0] !== \"TRANSIT\" ||\n activeModes[1] !== \"WALK\"\n ) {\n // Default mode is TRANSIT,WALK. If general TRANSIT is not used, check\n // against available transit modes in config.\n const defaultModes = getTransitModes(config)\n .concat([\"WALK\"])\n .sort();\n const modesEqual =\n activeModes.length === defaultModes.length &&\n activeModes.every((value, index) => {\n return value === defaultModes[index];\n });\n if (!modesEqual) return true;\n }\n // If modes are equal, check the remaining params.\n const defaultQuery = getDefaultQuery(config);\n for (let i = 0; i < defaultParams.length; i++) {\n const param = defaultParams[i];\n const paramInfo = queryParams.find(qp => qp.name === param);\n // If the parameter applies to the query and does not match the default\n // value, the query is not default.\n if (\n isParamApplicable(paramInfo, query, config) &&\n query[param] !== defaultQuery[param]\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Geocode utility for returning the first result for the provided place name text.\n * @param {string} text - text to search\n * @param {Object} geocoderConfig\n * @return {Location}\n */\nasync function getFirstGeocodeResult(text, geocoderConfig) {\n const geocoder = getGeocoder(geocoderConfig);\n // Attempt to geocode search text and return first result if found.\n // TODO: Import geocoder from @opentripplanner\n return geocoder.search({ text }).then(result => {\n const firstResult = result.features && result.features[0];\n if (firstResult) {\n return geocoder.getLocationFromGeocodedFeature(firstResult);\n }\n return null;\n });\n}\n\n/**\n * OTP allows passing a location in the form '123 Main St::lat,lon', so we check\n * for the double colon and parse the coordinates accordingly.\n * @param {string} value - query param for place described above\n * @return {Location} - location or null if the value is falsey or the parsed\n * coordinates do not result in both a lat and lon\n */\nexport function parseLocationString(value) {\n if (!value) return null;\n const parts = value.split(\"::\");\n const coordinates = parts[1]\n ? stringToCoords(parts[1])\n : stringToCoords(parts[0]);\n const name = parts[1] ? parts[0] : coordsToString(coordinates);\n return coordinates.length === 2\n ? {\n name: name || null,\n lat: coordinates[0] || null,\n lon: coordinates[1] || null\n }\n : null;\n}\n\n/**\n * Convert a string query param for a from or to place into a location. If\n * coordinates not provided and geocoder config is present, use the first\n * geocoded result.\n * @param {string} value\n * @param {Object} [geocoderConfig=null]\n * @return {Location}\n */\nasync function queryParamToLocation(value, geocoderConfig) {\n let location = parseLocationString(value);\n if (!location && value && geocoderConfig) {\n // If a valid location was not found, but the place name text exists,\n // attempt to geocode the name.\n location = await getFirstGeocodeResult(value, geocoderConfig);\n }\n return location;\n}\n\n/**\n * Create a otp query based on a the url params.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n */\nexport function planParamsToQuery(params) {\n const query = {};\n Object.keys(params).forEach(key => {\n switch (key) {\n case \"fromPlace\":\n query.from = parseLocationString(params.fromPlace);\n break;\n case \"toPlace\":\n query.to = parseLocationString(params.toPlace);\n break;\n case \"arriveBy\":\n query.departArrive =\n params.arriveBy === \"true\"\n ? \"ARRIVE\"\n : params.arriveBy === \"false\"\n ? \"DEPART\"\n : \"NOW\";\n break;\n case \"date\":\n query.date = params.date || getCurrentDate();\n break;\n case \"time\":\n {\n const parsedTime = moment(params.time, TIME_FORMATS);\n query.time = parsedTime.isValid()\n ? parsedTime.format(OTP_API_TIME_FORMAT)\n : getCurrentTime();\n }\n break;\n case \"intermediatePlaces\":\n // If query has intermediate places, ensure that they are parsed\n // as locations.\n query.intermediatePlaces = params.intermediatePlaces\n ? params.intermediatePlaces.map(parseLocationString)\n : [];\n break;\n default: {\n const maybeNumber = Number(params[key]);\n // If the param value is an empty string literal and is not a number,\n // use string value. Else, use parsed number value.\n // See https://github.com/opentripplanner/otp-ui/issues/50\n query[key] =\n params[key] === \"\" || Number.isNaN(maybeNumber)\n ? params[key]\n : maybeNumber;\n break;\n }\n }\n });\n return query;\n}\n\n/**\n * Async method to create a otp query based on a the url params. This provides\n * the same functionality as planParamsToQuery, except that it will also attempt\n * to geocode the input from and to strings if no lat/lng values were provided.\n *\n * @param {Object} params An object representing the parsed querystring of url\n * params.\n * @param config the config in the otp-rr store.\n */\nexport async function planParamsToQueryAsync(params, config = {}) {\n // Construct query from plan params.\n const query = planParamsToQuery(params);\n // Attempt to geocode from and to params if the string parsing does not return\n // valid locations.\n if (!query.from) {\n query.from = await queryParamToLocation(params.fromPlace, config.geocoder);\n }\n if (!query.to) {\n query.to = await queryParamToLocation(params.toPlace, config.geocoder);\n }\n return query;\n}\n\n/**\n * Create an object that can be used as a querystring in making an OTP\n * PlannerResource request.\n *\n * See http://otp-docs.ibi-transit.com/api/resource_PlannerResource.html\n *\n * @param {Object} config The OTP application config. See types#configType\n * @param {Object} currentQuery The current query parameters as saved in the\n * application state. This method does some extra logic on top of this data\n * in order to create a request suitable for OTP. See __tests__/query.js#L14 for more.\n * @param {boolean} ignoreRealtimeUpdates If true, will create a request that\n * does not use realtime data.\n */\nexport function getRoutingParams(config, currentQuery, ignoreRealtimeUpdates) {\n const routingType = currentQuery.routingType;\n const isItinerary = routingType === \"ITINERARY\";\n let params = {};\n\n // Start with the universe of OTP parameters defined in query-params.js:\n queryParams\n .filter(qp => {\n // A given parameter is included in the request if all of the following:\n // 1. Must apply to the active routing type (ITINERARY or PROFILE)\n // 2. Must be included in the current user-defined query\n // 3. Must pass the parameter's applicability test, if one is specified\n return (\n qp.routingTypes.indexOf(routingType) !== -1 &&\n qp.name in currentQuery &&\n (typeof qp.applicable !== \"function\" ||\n qp.applicable(currentQuery, config))\n );\n })\n .forEach(qp => {\n // Translate the applicable parameters according to their rewrite\n // functions (if provided)\n const rewriteFunction = isItinerary\n ? qp.itineraryRewrite\n : qp.profileRewrite;\n params = Object.assign(\n params,\n rewriteFunction\n ? rewriteFunction(currentQuery[qp.name])\n : { [qp.name]: currentQuery[qp.name] }\n );\n });\n\n // Additional processing specific to ITINERARY mode\n if (isItinerary) {\n // override ignoreRealtimeUpdates if provided\n if (typeof ignoreRealtimeUpdates === \"boolean\") {\n params.ignoreRealtimeUpdates = ignoreRealtimeUpdates;\n }\n\n // check date/time validity; ignore both if either is invalid\n const dateValid = moment(params.date, OTP_API_DATE_FORMAT).isValid();\n const timeValid = moment(params.time, OTP_API_TIME_FORMAT).isValid();\n\n if (!dateValid || !timeValid) {\n delete params.time;\n delete params.date;\n }\n\n // temp: set additional parameters for CAR_HAIL or CAR_RENT trips\n if (\n params.mode &&\n (params.mode.includes(\"CAR_HAIL\") || params.mode.includes(\"CAR_RENT\"))\n ) {\n params.minTransitDistance = \"50%\";\n // increase search timeout because these queries can take a while\n params.searchTimeout = 10000;\n }\n\n // set onlyTransitTrips for car rental searches\n if (params.mode && params.mode.includes(\"CAR_RENT\")) {\n params.onlyTransitTrips = true;\n }\n\n // Additional processing specific to PROFILE mode\n } else {\n // check start and end time validity; ignore both if either is invalid\n const startTimeValid = moment(\n params.startTime,\n OTP_API_TIME_FORMAT\n ).isValid();\n const endTimeValid = moment(params.endTime, OTP_API_TIME_FORMAT).isValid();\n\n if (!startTimeValid || !endTimeValid) {\n delete params.startTimeValid;\n delete params.endTimeValid;\n }\n }\n\n // TODO: check that valid from/to locations are provided\n\n // hack to add walking to driving/TNC trips\n if (hasCar(params.mode)) {\n params.mode += \",WALK\";\n }\n\n // Replace FLEX placeholder with OTP flex modes\n if (params.mode) {\n // Ensure query is in reduced format to avoid replacing twice\n const reducedMode = reduceOtpFlexModes(params.mode.split(\",\")).join(\",\");\n params.mode = expandOtpFlexMode(reducedMode);\n }\n\n return params;\n}\n"],"file":"query.js"}
package/lib/time.js CHANGED
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.toHoursMinutesSeconds = toHoursMinutesSeconds;
6
7
  exports.getTimeFormat = getTimeFormat;
7
8
  exports.getDateFormat = getDateFormat;
8
9
  exports.getLongDateFormat = getLongDateFormat;
9
10
  exports.formatDuration = formatDuration;
10
11
  exports.formatDurationWithSeconds = formatDurationWithSeconds;
12
+ exports.offsetTime = offsetTime;
11
13
  exports.formatTime = formatTime;
12
14
  exports.formatSecondsAfterMidnight = formatSecondsAfterMidnight;
13
15
  exports.getUserTimezone = getUserTimezone;
@@ -40,7 +42,10 @@ const OTP_API_TIME_FORMAT = "HH:mm";
40
42
 
41
43
  exports.OTP_API_TIME_FORMAT = OTP_API_TIME_FORMAT;
42
44
 
43
- function formatDurationLikeMoment(seconds, showSeconds, localize = true) {
45
+ function formatDurationLikeMoment(seconds, showSeconds, localize = {
46
+ enabled: true,
47
+ code: "en-US"
48
+ }) {
44
49
  // date-fns doesn't do this automatically
45
50
  if (!showSeconds && seconds < 60 || seconds === 0) {
46
51
  return "0 min";
@@ -55,7 +60,8 @@ function formatDurationLikeMoment(seconds, showSeconds, localize = true) {
55
60
  xSeconds: "sec"
56
61
  };
57
62
  const locale = localize ? {
58
- code: "en-US",
63
+ // Maintain backwards compatibility when called with localize=true
64
+ code: (localize === null || localize === void 0 ? void 0 : localize.code) || "en-US",
59
65
  formatDistance: (spec, val) => {
60
66
  return `${val} ${specLookup[spec]}`;
61
67
  }
@@ -69,6 +75,22 @@ function formatDurationLikeMoment(seconds, showSeconds, localize = true) {
69
75
  locale
70
76
  });
71
77
  }
78
+ /**
79
+ * Breaks up a duration in seconds into hours, minutes, and seconds.
80
+ * @param {number} seconds The number of seconds to break up
81
+ * @returns an object with fields with the corresponding, hours, minutes, seconds.
82
+ */
83
+
84
+
85
+ function toHoursMinutesSeconds(seconds) {
86
+ const hours = Math.floor(seconds / 3600);
87
+ const minutes = Math.floor((seconds - hours * 3600) / 60);
88
+ return {
89
+ hours,
90
+ minutes,
91
+ seconds: seconds - hours * 3600 - minutes * 60
92
+ };
93
+ }
72
94
  /**
73
95
  * @param {[type]} config the OTP config object found in store
74
96
  * @return {string} the config-defined time formatter or HH:mm (24-hr time)
@@ -111,8 +133,20 @@ function formatDuration(seconds) {
111
133
  */
112
134
 
113
135
 
114
- function formatDurationWithSeconds(seconds) {
115
- return formatDurationLikeMoment(seconds, true);
136
+ function formatDurationWithSeconds(seconds, region) {
137
+ return formatDurationLikeMoment(seconds, {
138
+ enabled: true,
139
+ code: region
140
+ });
141
+ }
142
+ /**
143
+ * Offsets a time according to the provided time options
144
+ * and returns the result.
145
+ */
146
+
147
+
148
+ function offsetTime(ms, options) {
149
+ return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
116
150
  }
117
151
  /**
118
152
  * Formats a time value for display in narrative
@@ -123,7 +157,7 @@ function formatDurationWithSeconds(seconds) {
123
157
 
124
158
 
125
159
  function formatTime(ms, options) {
126
- return (0, _dateFns.format)(ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0), (options === null || options === void 0 ? void 0 : options.format) || OTP_API_TIME_FORMAT);
160
+ return (0, _dateFns.format)(offsetTime(ms, options), (options === null || options === void 0 ? void 0 : options.format) || OTP_API_TIME_FORMAT);
127
161
  }
128
162
  /**
129
163
  * Formats a seconds after midnight value for display in narrative
package/lib/time.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/time.js"],"names":["OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","code","formatDistance","spec","val","undefined","format","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","formatDuration","formatDurationWithSeconds","formatTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeF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oCjC,OAApC,EAA6CsB,UAA7C,EAAyD;AAC9D,QAAMY,IAAI,GAAG,kBAAI,yBAAW,IAAIC,IAAJ,EAAX,CAAJ,EAA4B;AAAEnC,IAAAA;AAAF,GAA5B,CAAb;AACA,SAAO,qBAAOkC,IAAP,EAAaZ,UAAb,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASc,eAAT,CAAyBC,gBAAgB,GAAG,eAA5C,EAA6D;AAAA;;AAClE,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;;;AACO,SAASS,cAAT,CAAwBC,QAAQ,GAAGX,eAAe,EAAlD,EAAsD;AAC3D,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6CjD,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASmD,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAAsD;AAC3D,SAAO,qBACL,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CADK,EAELlD,4BAFK,CAAP;AAID","sourcesContent":["import {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nfunction formatDurationLikeMoment(seconds, showSeconds, localize = true) {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n code: \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\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) {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config) {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config) {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n\n/**\n * Formats an elapsed time duration for display in narrative.\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDuration(seconds) {\n return formatDurationLikeMoment(seconds, false);\n}\n\n/**\n * Formats an elapsed time in seconds, minutes, hours duration for display in narrative\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDurationWithSeconds(seconds) {\n return formatDurationLikeMoment(seconds, true);\n}\n/**\n * Formats a time value for display in narrative\n * TODO: internationalization/timezone\n * @param {number} ms epoch time value in milliseconds\n * @returns {string} formatted text representation\n */\nexport function formatTime(ms, options) {\n return format(\n ms + (options?.offset || 0),\n options?.format || OTP_API_TIME_FORMAT\n );\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(seconds, timeFormat) {\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\") {\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()) {\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()) {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
1
+ {"version":3,"sources":["../src/time.js"],"names":["OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","format","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","formatDuration","formatDurationWithSeconds","region","offsetTime","ms","options","offset","formatTime","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AAMA;;AAEA;AACA;AACO,MAAMA,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;;AACO,MAAMC,4BAA4B,GAAG,YAArC;;AACA,MAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,wBAAT,CACEC,OADF,EAEEC,WAFF,EAGEC,QAAQ,GAAG;AAAEC,EAAAA,OAAO,EAAE,IAAX;AAAiBC,EAAAA,IAAI,EAAE;AAAvB,CAHb,EAIE;AACA;AACA,MAAK,CAACH,WAAD,IAAgBD,OAAO,GAAG,EAA3B,IAAkCA,OAAO,KAAK,CAAlD,EAAqD;AACnD,WAAO,OAAP;AACD;;AAED,QAAMK,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAWP,OAAO,GAAG,IAArB,CAAd;AACA,QAAMQ,OAAO,GAAGF,IAAI,CAACC,KAAL,CAAW,CAACP,OAAO,GAAGK,KAAK,GAAG,IAAnB,IAA2B,EAAtC,CAAhB;AACA,QAAMI,eAAe,GAAGR,WAAW,GAC/BD,OAAO,GAAGK,KAAK,GAAG,IAAlB,GAAyBG,OAAO,GAAG,EADJ,GAE/B,CAFJ;AAGA,QAAME,UAAU,GAAG;AACjBC,IAAAA,MAAM,EAAE,IADS;AAEjBC,IAAAA,QAAQ,EAAE,KAFO;AAGjBC,IAAAA,QAAQ,EAAE;AAHO,GAAnB;AAKA,QAAMC,MAAM,GAAGZ,QAAQ,GACnB;AACE;AACAE,IAAAA,IAAI,EAAE,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEE,IAAV,KAAkB,OAF1B;AAGEW,IAAAA,cAAc,EAAE,CAACC,IAAD,EAAOC,GAAP,KAAe;AAC7B,aAAQ,GAAEA,GAAI,IA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,cAAN,GAAuBC,eAAvB,GAAyCC,QAAzC,KAAqDR,gBAA5D;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASS,cAAT,CAAwBC,QAAQ,GAAGX,eAAe,EAAlD,EAAsD;AAC3D,SAAO,qBAAO,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CAAP,EAA6CrD,mBAA7C,CAAP;AACD;AAED;AACA;AACA;AACA;;;AACO,SAASuD,cAAT,CAAwBF,QAAQ,GAAGX,eAAe,EAAlD,EAAsD;AAC3D,SAAO,qBACL,+BAAeD,IAAI,CAACa,GAAL,EAAf,EAA2BD,QAA3B,CADK,EAELtD,4BAFK,CAAP;AAID","sourcesContent":["import {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nfunction formatDurationLikeMoment(\n seconds,\n showSeconds,\n localize = { enabled: true, code: \"en-US\" }\n) {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\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(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 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) {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config) {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config) {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n\n/**\n * Formats an elapsed time duration for display in narrative.\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDuration(seconds) {\n return formatDurationLikeMoment(seconds, false);\n}\n\n/**\n * Formats an elapsed time in seconds, minutes, hours duration for display in narrative\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDurationWithSeconds(seconds, region) {\n return formatDurationLikeMoment(seconds, { enabled: true, code: region });\n}\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 time value for display in narrative\n * TODO: internationalization/timezone\n * @param {number} ms epoch time value in milliseconds\n * @returns {string} formatted text representation\n */\nexport function formatTime(ms, options) {\n return format(\n offsetTime(ms, options),\n options?.format || OTP_API_TIME_FORMAT\n );\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(seconds, timeFormat) {\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\") {\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()) {\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()) {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/core-utils",
3
- "version": "4.8.1-alpha",
3
+ "version": "4.10.0",
4
4
  "description": "Core functionality that is shared among numerous UI components",
5
5
  "engines": {
6
6
  "node": ">=13"
@@ -77,7 +77,7 @@ Array [
77
77
  },
78
78
  Object {
79
79
  "applicable": [Function],
80
- "default": 1609,
80
+ "default": 1207,
81
81
  "label": "Max Walk Distance In Meters",
82
82
  "name": "maxWalkDistance",
83
83
  "options": Array [
@@ -42,7 +42,7 @@ Object {
42
42
  "maxBikeDistance": 4828,
43
43
  "maxBikeTime": 20,
44
44
  "maxEScooterDistance": 4828,
45
- "maxWalkDistance": 1609,
45
+ "maxWalkDistance": 1207,
46
46
  "maxWalkTime": 15,
47
47
  "mode": "WALK,TRANSIT",
48
48
  "numItineraries": 3,
@@ -66,7 +66,7 @@ Object {
66
66
  "date": "2020-08-24",
67
67
  "fromPlace": "Steamer Lane, Santa Cruz, CA, 95060, USA::36.95471026341096,-122.0248185852425",
68
68
  "ignoreRealtimeUpdates": false,
69
- "maxWalkDistance": 1609,
69
+ "maxWalkDistance": 1207,
70
70
  "mode": "WALK,FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT,TRANSIT",
71
71
  "numItineraries": 3,
72
72
  "optimize": "QUICK",
@@ -100,7 +100,7 @@ Object {
100
100
  "date": "2020-08-24",
101
101
  "fromPlace": "Steamer Lane, Santa Cruz, CA, 95060, USA::36.95471026341096,-122.0248185852425",
102
102
  "ignoreRealtimeUpdates": false,
103
- "maxWalkDistance": 1609,
103
+ "maxWalkDistance": 1207,
104
104
  "mode": "FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT,WALK,BIKE,WALK,TRANSIT,BUS",
105
105
  "numItineraries": 3,
106
106
  "optimize": "QUICK",
@@ -157,7 +157,7 @@ Object {
157
157
  "Lighthouse Point Park, Santa Cruz, CA, USA::36.95145225211049,-122.02672866668283",
158
158
  "Natural Bridges State Beach, 2531 W Cliff Dr, Santa Cruz, CA, 95060, USA::36.95028619314903,-122.05711810284686",
159
159
  ],
160
- "maxWalkDistance": 1609,
160
+ "maxWalkDistance": 1207,
161
161
  "mode": "WALK,TRANSIT",
162
162
  "numItineraries": 3,
163
163
  "optimize": "QUICK",
@@ -197,7 +197,7 @@ Object {
197
197
  "date": "2020-08-24",
198
198
  "fromPlace": "Steamer Lane, Santa Cruz, CA, 95060, USA::36.95471026341096,-122.0248185852425",
199
199
  "ignoreRealtimeUpdates": false,
200
- "maxWalkDistance": 1609,
200
+ "maxWalkDistance": 1207,
201
201
  "mode": "WALK,TRANSIT,FLEX_EGRESS,FLEX_ACCESS,FLEX_DIRECT",
202
202
  "numItineraries": 3,
203
203
  "optimize": "QUICK",
@@ -230,7 +230,7 @@ Object {
230
230
  "date": "2020-08-24",
231
231
  "fromPlace": "Steamer Lane, Santa Cruz, CA, 95060, USA::36.95471026341096,-122.0248185852425",
232
232
  "ignoreRealtimeUpdates": false,
233
- "maxWalkDistance": 1609,
233
+ "maxWalkDistance": 1207,
234
234
  "mode": "WALK,TRANSIT",
235
235
  "numItineraries": 3,
236
236
  "optimize": "QUICK",