@opentripplanner/core-utils 13.0.0-alpha.4 → 14.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/__mocks__/fake-route-data.story.json +5425 -0
- package/esm/__mocks__/fake-transit-operators.story.json +97 -0
- package/esm/__tests__/__mocks__/routes.json +234 -105
- package/esm/query-gen.js +1 -3
- package/esm/query-gen.js.map +1 -1
- package/esm/route.js +36 -21
- package/esm/route.js.map +1 -1
- package/esm/routes.json +234 -105
- package/esm/time.js +10 -0
- package/esm/time.js.map +1 -1
- package/lib/__mocks__/fake-route-data.story.json +5425 -0
- package/lib/__mocks__/fake-transit-operators.story.json +97 -0
- package/lib/__tests__/__mocks__/routes.json +234 -105
- package/lib/query-gen.js +1 -1
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts +35 -1
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +38 -17
- package/lib/route.js.map +1 -1
- package/lib/time.d.ts +7 -0
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +10 -1
- package/lib/time.js.map +1 -1
- package/package.json +2 -2
- package/src/__mocks__/fake-route-data.story.json +5425 -0
- package/src/__mocks__/fake-transit-operators.story.json +97 -0
- package/src/__snapshots__/core-utils.story.tsx.snap +8382 -0
- package/src/__tests__/__mocks__/routes.json +234 -105
- package/src/__tests__/__snapshots__/route.js.snap +285 -95
- package/src/__tests__/route.js +27 -55
- package/src/core-utils.story.tsx +200 -1
- package/src/query-gen.ts +1 -1
- package/src/route.ts +41 -21
- package/src/time.ts +9 -0
- package/tsconfig.tsbuildinfo +1 -1
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","_config$dateTime","dateTime","timeFormat","getDateFormat","_config$dateTime2","dateFormat","getLongDateFormat","_config$dateTime3","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","_Intl","fallbackTimezone","arguments","length","undefined","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"sources":["../src/time.ts"],"sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\n/** @deprecated */\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"mappings":"AACA,SAASA,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,UAAU;AAClD,SAASC,cAAc,QAAQ,aAAa;;AAE5C;AACA;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAAY;AAC/C,OAAO,IAAMC,mBAAmB,GAAG,OAAO;;AAE1C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,OAAe,EAKf;EACA,OAAO;IACLC,KAAK,EAAEC,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,IAAI,CAAC;IACjCI,OAAO,EAAEF,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;IACtCA,OAAO,EAAEA,OAAO,GAAG;EACrB,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"time.js","names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","ensureAtLeastOneMinute","duration","getTimeFormat","config","_config$dateTime","dateTime","timeFormat","getDateFormat","_config$dateTime2","dateFormat","getLongDateFormat","_config$dateTime3","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","_Intl","fallbackTimezone","arguments","length","undefined","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"sources":["../src/time.ts"],"sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * If a duration is less than 60 seconds, round it to one minute, to avoid a duration\n * of 0 minutes on a leg.\n * @param {number} duration The leg or trip duration in seconds\n * @returns a duration in seconds of at least 60 seconds.\n */\nexport const ensureAtLeastOneMinute = (duration: number): number =>\n duration < 60 ? 60 : duration;\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\n/** @deprecated */\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"mappings":"AACA,SAASA,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,UAAU;AAClD,SAASC,cAAc,QAAQ,aAAa;;AAE5C;AACA;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAAY;AAC/C,OAAO,IAAMC,mBAAmB,GAAG,OAAO;;AAE1C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,OAAe,EAKf;EACA,OAAO;IACLC,KAAK,EAAEC,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,IAAI,CAAC;IACjCI,OAAO,EAAEF,IAAI,CAACC,KAAK,CAACH,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE;IACtCA,OAAO,EAAEA,OAAO,GAAG;EACrB,CAAC;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