@vielzeug/tempo 2.0.0 → 2.1.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.
Files changed (59) hide show
  1. package/dist/_convert.cjs.map +1 -1
  2. package/dist/_convert.d.ts.map +1 -1
  3. package/dist/_convert.js.map +1 -1
  4. package/dist/_floor.cjs +1 -1
  5. package/dist/_floor.cjs.map +1 -1
  6. package/dist/_floor.d.ts +3 -3
  7. package/dist/_floor.d.ts.map +1 -1
  8. package/dist/_floor.js +0 -1
  9. package/dist/_floor.js.map +1 -1
  10. package/dist/_tz.cjs +1 -1
  11. package/dist/_tz.cjs.map +1 -1
  12. package/dist/_tz.d.ts +0 -2
  13. package/dist/_tz.d.ts.map +1 -1
  14. package/dist/_tz.js +2 -5
  15. package/dist/_tz.js.map +1 -1
  16. package/dist/boundary.cjs +1 -1
  17. package/dist/boundary.cjs.map +1 -1
  18. package/dist/boundary.d.ts +1 -1
  19. package/dist/boundary.d.ts.map +1 -1
  20. package/dist/boundary.js +0 -1
  21. package/dist/boundary.js.map +1 -1
  22. package/dist/classify.cjs.map +1 -1
  23. package/dist/classify.d.ts.map +1 -1
  24. package/dist/classify.js.map +1 -1
  25. package/dist/compare.cjs +1 -1
  26. package/dist/compare.cjs.map +1 -1
  27. package/dist/compare.d.ts +1 -1
  28. package/dist/compare.d.ts.map +1 -1
  29. package/dist/compare.js +20 -17
  30. package/dist/compare.js.map +1 -1
  31. package/dist/core.cjs.map +1 -1
  32. package/dist/core.d.ts.map +1 -1
  33. package/dist/core.js.map +1 -1
  34. package/dist/errors.cjs +1 -1
  35. package/dist/errors.cjs.map +1 -1
  36. package/dist/errors.d.ts +0 -1
  37. package/dist/errors.d.ts.map +1 -1
  38. package/dist/errors.js +1 -4
  39. package/dist/errors.js.map +1 -1
  40. package/dist/format.cjs.map +1 -1
  41. package/dist/format.d.ts +10 -4
  42. package/dist/format.d.ts.map +1 -1
  43. package/dist/format.js.map +1 -1
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.d.ts +3 -3
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +6 -6
  48. package/dist/range.cjs.map +1 -1
  49. package/dist/range.d.ts.map +1 -1
  50. package/dist/range.js.map +1 -1
  51. package/dist/tempo.cjs +1 -1
  52. package/dist/tempo.cjs.map +1 -1
  53. package/dist/tempo.iife.js +1 -1
  54. package/dist/tempo.iife.js.map +1 -1
  55. package/dist/tempo.js +1 -1
  56. package/dist/tempo.js.map +1 -1
  57. package/dist/types.d.ts +1 -1
  58. package/dist/types.d.ts.map +1 -1
  59. package/package.json +23 -18
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\nimport { validateTimeZone } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":"8FAaA,SAAgB,EAAU,EAAkB,EAA6B,CAAC,EAAqB,CAC7F,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAE9C,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,UAAU,EAE/D,EAAQ,UACX,EAAA,KACE,0FACA,EAAA,mBACF,EAGF,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,CAAC,CAAC,UAAU,EAG/F,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,CAAC,CAAC,UAAU,EAE9F,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAQ,EAAkB,EAA4D,CACpG,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,aAAa,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAAM,mBAAmB,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,EAGnF,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,EAElF,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAW,EAAkB,EAA0C,CACrF,OAAO,EAAQ,EAAO,CAAE,UAAS,CAAC,CACpC"}
1
+ {"version":3,"file":"_convert.cjs","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { validateTimeZone } from './_tz';\nimport { fail, TempoMissingTzError, TempoUnsupportedInputError } from './errors';\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":"8FAWA,SAAgB,EAAU,EAAkB,EAA6B,CAAC,EAAqB,CAC7F,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAE9C,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,UAAU,EAE/D,EAAQ,UACX,EAAA,KACE,0FACA,EAAA,mBACF,EAGF,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,CAAC,CAAC,UAAU,EAG/F,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,CAAC,CAAC,UAAU,EAE9F,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAQ,EAAkB,EAA4D,CACpG,IAAM,EAAW,EAAA,iBAAiB,EAAQ,QAAQ,EAElD,GAAI,aAAiB,EAAA,SAAS,cAAe,OAAO,EAAM,aAAa,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,QAAS,OAAO,EAAM,mBAAmB,CAAQ,EAE/E,GAAI,aAAiB,EAAA,SAAS,cAC5B,OAAO,EAAM,gBAAgB,EAAU,CAAE,eAAgB,EAAQ,cAAe,CAAC,EAGnF,GAAI,aAAiB,EAAA,SAAS,UAAW,OAAO,EAAM,gBAAgB,CAAE,UAAS,CAAC,EAElF,EAAA,KAAK,gCAAgC,OAAO,CAAK,IAAK,EAAA,0BAA0B,CAClF,CAEA,SAAgB,EAAW,EAAkB,EAA0C,CACrF,OAAO,EAAQ,EAAO,CAAE,UAAS,CAAC,CACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKzG,KAAK,iBAAiB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AACjE,KAAK,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjG,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC;AAwB3F,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,aAAa,CAcpG;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,CAErF"}
1
+ {"version":3,"file":"_convert.d.ts","sourceRoot":"","sources":["../src/_convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzG,KAAK,iBAAiB,GAAG,qBAAqB,GAAG,eAAe,CAAC;AACjE,KAAK,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,OAAO,CAAC;AACjG,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC;AAwB3F,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,yBAAyB,GAAG,QAAQ,CAAC,aAAa,CAcpG;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,CAErF"}
@@ -1 +1 @@
1
- {"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\nimport { validateTimeZone } from './_tz';\nimport { TempoMissingTzError, TempoUnsupportedInputError, fail } from './errors';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":";;;;AAaA,SAAgB,EAAU,GAAkB,IAA6B,CAAC,GAAqB;CAC7F,IAAI,aAAiB,EAAS,SAAS,OAAO;CAE9C,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,UAAU;CAEpE,AAAK,EAAQ,YACX,EACE,2FACA,CACF;CAGF,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC,CAAC,CAAC,UAAU;CAG/F,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC,CAAC,CAAC,UAAU;CAE9F,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAQ,GAAkB,GAA4D;CACpG,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,aAAa,CAAQ;CAE/E,IAAI,aAAiB,EAAS,SAAS,OAAO,EAAM,mBAAmB,CAAQ;CAE/E,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC;CAGnF,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC;CAElF,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAW,GAAkB,GAA0C;CACrF,OAAO,EAAQ,GAAO,EAAE,YAAS,CAAC;AACpC"}
1
+ {"version":3,"file":"_convert.js","names":[],"sources":["../src/_convert.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { validateTimeZone } from './_tz';\nimport { fail, TempoMissingTzError, TempoUnsupportedInputError } from './errors';\nimport type { AbsoluteTime, DisambiguationOptions, TimeInput, TimeZoneOptions, WallTime } from './types';\n\ntype ResolutionOptions = DisambiguationOptions & TimeZoneOptions;\ntype RequiredResolutionOptions = ResolutionOptions & { timeZone: string };\n\nexport function toInstant(input: AbsoluteTime): Temporal.Instant;\nexport function toInstant(input: WallTime, options: RequiredResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options?: ResolutionOptions): Temporal.Instant;\nexport function toInstant(input: TimeInput, options: ResolutionOptions = {}): Temporal.Instant {\n if (input instanceof Temporal.Instant) return input;\n\n if (input instanceof Temporal.ZonedDateTime) return input.toInstant();\n\n if (!options.timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation }).toInstant();\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone }).toInstant();\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function toZoned(input: TimeInput, options: RequiredResolutionOptions): Temporal.ZonedDateTime {\n const timeZone = validateTimeZone(options.timeZone);\n\n if (input instanceof Temporal.ZonedDateTime) return input.withTimeZone(timeZone);\n\n if (input instanceof Temporal.Instant) return input.toZonedDateTimeISO(timeZone);\n\n if (input instanceof Temporal.PlainDateTime) {\n return input.toZonedDateTime(timeZone, { disambiguation: options.disambiguation });\n }\n\n if (input instanceof Temporal.PlainDate) return input.toZonedDateTime({ timeZone });\n\n fail(`Unsupported time input type: ${String(input)}`, TempoUnsupportedInputError);\n}\n\nexport function inTimeZone(input: TimeInput, timeZone: string): Temporal.ZonedDateTime {\n return toZoned(input, { timeZone });\n}\n"],"mappings":";;;;AAWA,SAAgB,EAAU,GAAkB,IAA6B,CAAC,GAAqB;CAC7F,IAAI,aAAiB,EAAS,SAAS,OAAO;CAE9C,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,UAAU;CAEpE,AAAK,EAAQ,YACX,EACE,2FACA,CACF;CAGF,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC,CAAC,CAAC,UAAU;CAG/F,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC,CAAC,CAAC,UAAU;CAE9F,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAQ,GAAkB,GAA4D;CACpG,IAAM,IAAW,EAAiB,EAAQ,QAAQ;CAElD,IAAI,aAAiB,EAAS,eAAe,OAAO,EAAM,aAAa,CAAQ;CAE/E,IAAI,aAAiB,EAAS,SAAS,OAAO,EAAM,mBAAmB,CAAQ;CAE/E,IAAI,aAAiB,EAAS,eAC5B,OAAO,EAAM,gBAAgB,GAAU,EAAE,gBAAgB,EAAQ,eAAe,CAAC;CAGnF,IAAI,aAAiB,EAAS,WAAW,OAAO,EAAM,gBAAgB,EAAE,YAAS,CAAC;CAElF,EAAK,gCAAgC,OAAO,CAAK,KAAK,CAA0B;AAClF;AAEA,SAAgB,EAAW,GAAkB,GAA0C;CACrF,OAAO,EAAQ,GAAO,EAAE,YAAS,CAAC;AACpC"}
package/dist/_floor.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_convert.cjs");require("@js-temporal/polyfill");var t={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},n={day:t,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...t,day:1},year:{...t,day:1,month:1}};function r(r,i,a){let o=e.toZoned(r,a);if(i===`week`){let e=(o.dayOfWeek-(a.weekStartsOn??1)+7)%7;return o.subtract({days:e}).with(t).toInstant()}return o.with(n[i]).toInstant()}exports.floorToUnit=r;
1
+ const e=require("./_convert.cjs");var t={hour:0,microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},n={day:t,hour:{microsecond:0,millisecond:0,minute:0,nanosecond:0,second:0},minute:{microsecond:0,millisecond:0,nanosecond:0,second:0},month:{...t,day:1},year:{...t,day:1,month:1}};function r(r,i,a){let o=e.toZoned(r,a);if(i===`week`){let e=(o.dayOfWeek-(a.weekStartsOn??1)+7)%7;return o.subtract({days:e}).with(t).toInstant()}return o.with(n[i]).toInstant()}exports.floorToUnit=r;
2
2
  //# sourceMappingURL=_floor.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, Disambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":"mEAMA,IAAM,EAAwC,CAC5C,KAAM,EACN,YAAa,EACb,YAAa,EACb,OAAQ,EACR,WAAY,EACZ,OAAQ,CACV,EAEM,EAAoF,CACxF,IAAK,EACL,KAAM,CAAE,YAAa,EAAG,YAAa,EAAG,OAAQ,EAAG,WAAY,EAAG,OAAQ,CAAE,EAC5E,OAAQ,CAAE,YAAa,EAAG,YAAa,EAAG,WAAY,EAAG,OAAQ,CAAE,EACnE,MAAO,CAAE,GAAG,EAAW,IAAK,CAAE,EAC9B,KAAM,CAAE,GAAG,EAAW,IAAK,EAAG,MAAO,CAAE,CACzC,EAEA,SAAgB,EACd,EACA,EACA,EACkB,CAClB,IAAM,EAAQ,EAAA,QAAQ,EAAO,CAAO,EAEpC,GAAI,IAAS,OAAQ,CACnB,IAAM,GAAkB,EAAM,WAAa,EAAQ,cAAgB,GAAK,GAAK,EAE7E,OAAO,EAAM,SAAS,CAAE,KAAM,CAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU,CAC5E,CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU,CACpD"}
1
+ {"version":3,"file":"_floor.cjs","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: WeekStartDay },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":"kCAIA,IAAM,EAAwC,CAC5C,KAAM,EACN,YAAa,EACb,YAAa,EACb,OAAQ,EACR,WAAY,EACZ,OAAQ,CACV,EAEM,EAAoF,CACxF,IAAK,EACL,KAAM,CAAE,YAAa,EAAG,YAAa,EAAG,OAAQ,EAAG,WAAY,EAAG,OAAQ,CAAE,EAC5E,OAAQ,CAAE,YAAa,EAAG,YAAa,EAAG,WAAY,EAAG,OAAQ,CAAE,EACnE,MAAO,CAAE,GAAG,EAAW,IAAK,CAAE,EAC9B,KAAM,CAAE,GAAG,EAAW,IAAK,EAAG,MAAO,CAAE,CACzC,EAEA,SAAgB,EACd,EACA,EACA,EACkB,CAClB,IAAM,EAAQ,EAAA,QAAQ,EAAO,CAAO,EAEpC,GAAI,IAAS,OAAQ,CACnB,IAAM,GAAkB,EAAM,WAAa,EAAQ,cAAgB,GAAK,GAAK,EAE7E,OAAO,EAAM,SAAS,CAAE,KAAM,CAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU,CAC5E,CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU,CACpD"}
package/dist/_floor.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Temporal } from '@js-temporal/polyfill';
2
- import type { BoundaryUnit, Disambiguation, TimeInput } from './types';
1
+ import type { Temporal } from '@js-temporal/polyfill';
2
+ import type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';
3
3
  export declare function floorToUnit(input: TimeInput, unit: BoundaryUnit, options: {
4
4
  disambiguation?: Disambiguation;
5
5
  timeZone: string;
6
- weekStartsOn?: number;
6
+ weekStartsOn?: WeekStartDay;
7
7
  }): Temporal.Instant;
8
8
  //# sourceMappingURL=_floor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAqBvE,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;IAAE,cAAc,CAAC,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACpF,QAAQ,CAAC,OAAO,CAUlB"}
1
+ {"version":3,"file":"_floor.d.ts","sourceRoot":"","sources":["../src/_floor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAmBrF,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;IAAE,cAAc,CAAC,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,YAAY,CAAA;CAAE,GAC1F,QAAQ,CAAC,OAAO,CAUlB"}
package/dist/_floor.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { toZoned as e } from "./_convert.js";
2
- import "@js-temporal/polyfill";
3
2
  //#region src/_floor.ts
4
3
  var t = {
5
4
  hour: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryUnit, Disambiguation, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: number },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":";;;AAMA,IAAM,IAAwC;CAC5C,MAAM;CACN,aAAa;CACb,aAAa;CACb,QAAQ;CACR,YAAY;CACZ,QAAQ;AACV,GAEM,IAAoF;CACxF,KAAK;CACL,MAAM;EAAE,aAAa;EAAG,aAAa;EAAG,QAAQ;EAAG,YAAY;EAAG,QAAQ;CAAE;CAC5E,QAAQ;EAAE,aAAa;EAAG,aAAa;EAAG,YAAY;EAAG,QAAQ;CAAE;CACnE,OAAO;EAAE,GAAG;EAAW,KAAK;CAAE;CAC9B,MAAM;EAAE,GAAG;EAAW,KAAK;EAAG,OAAO;CAAE;AACzC;AAEA,SAAgB,EACd,GACA,GACA,GACkB;CAClB,IAAM,IAAQ,EAAQ,GAAO,CAAO;CAEpC,IAAI,MAAS,QAAQ;EACnB,IAAM,KAAkB,EAAM,aAAa,EAAQ,gBAAgB,KAAK,KAAK;EAE7E,OAAO,EAAM,SAAS,EAAE,MAAM,EAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU;CAC5E;CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU;AACpD"}
1
+ {"version":3,"file":"_floor.js","names":[],"sources":["../src/_floor.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport type { BoundaryUnit, Disambiguation, TimeInput, WeekStartDay } from './types';\n\nconst TIME_ZERO: Temporal.ZonedDateTimeLike = {\n hour: 0,\n microsecond: 0,\n millisecond: 0,\n minute: 0,\n nanosecond: 0,\n second: 0,\n};\n\nconst BOUNDARY_CLEAR: Record<Exclude<BoundaryUnit, 'week'>, Temporal.ZonedDateTimeLike> = {\n day: TIME_ZERO,\n hour: { microsecond: 0, millisecond: 0, minute: 0, nanosecond: 0, second: 0 },\n minute: { microsecond: 0, millisecond: 0, nanosecond: 0, second: 0 },\n month: { ...TIME_ZERO, day: 1 },\n year: { ...TIME_ZERO, day: 1, month: 1 },\n};\n\nexport function floorToUnit(\n input: TimeInput,\n unit: BoundaryUnit,\n options: { disambiguation?: Disambiguation; timeZone: string; weekStartsOn?: WeekStartDay },\n): Temporal.Instant {\n const zoned = toZoned(input, options);\n\n if (unit === 'week') {\n const daysToSubtract = (zoned.dayOfWeek - (options.weekStartsOn ?? 1) + 7) % 7;\n\n return zoned.subtract({ days: daysToSubtract }).with(TIME_ZERO).toInstant();\n }\n\n return zoned.with(BOUNDARY_CLEAR[unit]).toInstant();\n}\n"],"mappings":";;AAIA,IAAM,IAAwC;CAC5C,MAAM;CACN,aAAa;CACb,aAAa;CACb,QAAQ;CACR,YAAY;CACZ,QAAQ;AACV,GAEM,IAAoF;CACxF,KAAK;CACL,MAAM;EAAE,aAAa;EAAG,aAAa;EAAG,QAAQ;EAAG,YAAY;EAAG,QAAQ;CAAE;CAC5E,QAAQ;EAAE,aAAa;EAAG,aAAa;EAAG,YAAY;EAAG,QAAQ;CAAE;CACnE,OAAO;EAAE,GAAG;EAAW,KAAK;CAAE;CAC9B,MAAM;EAAE,GAAG;EAAW,KAAK;EAAG,OAAO;CAAE;AACzC;AAEA,SAAgB,EACd,GACA,GACA,GACkB;CAClB,IAAM,IAAQ,EAAQ,GAAO,CAAO;CAEpC,IAAI,MAAS,QAAQ;EACnB,IAAM,KAAkB,EAAM,aAAa,EAAQ,gBAAgB,KAAK,KAAK;EAE7E,OAAO,EAAM,SAAS,EAAE,MAAM,EAAe,CAAC,CAAC,CAAC,KAAK,CAAS,CAAC,CAAC,UAAU;CAC5E;CAEA,OAAO,EAAM,KAAK,EAAe,EAAK,CAAC,CAAC,UAAU;AACpD"}
package/dist/_tz.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs");let t=require("@js-temporal/polyfill");function n(n){try{t.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(n)}catch{e.fail(`Unknown or invalid timezone: "${n}". Expected an IANA timezone name or UTC offset.`,e.TempoInvalidTzError)}return n}function r(r,i){let a=i.timeZone??(r instanceof t.Temporal.ZonedDateTime?r.timeZoneId:void 0);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),n(a)}function i(r,i){if(i.timeZone)return n(i.timeZone);let a;for(let n of r)n instanceof t.Temporal.ZonedDateTime&&(a?a!==n.timeZoneId&&e.fail(`Inputs use different time zones. Pass options.timeZone explicitly.`):a=n.timeZoneId);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),a}function a(e,n){return t.Temporal.Instant.compare(e,n)<=0?[e,n]:[n,e]}var o=new Set([`day`,`month`,`week`,`year`]);exports.CALENDAR_UNITS=o,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.normalizeRange=a,exports.validateTimeZone=n;
1
+ const e=require("./errors.cjs");let t=require("@js-temporal/polyfill");function n(n){try{t.Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(n)}catch{e.fail(`Unknown or invalid timezone: "${n}". Expected an IANA timezone name or UTC offset.`,e.TempoInvalidTzError)}return n}function r(r,i){let a=i.timeZone??(r instanceof t.Temporal.ZonedDateTime?r.timeZoneId:void 0);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),n(a)}function i(r,i){if(i.timeZone)return n(i.timeZone);let a;for(let n of r)n instanceof t.Temporal.ZonedDateTime&&(a?a!==n.timeZoneId&&e.fail(`Inputs use different time zones. Pass options.timeZone explicitly.`):a=n.timeZoneId);return a||e.fail(`This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.`,e.TempoMissingTzError),a}var a=new Set([`day`,`month`,`week`,`year`]);exports.CALENDAR_UNITS=a,exports.inferSharedTimeZone=i,exports.inferTimeZone=r,exports.validateTimeZone=n;
2
2
  //# sourceMappingURL=_tz.cjs.map
package/dist/_tz.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_tz.cjs","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":"uEAMA,SAAgB,EAAiB,EAA0B,CACzD,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CACvE,MAAQ,CACN,EAAA,KACE,iCAAiC,EAAS,kDAC1C,EAAA,mBACF,CACF,CAEA,OAAO,CACT,CAEA,SAAgB,EAAc,EAAkB,EAAkC,CAChF,IAAM,EAAW,EAAQ,WAAa,aAAiB,EAAA,SAAS,cAAgB,EAAM,WAAa,IAAA,IASnG,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,EAAiB,CAAQ,CAClC,CAEA,SAAgB,EAAoB,EAA8B,EAAkC,CAClG,GAAI,EAAQ,SAAU,OAAO,EAAiB,EAAQ,QAAQ,EAE9D,IAAI,EAEJ,IAAK,IAAM,KAAS,EACZ,aAAiB,EAAA,SAAS,gBAE3B,EACI,IAAa,EAAM,YAC1B,EAAA,KAAK,oEAAoE,EAF5D,EAAW,EAAM,YAalC,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,CACT,CAEA,SAAgB,EAAe,EAAyB,EAA6D,CACnH,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAO,CAAG,GAAK,EAAI,CAAC,EAAO,CAAG,EAAI,CAAC,EAAK,CAAK,CAC/E,CAEA,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC"}
1
+ {"version":3,"file":"_tz.cjs","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":"uEAIA,SAAgB,EAAiB,EAA0B,CACzD,GAAI,CACF,EAAA,SAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CACvE,MAAQ,CACN,EAAA,KACE,iCAAiC,EAAS,kDAC1C,EAAA,mBACF,CACF,CAEA,OAAO,CACT,CAEA,SAAgB,EAAc,EAAkB,EAAkC,CAChF,IAAM,EAAW,EAAQ,WAAa,aAAiB,EAAA,SAAS,cAAgB,EAAM,WAAa,IAAA,IASnG,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,EAAiB,CAAQ,CAClC,CAEA,SAAgB,EAAoB,EAA8B,EAAkC,CAClG,GAAI,EAAQ,SAAU,OAAO,EAAiB,EAAQ,QAAQ,EAE9D,IAAI,EAEJ,IAAK,IAAM,KAAS,EACZ,aAAiB,EAAA,SAAS,gBAE3B,EACI,IAAa,EAAM,YAC1B,EAAA,KAAK,oEAAoE,EAF5D,EAAW,EAAM,YAalC,OAPK,GACH,EAAA,KACE,0FACA,EAAA,mBACF,EAGK,CACT,CAEA,IAAa,EAAiB,IAAI,IAAkB,CAAC,MAAO,QAAS,OAAQ,MAAM,CAAC"}
package/dist/_tz.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { Temporal } from '@js-temporal/polyfill';
2
1
  import type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';
3
2
  export declare function validateTimeZone(timeZone: string): string;
4
3
  export declare function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string;
5
4
  export declare function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string;
6
- export declare function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant];
7
5
  export declare const CALENDAR_UNITS: Set<CalendarUnit>;
8
6
  //# sourceMappingURL=_tz.d.ts.map
package/dist/_tz.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAIxE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWzD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAWhF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAsBlG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAEnH;AAED,eAAO,MAAM,cAAc,mBAA0D,CAAC"}
1
+ {"version":3,"file":"_tz.d.ts","sourceRoot":"","sources":["../src/_tz.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWzD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAWhF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAsBlG;AAED,eAAO,MAAM,cAAc,mBAA0D,CAAC"}
package/dist/_tz.js CHANGED
@@ -19,16 +19,13 @@ function o(e, a) {
19
19
  for (let t of e) t instanceof r.ZonedDateTime && (o ? o !== t.timeZoneId && n("Inputs use different time zones. Pass options.timeZone explicitly.") : o = t.timeZoneId);
20
20
  return o || n("This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.", t), o;
21
21
  }
22
- function s(e, t) {
23
- return r.Instant.compare(e, t) <= 0 ? [e, t] : [t, e];
24
- }
25
- var c = /* @__PURE__ */ new Set([
22
+ var s = /* @__PURE__ */ new Set([
26
23
  "day",
27
24
  "month",
28
25
  "week",
29
26
  "year"
30
27
  ]);
31
28
  //#endregion
32
- export { c as CALENDAR_UNITS, o as inferSharedTimeZone, a as inferTimeZone, s as normalizeRange, i as validateTimeZone };
29
+ export { s as CALENDAR_UNITS, o as inferSharedTimeZone, a as inferTimeZone, i as validateTimeZone };
33
30
 
34
31
  //# sourceMappingURL=_tz.js.map
package/dist/_tz.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"_tz.js","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nimport { TempoInvalidTzError, TempoMissingTzError, fail } from './errors';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport function normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":";;;AAMA,SAAgB,EAAiB,GAA0B;CACzD,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ;CACvE,QAAQ;EACN,EACE,iCAAiC,EAAS,mDAC1C,CACF;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAc,GAAkB,GAAkC;CAChF,IAAM,IAAW,EAAQ,aAAa,aAAiB,EAAS,gBAAgB,EAAM,aAAa,KAAA;CASnG,OAPK,KACH,EACE,2FACA,CACF,GAGK,EAAiB,CAAQ;AAClC;AAEA,SAAgB,EAAoB,GAA8B,GAAkC;CAClG,IAAI,EAAQ,UAAU,OAAO,EAAiB,EAAQ,QAAQ;CAE9D,IAAI;CAEJ,KAAK,IAAM,KAAS,GACZ,aAAiB,EAAS,kBAE3B,IACI,MAAa,EAAM,cAC1B,EAAK,oEAAoE,IAF5D,IAAW,EAAM;CAalC,OAPK,KACH,EACE,2FACA,CACF,GAGK;AACT;AAEA,SAAgB,EAAe,GAAyB,GAA6D;CACnH,OAAO,EAAS,QAAQ,QAAQ,GAAO,CAAG,KAAK,IAAI,CAAC,GAAO,CAAG,IAAI,CAAC,GAAK,CAAK;AAC/E;AAEA,IAAa,oBAAiB,IAAI,IAAkB;CAAC;CAAO;CAAS;CAAQ;AAAM,CAAC"}
1
+ {"version":3,"file":"_tz.js","names":[],"sources":["../src/_tz.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { fail, TempoInvalidTzError, TempoMissingTzError } from './errors';\nimport type { CalendarUnit, TimeInput, TimeZoneOptions } from './types';\n\nexport function validateTimeZone(timeZone: string): string {\n try {\n Temporal.Instant.fromEpochMilliseconds(0).toZonedDateTimeISO(timeZone);\n } catch {\n fail(\n `Unknown or invalid timezone: \"${timeZone}\". Expected an IANA timezone name or UTC offset.`,\n TempoInvalidTzError,\n );\n }\n\n return timeZone;\n}\n\nexport function inferTimeZone(input: TimeInput, options: TimeZoneOptions): string {\n const timeZone = options.timeZone ?? (input instanceof Temporal.ZonedDateTime ? input.timeZoneId : undefined);\n\n if (!timeZone) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return validateTimeZone(timeZone);\n}\n\nexport function inferSharedTimeZone(inputs: readonly TimeInput[], options: TimeZoneOptions): string {\n if (options.timeZone) return validateTimeZone(options.timeZone);\n\n let inferred: string | undefined;\n\n for (const input of inputs) {\n if (!(input instanceof Temporal.ZonedDateTime)) continue;\n\n if (!inferred) inferred = input.timeZoneId;\n else if (inferred !== input.timeZoneId) {\n fail('Inputs use different time zones. Pass options.timeZone explicitly.');\n }\n }\n\n if (!inferred) {\n fail(\n 'This operation requires a timeZone. Pass options.timeZone or use a ZonedDateTime input.',\n TempoMissingTzError,\n );\n }\n\n return inferred;\n}\n\nexport const CALENDAR_UNITS = new Set<CalendarUnit>(['day', 'month', 'week', 'year']);\n"],"mappings":";;;AAIA,SAAgB,EAAiB,GAA0B;CACzD,IAAI;EACF,EAAS,QAAQ,sBAAsB,CAAC,CAAC,CAAC,mBAAmB,CAAQ;CACvE,QAAQ;EACN,EACE,iCAAiC,EAAS,mDAC1C,CACF;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAc,GAAkB,GAAkC;CAChF,IAAM,IAAW,EAAQ,aAAa,aAAiB,EAAS,gBAAgB,EAAM,aAAa,KAAA;CASnG,OAPK,KACH,EACE,2FACA,CACF,GAGK,EAAiB,CAAQ;AAClC;AAEA,SAAgB,EAAoB,GAA8B,GAAkC;CAClG,IAAI,EAAQ,UAAU,OAAO,EAAiB,EAAQ,QAAQ;CAE9D,IAAI;CAEJ,KAAK,IAAM,KAAS,GACZ,aAAiB,EAAS,kBAE3B,IACI,MAAa,EAAM,cAC1B,EAAK,oEAAoE,IAF5D,IAAW,EAAM;CAalC,OAPK,KACH,EACE,2FACA,CACF,GAGK;AACT;AAEA,IAAa,oBAAiB,IAAI,IAAkB;CAAC;CAAO;CAAS;CAAQ;AAAM,CAAC"}
package/dist/boundary.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_tz.cjs"),t=require("./_floor.cjs");require("@js-temporal/polyfill");var n={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function r(n,r,i={}){let a=e.inferTimeZone(n,i);return t.floorToUnit(n,r,{timeZone:a,weekStartsOn:i.weekStartsOn}).toZonedDateTimeISO(a)}function i(r,i,a={}){let o=e.inferTimeZone(r,a);return t.floorToUnit(r,i,{timeZone:o,weekStartsOn:a.weekStartsOn}).toZonedDateTimeISO(o).add(n[i]).subtract({nanoseconds:1})}exports.endOf=i,exports.startOf=r;
1
+ const e=require("./_tz.cjs"),t=require("./_floor.cjs");var n={day:{days:1},hour:{hours:1},minute:{minutes:1},month:{months:1},week:{weeks:1},year:{years:1}};function r(n,r,i={}){let a=e.inferTimeZone(n,i);return t.floorToUnit(n,r,{timeZone:a,weekStartsOn:i.weekStartsOn}).toZonedDateTimeISO(a)}function i(r,i,a={}){let o=e.inferTimeZone(r,a);return t.floorToUnit(r,i,{timeZone:o,weekStartsOn:a.weekStartsOn}).toZonedDateTimeISO(o).add(n[i]).subtract({nanoseconds:1})}exports.endOf=i,exports.startOf=r;
2
2
  //# sourceMappingURL=boundary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":"wFAOA,IAAM,EAA6D,CACjE,IAAK,CAAE,KAAM,CAAE,EACf,KAAM,CAAE,MAAO,CAAE,EACjB,OAAQ,CAAE,QAAS,CAAE,EACrB,MAAO,CAAE,OAAQ,CAAE,EACnB,KAAM,CAAE,MAAO,CAAE,EACjB,KAAM,CAAE,MAAO,CAAE,CACnB,EAEA,SAAgB,EAAQ,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACnH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAE7C,OAAO,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CAC/G,CAEA,SAAgB,EAAM,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACjH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAG7C,OAFc,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,CAAE,YAAa,CAAE,CAAC,CAChG"}
1
+ {"version":3,"file":"boundary.cjs","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":"uDAKA,IAAM,EAA6D,CACjE,IAAK,CAAE,KAAM,CAAE,EACf,KAAM,CAAE,MAAO,CAAE,EACjB,OAAQ,CAAE,QAAS,CAAE,EACrB,MAAO,CAAE,OAAQ,CAAE,EACnB,KAAM,CAAE,MAAO,CAAE,EACjB,KAAM,CAAE,MAAO,CAAE,CACnB,EAEA,SAAgB,EAAQ,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACnH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAE7C,OAAO,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ,CAC/G,CAEA,SAAgB,EAAM,EAAkB,EAAoB,EAA2B,CAAC,EAA2B,CACjH,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAG7C,OAFc,EAAA,YAAY,EAAO,EAAM,CAAE,WAAU,aAAc,EAAQ,YAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,CAAE,YAAa,CAAE,CAAC,CAChG"}
@@ -1,4 +1,4 @@
1
- import { Temporal } from '@js-temporal/polyfill';
1
+ import type { Temporal } from '@js-temporal/polyfill';
2
2
  import type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';
3
3
  export declare function startOf(input: TimeInput, unit: BoundaryUnit, options?: BoundaryOptions): Temporal.ZonedDateTime;
4
4
  export declare function endOf(input: TimeInput, unit: BoundaryUnit, options?: BoundaryOptions): Temporal.ZonedDateTime;
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAcxE,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAInH;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAKjH"}
1
+ {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../src/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAWxE,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAInH;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAAC,aAAa,CAKjH"}
package/dist/boundary.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { inferTimeZone as e } from "./_tz.js";
2
2
  import { floorToUnit as t } from "./_floor.js";
3
- import "@js-temporal/polyfill";
4
3
  //#region src/boundary.ts
5
4
  var n = {
6
5
  day: { days: 1 },
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":";;;;AAOA,IAAM,IAA6D;CACjE,KAAK,EAAE,MAAM,EAAE;CACf,MAAM,EAAE,OAAO,EAAE;CACjB,QAAQ,EAAE,SAAS,EAAE;CACrB,OAAO,EAAE,QAAQ,EAAE;CACnB,MAAM,EAAE,OAAO,EAAE;CACjB,MAAM,EAAE,OAAO,EAAE;AACnB;AAEA,SAAgB,EAAQ,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACnH,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ;AAC/G;AAEA,SAAgB,EAAM,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACjH,IAAM,IAAW,EAAc,GAAO,CAAO;CAG7C,OAFc,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;AAChG"}
1
+ {"version":3,"file":"boundary.js","names":[],"sources":["../src/boundary.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { floorToUnit } from './_floor';\nimport { inferTimeZone } from './_tz';\nimport type { BoundaryOptions, BoundaryUnit, TimeInput } from './types';\n\nconst BOUNDARY_STEP: Record<BoundaryUnit, Temporal.DurationLike> = {\n day: { days: 1 },\n hour: { hours: 1 },\n minute: { minutes: 1 },\n month: { months: 1 },\n week: { weeks: 1 },\n year: { years: 1 },\n};\n\nexport function startOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn }).toZonedDateTimeISO(timeZone);\n}\n\nexport function endOf(input: TimeInput, unit: BoundaryUnit, options: BoundaryOptions = {}): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n const start = floorToUnit(input, unit, { timeZone, weekStartsOn: options.weekStartsOn });\n\n return start.toZonedDateTimeISO(timeZone).add(BOUNDARY_STEP[unit]).subtract({ nanoseconds: 1 });\n}\n"],"mappings":";;;AAKA,IAAM,IAA6D;CACjE,KAAK,EAAE,MAAM,EAAE;CACf,MAAM,EAAE,OAAO,EAAE;CACjB,QAAQ,EAAE,SAAS,EAAE;CACrB,OAAO,EAAE,QAAQ,EAAE;CACnB,MAAM,EAAE,OAAO,EAAE;CACjB,MAAM,EAAE,OAAO,EAAE;AACnB;AAEA,SAAgB,EAAQ,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACnH,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAAC,CAAC,CAAC,mBAAmB,CAAQ;AAC/G;AAEA,SAAgB,EAAM,GAAkB,GAAoB,IAA2B,CAAC,GAA2B;CACjH,IAAM,IAAW,EAAc,GAAO,CAAO;CAG7C,OAFc,EAAY,GAAO,GAAM;EAAE;EAAU,cAAc,EAAQ;CAAa,CAE/E,CAAA,CAAM,mBAAmB,CAAQ,CAAC,CAAC,IAAI,EAAc,EAAK,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;AAChG"}
@@ -1 +1 @@
1
- {"version":3,"file":"classify.cjs","names":[],"sources":["../src/classify.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type {\n ClassifyExpiryInput,\n FixedDuration,\n TimeDiffResult,\n TimeDiffUnit,\n TimeInput,\n TimeZoneOptions,\n} from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferSharedTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\n\nconst MILLIS = {\n day: 86_400_000,\n hour: 3_600_000,\n microsecond: 1 / 1_000,\n millisecond: 1,\n minute: 60_000,\n nanosecond: 1 / 1_000_000,\n second: 1_000,\n week: 604_800_000,\n} as const;\nconst UNIT_ORDER: ReadonlyArray<{ field: keyof Temporal.Duration; unit: TimeDiffUnit }> = [\n { field: 'years', unit: 'year' },\n { field: 'months', unit: 'month' },\n { field: 'weeks', unit: 'week' },\n { field: 'days', unit: 'day' },\n { field: 'hours', unit: 'hour' },\n { field: 'minutes', unit: 'minute' },\n { field: 'seconds', unit: 'second' },\n { field: 'milliseconds', unit: 'millisecond' },\n];\n\n// Expiry classification is elapsed-time math. Calendar months and years are rejected rather than approximated.\nfunction fixedDurationToMilliseconds(input: FixedDuration): number {\n const duration = Temporal.Duration.from(input);\n\n if (duration.years || duration.months) {\n throw new TempoInvalidInputError(\n 'classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.',\n );\n }\n\n return (\n duration.weeks * MILLIS.week +\n duration.days * MILLIS.day +\n duration.hours * MILLIS.hour +\n duration.minutes * MILLIS.minute +\n duration.seconds * MILLIS.second +\n duration.milliseconds +\n duration.microseconds * MILLIS.microsecond +\n duration.nanoseconds * MILLIS.nanosecond\n );\n}\n\nexport function classifyExpiry<K extends string>(input: ClassifyExpiryInput<K>): K | null {\n const reference = input.relativeTo ?? Temporal.Now.instant();\n const value = toInstant(input.value, input);\n const elapsed = value.epochMilliseconds - reference.epochMilliseconds;\n const thresholds = (Object.entries(input.thresholds) as Array<[K, FixedDuration]>)\n .map(([key, duration]) => ({ key, max: fixedDurationToMilliseconds(duration) }))\n .sort((left, right) => left.max - right.max);\n\n return thresholds.find(({ max }) => elapsed <= max)?.key ?? null;\n}\n\nfunction pickLargestUnit(duration: Temporal.Duration): TimeDiffResult {\n for (const { field, unit } of UNIT_ORDER) {\n const value = Math.abs(duration[field] as number);\n\n if (value > 0) return { unit, value };\n }\n\n return { unit: 'millisecond', value: 0 };\n}\n\nexport function timeDiff(\n a: TimeInput,\n b: TimeInput = Temporal.Now.instant(),\n options: TimeZoneOptions = {},\n): TimeDiffResult {\n if (!options.timeZone && a instanceof Temporal.Instant && b instanceof Temporal.Instant) {\n const left = a.toZonedDateTimeISO('UTC');\n const right = b.toZonedDateTimeISO('UTC');\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n }\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const left = toZoned(a, { timeZone });\n const right = toZoned(b, { timeZone });\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n}\n"],"mappings":"0HAeA,IAAM,EAAS,CACb,IAAK,MACL,KAAM,KACN,YAAa,EAAI,IACjB,YAAa,EACb,OAAQ,IACR,WAAY,EAAI,IAChB,OAAQ,IACR,KAAM,MACR,EACM,EAAoF,CACxF,CAAE,MAAO,QAAS,KAAM,MAAO,EAC/B,CAAE,MAAO,SAAU,KAAM,OAAQ,EACjC,CAAE,MAAO,QAAS,KAAM,MAAO,EAC/B,CAAE,MAAO,OAAQ,KAAM,KAAM,EAC7B,CAAE,MAAO,QAAS,KAAM,MAAO,EAC/B,CAAE,MAAO,UAAW,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AAmB,KAAK,EACjC,EAAQ,EAAE,mBAAmB,KAAK,EAExC,OAAO,EACL,EAAA,SAAS,cAAc,QAAQ,EAAM,CAAK,GAAK,EAC3C,EAAM,MAAM,EAAM,CAAE,YAAa,MAAO,CAAC,EACzC,EAAK,MAAM,EAAO,CAAE,YAAa,MAAO,CAAC,CAC/C,CACF,CAEA,IAAM,EAAW,EAAA,oBAAoB,CAAC,EAAG,CAAC,EAAG,CAAO,EAC9C,EAAO,EAAA,QAAQ,EAAG,CAAE,UAAS,CAAC,EAC9B,EAAQ,EAAA,QAAQ,EAAG,CAAE,UAAS,CAAC,EAErC,OAAO,EACL,EAAA,SAAS,cAAc,QAAQ,EAAM,CAAK,GAAK,EAC3C,EAAM,MAAM,EAAM,CAAE,YAAa,MAAO,CAAC,EACzC,EAAK,MAAM,EAAO,CAAE,YAAa,MAAO,CAAC,CAC/C,CACF"}
1
+ {"version":3,"file":"classify.cjs","names":[],"sources":["../src/classify.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant, toZoned } from './_convert';\nimport { inferSharedTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\nimport type {\n ClassifyExpiryInput,\n FixedDuration,\n TimeDiffResult,\n TimeDiffUnit,\n TimeInput,\n TimeZoneOptions,\n} from './types';\n\nconst MILLIS = {\n day: 86_400_000,\n hour: 3_600_000,\n microsecond: 1 / 1_000,\n millisecond: 1,\n minute: 60_000,\n nanosecond: 1 / 1_000_000,\n second: 1_000,\n week: 604_800_000,\n} as const;\nconst UNIT_ORDER: ReadonlyArray<{ field: keyof Temporal.Duration; unit: TimeDiffUnit }> = [\n { field: 'years', unit: 'year' },\n { field: 'months', unit: 'month' },\n { field: 'weeks', unit: 'week' },\n { field: 'days', unit: 'day' },\n { field: 'hours', unit: 'hour' },\n { field: 'minutes', unit: 'minute' },\n { field: 'seconds', unit: 'second' },\n { field: 'milliseconds', unit: 'millisecond' },\n];\n\n// Expiry classification is elapsed-time math. Calendar months and years are rejected rather than approximated.\nfunction fixedDurationToMilliseconds(input: FixedDuration): number {\n const duration = Temporal.Duration.from(input);\n\n if (duration.years || duration.months) {\n throw new TempoInvalidInputError(\n 'classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.',\n );\n }\n\n return (\n duration.weeks * MILLIS.week +\n duration.days * MILLIS.day +\n duration.hours * MILLIS.hour +\n duration.minutes * MILLIS.minute +\n duration.seconds * MILLIS.second +\n duration.milliseconds +\n duration.microseconds * MILLIS.microsecond +\n duration.nanoseconds * MILLIS.nanosecond\n );\n}\n\nexport function classifyExpiry<K extends string>(input: ClassifyExpiryInput<K>): K | null {\n const reference = input.relativeTo ?? Temporal.Now.instant();\n const value = toInstant(input.value, input);\n const elapsed = value.epochMilliseconds - reference.epochMilliseconds;\n const thresholds = (Object.entries(input.thresholds) as Array<[K, FixedDuration]>)\n .map(([key, duration]) => ({ key, max: fixedDurationToMilliseconds(duration) }))\n .sort((left, right) => left.max - right.max);\n\n return thresholds.find(({ max }) => elapsed <= max)?.key ?? null;\n}\n\nfunction pickLargestUnit(duration: Temporal.Duration): TimeDiffResult {\n for (const { field, unit } of UNIT_ORDER) {\n const value = Math.abs(duration[field] as number);\n\n if (value > 0) return { unit, value };\n }\n\n return { unit: 'millisecond', value: 0 };\n}\n\nexport function timeDiff(\n a: TimeInput,\n b: TimeInput = Temporal.Now.instant(),\n options: TimeZoneOptions = {},\n): TimeDiffResult {\n if (!options.timeZone && a instanceof Temporal.Instant && b instanceof Temporal.Instant) {\n const left = a.toZonedDateTimeISO('UTC');\n const right = b.toZonedDateTimeISO('UTC');\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n }\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const left = toZoned(a, { timeZone });\n const right = toZoned(b, { timeZone });\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right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,GAAG,CAAC,GAAG,IAAI,CASxF;AAYD,wBAAgB,QAAQ,CACtB,CAAC,EAAE,SAAS,EACZ,CAAC,GAAE,SAAkC,EACrC,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAqBhB"}
1
+ {"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,mBAAmB,EAEnB,cAAc,EAEd,SAAS,EACT,eAAe,EAChB,MAAM,SAAS,CAAC;AA6CjB,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CASxF;AAYD,wBAAgB,QAAQ,CACtB,CAAC,EAAE,SAAS,EACZ,CAAC,GAAE,SAAkC,EACrC,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAqBhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"classify.js","names":[],"sources":["../src/classify.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type {\n ClassifyExpiryInput,\n FixedDuration,\n TimeDiffResult,\n TimeDiffUnit,\n TimeInput,\n TimeZoneOptions,\n} from './types';\n\nimport { toInstant, toZoned } from './_convert';\nimport { inferSharedTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\n\nconst MILLIS = {\n day: 86_400_000,\n hour: 3_600_000,\n microsecond: 1 / 1_000,\n millisecond: 1,\n minute: 60_000,\n nanosecond: 1 / 1_000_000,\n second: 1_000,\n week: 604_800_000,\n} as const;\nconst UNIT_ORDER: ReadonlyArray<{ field: keyof Temporal.Duration; unit: TimeDiffUnit }> = [\n { field: 'years', unit: 'year' },\n { field: 'months', unit: 'month' },\n { field: 'weeks', unit: 'week' },\n { field: 'days', unit: 'day' },\n { field: 'hours', unit: 'hour' },\n { field: 'minutes', unit: 'minute' },\n { field: 'seconds', unit: 'second' },\n { field: 'milliseconds', unit: 'millisecond' },\n];\n\n// Expiry classification is elapsed-time math. Calendar months and years are rejected rather than approximated.\nfunction fixedDurationToMilliseconds(input: FixedDuration): number {\n const duration = Temporal.Duration.from(input);\n\n if (duration.years || duration.months) {\n throw new TempoInvalidInputError(\n 'classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.',\n );\n }\n\n return (\n duration.weeks * MILLIS.week +\n duration.days * MILLIS.day +\n duration.hours * MILLIS.hour +\n duration.minutes * MILLIS.minute +\n duration.seconds * MILLIS.second +\n duration.milliseconds +\n duration.microseconds * MILLIS.microsecond +\n duration.nanoseconds * MILLIS.nanosecond\n );\n}\n\nexport function classifyExpiry<K extends string>(input: ClassifyExpiryInput<K>): K | null {\n const reference = input.relativeTo ?? Temporal.Now.instant();\n const value = toInstant(input.value, input);\n const elapsed = value.epochMilliseconds - reference.epochMilliseconds;\n const thresholds = (Object.entries(input.thresholds) as Array<[K, FixedDuration]>)\n .map(([key, duration]) => ({ key, max: fixedDurationToMilliseconds(duration) }))\n .sort((left, right) => left.max - right.max);\n\n return thresholds.find(({ max }) => elapsed <= max)?.key ?? null;\n}\n\nfunction pickLargestUnit(duration: Temporal.Duration): TimeDiffResult {\n for (const { field, unit } of UNIT_ORDER) {\n const value = Math.abs(duration[field] as number);\n\n if (value > 0) return { unit, value };\n }\n\n return { unit: 'millisecond', value: 0 };\n}\n\nexport function timeDiff(\n a: TimeInput,\n b: TimeInput = Temporal.Now.instant(),\n options: TimeZoneOptions = {},\n): TimeDiffResult {\n if (!options.timeZone && a instanceof Temporal.Instant && b instanceof Temporal.Instant) {\n const left = a.toZonedDateTimeISO('UTC');\n const right = b.toZonedDateTimeISO('UTC');\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n }\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const left = toZoned(a, { timeZone });\n const right = toZoned(b, { timeZone });\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(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AAC9D;AAEA,SAAS,EAAgB,GAA6C;CACpE,KAAK,IAAM,EAAE,UAAO,aAAU,GAAY;EACxC,IAAM,IAAQ,KAAK,IAAI,EAAS,EAAgB;EAEhD,IAAI,IAAQ,GAAG,OAAO;GAAE;GAAM;EAAM;CACtC;CAEA,OAAO;EAAE,MAAM;EAAe,OAAO;CAAE;AACzC;AAEA,SAAgB,EACd,GACA,IAAe,EAAS,IAAI,QAAQ,GACpC,IAA2B,CAAC,GACZ;CAChB,IAAI,CAAC,EAAQ,YAAY,aAAa,EAAS,WAAW,aAAa,EAAS,SAAS;EACvF,IAAM,IAAO,EAAE,mBAAmB,KAAK,GACjC,IAAQ,EAAE,mBAAmB,KAAK;EAExC,OAAO,EACL,EAAS,cAAc,QAAQ,GAAM,CAAK,KAAK,IAC3C,EAAM,MAAM,GAAM,EAAE,aAAa,OAAO,CAAC,IACzC,EAAK,MAAM,GAAO,EAAE,aAAa,OAAO,CAAC,CAC/C;CACF;CAEA,IAAM,IAAW,EAAoB,CAAC,GAAG,CAAC,GAAG,CAAO,GAC9C,IAAO,EAAQ,GAAG,EAAE,YAAS,CAAC,GAC9B,IAAQ,EAAQ,GAAG,EAAE,YAAS,CAAC;CAErC,OAAO,EACL,EAAS,cAAc,QAAQ,GAAM,CAAK,KAAK,IAC3C,EAAM,MAAM,GAAM,EAAE,aAAa,OAAO,CAAC,IACzC,EAAK,MAAM,GAAO,EAAE,aAAa,OAAO,CAAC,CAC/C;AACF"}
1
+ {"version":3,"file":"classify.js","names":[],"sources":["../src/classify.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant, toZoned } from './_convert';\nimport { inferSharedTimeZone } from './_tz';\nimport { TempoInvalidInputError } from './errors';\nimport type {\n ClassifyExpiryInput,\n FixedDuration,\n TimeDiffResult,\n TimeDiffUnit,\n TimeInput,\n TimeZoneOptions,\n} from './types';\n\nconst MILLIS = {\n day: 86_400_000,\n hour: 3_600_000,\n microsecond: 1 / 1_000,\n millisecond: 1,\n minute: 60_000,\n nanosecond: 1 / 1_000_000,\n second: 1_000,\n week: 604_800_000,\n} as const;\nconst UNIT_ORDER: ReadonlyArray<{ field: keyof Temporal.Duration; unit: TimeDiffUnit }> = [\n { field: 'years', unit: 'year' },\n { field: 'months', unit: 'month' },\n { field: 'weeks', unit: 'week' },\n { field: 'days', unit: 'day' },\n { field: 'hours', unit: 'hour' },\n { field: 'minutes', unit: 'minute' },\n { field: 'seconds', unit: 'second' },\n { field: 'milliseconds', unit: 'millisecond' },\n];\n\n// Expiry classification is elapsed-time math. Calendar months and years are rejected rather than approximated.\nfunction fixedDurationToMilliseconds(input: FixedDuration): number {\n const duration = Temporal.Duration.from(input);\n\n if (duration.years || duration.months) {\n throw new TempoInvalidInputError(\n 'classifyExpiry thresholds cannot contain months or years. Use fixed elapsed-time units.',\n );\n }\n\n return (\n duration.weeks * MILLIS.week +\n duration.days * MILLIS.day +\n duration.hours * MILLIS.hour +\n duration.minutes * MILLIS.minute +\n duration.seconds * MILLIS.second +\n duration.milliseconds +\n duration.microseconds * MILLIS.microsecond +\n duration.nanoseconds * MILLIS.nanosecond\n );\n}\n\nexport function classifyExpiry<K extends string>(input: ClassifyExpiryInput<K>): K | null {\n const reference = input.relativeTo ?? Temporal.Now.instant();\n const value = toInstant(input.value, input);\n const elapsed = value.epochMilliseconds - reference.epochMilliseconds;\n const thresholds = (Object.entries(input.thresholds) as Array<[K, FixedDuration]>)\n .map(([key, duration]) => ({ key, max: fixedDurationToMilliseconds(duration) }))\n .sort((left, right) => left.max - right.max);\n\n return thresholds.find(({ max }) => elapsed <= max)?.key ?? null;\n}\n\nfunction pickLargestUnit(duration: Temporal.Duration): TimeDiffResult {\n for (const { field, unit } of UNIT_ORDER) {\n const value = Math.abs(duration[field] as number);\n\n if (value > 0) return { unit, value };\n }\n\n return { unit: 'millisecond', value: 0 };\n}\n\nexport function timeDiff(\n a: TimeInput,\n b: TimeInput = Temporal.Now.instant(),\n options: TimeZoneOptions = {},\n): TimeDiffResult {\n if (!options.timeZone && a instanceof Temporal.Instant && b instanceof Temporal.Instant) {\n const left = a.toZonedDateTimeISO('UTC');\n const right = b.toZonedDateTimeISO('UTC');\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n }\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const left = toZoned(a, { timeZone });\n const right = toZoned(b, { timeZone });\n\n return pickLargestUnit(\n Temporal.ZonedDateTime.compare(left, right) <= 0\n ? right.since(left, { largestUnit: 'year' })\n : left.since(right, { largestUnit: 'year' }),\n );\n}\n"],"mappings":";;;;;AAaA,IAAM,IAAS;CACb,KAAK;CACL,MAAM;CACN,aAAa,IAAI;CACjB,aAAa;CACb,QAAQ;CACR,YAAY,IAAI;CAChB,QAAQ;CACR,MAAM;AACR,GACM,IAAoF;CACxF;EAAE,OAAO;EAAS,MAAM;CAAO;CAC/B;EAAE,OAAO;EAAU,MAAM;CAAQ;CACjC;EAAE,OAAO;EAAS,MAAM;CAAO;CAC/B;EAAE,OAAO;EAAQ,MAAM;CAAM;CAC7B;EAAE,OAAO;EAAS,MAAM;CAAO;CAC/B;EAAE,OAAO;EAAW,MAAM;CAAS;CACnC;EAAE,OAAO;EAAW,MAAM;CAAS;CACnC;EAAE,OAAO;EAAgB,MAAM;CAAc;AAC/C;AAGA,SAAS,EAA4B,GAA8B;CACjE,IAAM,IAAW,EAAS,SAAS,KAAK,CAAK;CAE7C,IAAI,EAAS,SAAS,EAAS,QAC7B,MAAM,IAAI,EACR,yFACF;CAGF,OACE,EAAS,QAAQ,EAAO,OACxB,EAAS,OAAO,EAAO,MACvB,EAAS,QAAQ,EAAO,OACxB,EAAS,UAAU,EAAO,SAC1B,EAAS,UAAU,EAAO,SAC1B,EAAS,eACT,EAAS,eAAe,EAAO,cAC/B,EAAS,cAAc,EAAO;AAElC;AAEA,SAAgB,EAAiC,GAAyC;CACxF,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AO,CAAC,CAC/C;AACF"}
package/dist/compare.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./_tz.cjs"),t=require("./_convert.cjs"),n=require("./_floor.cjs");let r=require("@js-temporal/polyfill");function i(i,a,o){if(!o.unit)return r.Temporal.Instant.compare(t.toInstant(i,o),t.toInstant(a,o));let s={timeZone:e.inferSharedTimeZone([i,a],o),weekStartsOn:o.weekStartsOn};return r.Temporal.Instant.compare(n.floorToUnit(i,o.unit,s),n.floorToUnit(a,o.unit,s))}function a({end:r,start:i,value:a,...o}){if(!o.unit){let n=t.toInstant(a,o),[s,c]=e.normalizeRange(t.toInstant(i,o),t.toInstant(r,o));return{lower:s,target:n,upper:c}}let s={timeZone:e.inferSharedTimeZone([a,i,r],o),weekStartsOn:o.weekStartsOn},c=n.floorToUnit(a,o.unit,s),[l,u]=e.normalizeRange(n.floorToUnit(i,o.unit,s),n.floorToUnit(r,o.unit,s));return{lower:l,target:c,upper:u}}function o(e,t,n={}){return i(e,t,n)<0}function s(e,t,n={}){return i(e,t,n)>0}function c(e,t,n={}){return i(e,t,n)===0}function l(e){let{lower:t,target:n,upper:i}=a(e);return r.Temporal.Instant.compare(t,n)<=0&&r.Temporal.Instant.compare(n,i)<=0}function u(e){let{lower:t,target:n,upper:i}=a(e),o=r.Temporal.Instant.compare(n,t)<0?t:r.Temporal.Instant.compare(n,i)>0?i:n;return e.value instanceof r.Temporal.ZonedDateTime?o.toZonedDateTimeISO(e.timeZone??e.value.timeZoneId):o}exports.clamp=u,exports.contains=l,exports.isAfter=s,exports.isBefore=o,exports.isSame=c;
1
+ const e=require("./_tz.cjs"),t=require("./_convert.cjs"),n=require("./_floor.cjs");let r=require("@js-temporal/polyfill");function i(e,t){return r.Temporal.Instant.compare(e,t)<=0?[e,t]:[t,e]}function a(i,a,o){if(!o.unit)return r.Temporal.Instant.compare(t.toInstant(i,o),t.toInstant(a,o));let s={timeZone:e.inferSharedTimeZone([i,a],o),weekStartsOn:o.weekStartsOn};return r.Temporal.Instant.compare(n.floorToUnit(i,o.unit,s),n.floorToUnit(a,o.unit,s))}function o({end:r,start:a,value:o,...s}){if(!s.unit){let e=t.toInstant(o,s),[n,c]=i(t.toInstant(a,s),t.toInstant(r,s));return{lower:n,target:e,upper:c}}let c={timeZone:e.inferSharedTimeZone([o,a,r],s),weekStartsOn:s.weekStartsOn},l=n.floorToUnit(o,s.unit,c),[u,d]=i(n.floorToUnit(a,s.unit,c),n.floorToUnit(r,s.unit,c));return{lower:u,target:l,upper:d}}function s(e,t,n={}){return a(e,t,n)<0}function c(e,t,n={}){return a(e,t,n)>0}function l(e,t,n={}){return a(e,t,n)===0}function u(e){let{lower:t,target:n,upper:i}=o(e);return r.Temporal.Instant.compare(t,n)<=0&&r.Temporal.Instant.compare(n,i)<=0}function d(e){let{lower:t,target:n,upper:i}=o(e),a=r.Temporal.Instant.compare(n,t)<0?t:r.Temporal.Instant.compare(n,i)>0?i:n;return e.value instanceof r.Temporal.ZonedDateTime?a.toZonedDateTimeISO(e.timeZone??e.value.timeZoneId):a}exports.clamp=d,exports.contains=u,exports.isAfter=c,exports.isBefore=s,exports.isSame=l;
2
2
  //# sourceMappingURL=compare.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"compare.cjs","names":[],"sources":["../src/compare.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { ClampInput, ContainsInput, CompareOptions, TimeInput } from './types';\n\nimport { toInstant } from './_convert';\nimport { floorToUnit } from './_floor';\nimport { inferSharedTimeZone, normalizeRange } from './_tz';\n\nfunction compareByUnit(a: TimeInput, b: TimeInput, options: CompareOptions): number {\n if (!options.unit) return Temporal.Instant.compare(toInstant(a, options), toInstant(b, options));\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n\n return Temporal.Instant.compare(floorToUnit(a, options.unit, unitOptions), floorToUnit(b, options.unit, unitOptions));\n}\n\nfunction resolveRange({ end, start, value, ...options }: ContainsInput | ClampInput): {\n lower: Temporal.Instant;\n target: Temporal.Instant;\n upper: Temporal.Instant;\n} {\n if (!options.unit) {\n const target = toInstant(value, options);\n const [lower, upper] = normalizeRange(toInstant(start, options), toInstant(end, options));\n\n return { lower, target, upper };\n }\n\n const timeZone = inferSharedTimeZone([value, start, end], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n const target = floorToUnit(value, options.unit, unitOptions);\n const [lower, upper] = normalizeRange(\n floorToUnit(start, options.unit, unitOptions),\n floorToUnit(end, options.unit, unitOptions),\n );\n\n return { lower, target, upper };\n}\n\nexport function isBefore(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) < 0;\n}\n\nexport function isAfter(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) > 0;\n}\n\nexport function isSame(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) === 0;\n}\n\nexport function contains(input: ContainsInput): boolean {\n const { lower, target, upper } = resolveRange(input);\n\n return Temporal.Instant.compare(lower, target) <= 0 && Temporal.Instant.compare(target, upper) <= 0;\n}\n\nexport function clamp(input: ClampInput & { value: Temporal.ZonedDateTime }): Temporal.ZonedDateTime;\nexport function clamp(input: ClampInput): Temporal.Instant;\nexport function clamp(input: ClampInput): Temporal.Instant | Temporal.ZonedDateTime {\n const { lower, target, upper } = resolveRange(input);\n const clamped =\n Temporal.Instant.compare(target, lower) < 0 ? lower : Temporal.Instant.compare(target, upper) > 0 ? upper : target;\n\n return input.value instanceof Temporal.ZonedDateTime\n ? clamped.toZonedDateTimeISO(input.timeZone ?? input.value.timeZoneId)\n : clamped;\n}\n"],"mappings":"0HAQA,SAAS,EAAc,EAAc,EAAc,EAAiC,CAClF,GAAI,CAAC,EAAQ,KAAM,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAA,UAAU,EAAG,CAAO,EAAG,EAAA,UAAU,EAAG,CAAO,CAAC,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AAQ,EAAO,CAAM,GAAK,GAAK,EAAA,SAAS,QAAQ,QAAQ,EAAQ,CAAK,GAAK,CACpG,CAIA,SAAgB,EAAM,EAA8D,CAClF,GAAM,CAAE,QAAO,SAAQ,SAAU,EAAa,CAAK,EAC7C,EACJ,EAAA,SAAS,QAAQ,QAAQ,EAAQ,CAAK,EAAI,EAAI,EAAQ,EAAA,SAAS,QAAQ,QAAQ,EAAQ,CAAK,EAAI,EAAI,EAAQ,EAE9G,OAAO,EAAM,iBAAiB,EAAA,SAAS,cACnC,EAAQ,mBAAmB,EAAM,UAAY,EAAM,MAAM,UAAU,EACnE,CACN"}
1
+ {"version":3,"file":"compare.cjs","names":[],"sources":["../src/compare.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant } from './_convert';\nimport { floorToUnit } from './_floor';\nimport { inferSharedTimeZone } from './_tz';\nimport type { ClampInput, CompareOptions, ContainsInput, TimeInput } from './types';\n\nfunction normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nfunction compareByUnit(a: TimeInput, b: TimeInput, options: CompareOptions): number {\n if (!options.unit) return Temporal.Instant.compare(toInstant(a, options), toInstant(b, options));\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n\n return Temporal.Instant.compare(floorToUnit(a, options.unit, unitOptions), floorToUnit(b, options.unit, unitOptions));\n}\n\nfunction resolveRange({ end, start, value, ...options }: ContainsInput | ClampInput): {\n lower: Temporal.Instant;\n target: Temporal.Instant;\n upper: Temporal.Instant;\n} {\n if (!options.unit) {\n const target = toInstant(value, options);\n const [lower, upper] = normalizeRange(toInstant(start, options), toInstant(end, options));\n\n return { lower, target, upper };\n }\n\n const timeZone = inferSharedTimeZone([value, start, end], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n const target = floorToUnit(value, options.unit, unitOptions);\n const [lower, upper] = normalizeRange(\n floorToUnit(start, options.unit, unitOptions),\n floorToUnit(end, options.unit, unitOptions),\n );\n\n return { lower, target, upper };\n}\n\nexport function isBefore(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) < 0;\n}\n\nexport function isAfter(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) > 0;\n}\n\nexport function isSame(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) === 0;\n}\n\nexport function contains(input: ContainsInput): boolean {\n const { lower, target, upper } = resolveRange(input);\n\n return Temporal.Instant.compare(lower, target) <= 0 && Temporal.Instant.compare(target, upper) <= 0;\n}\n\nexport function clamp(input: ClampInput & { value: Temporal.ZonedDateTime }): Temporal.ZonedDateTime;\nexport function clamp(input: ClampInput): Temporal.Instant;\nexport function clamp(input: ClampInput): Temporal.Instant | Temporal.ZonedDateTime {\n const { lower, target, upper } = resolveRange(input);\n const clamped =\n Temporal.Instant.compare(target, lower) < 0 ? lower : Temporal.Instant.compare(target, upper) > 0 ? upper : target;\n\n return input.value instanceof Temporal.ZonedDateTime\n ? clamped.toZonedDateTimeISO(input.timeZone ?? input.value.timeZoneId)\n : clamped;\n}\n"],"mappings":"0HAMA,SAAS,EAAe,EAAyB,EAA6D,CAC5G,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAO,CAAG,GAAK,EAAI,CAAC,EAAO,CAAG,EAAI,CAAC,EAAK,CAAK,CAC/E,CAEA,SAAS,EAAc,EAAc,EAAc,EAAiC,CAClF,GAAI,CAAC,EAAQ,KAAM,OAAO,EAAA,SAAS,QAAQ,QAAQ,EAAA,UAAU,EAAG,CAAO,EAAG,EAAA,UAAU,EAAG,CAAO,CAAC,EAG/F,IAAM,EAAc,CAAE,SADL,EAAA,oBAAoB,CAAC,EAAG,CAAC,EAAG,CACvB,EAAU,aAAc,EAAQ,YAAa,EAEnE,OA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AAE,QAAO,SAAQ,SAAU,EAAa,CAAK,EAC7C,EACJ,EAAA,SAAS,QAAQ,QAAQ,EAAQ,CAAK,EAAI,EAAI,EAAQ,EAAA,SAAS,QAAQ,QAAQ,EAAQ,CAAK,EAAI,EAAI,EAAQ,EAE9G,OAAO,EAAM,iBAAiB,EAAA,SAAS,cACnC,EAAQ,mBAAmB,EAAM,UAAY,EAAM,MAAM,UAAU,EACnE,CACN"}
package/dist/compare.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import type { ClampInput, ContainsInput, CompareOptions, TimeInput } from './types';
2
+ import type { ClampInput, CompareOptions, ContainsInput, TimeInput } from './types';
3
3
  export declare function isBefore(a: TimeInput, b: TimeInput, options?: CompareOptions): boolean;
4
4
  export declare function isAfter(a: TimeInput, b: TimeInput, options?: CompareOptions): boolean;
5
5
  export declare function isSame(a: TimeInput, b: TimeInput, options?: CompareOptions): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAsCpF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAE1F;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAEzF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAExF;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAItD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAA;CAAE,GAAG,QAAQ,CAAC,aAAa,CAAC;AACrG,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC"}
1
+ {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAsCpF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAE1F;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAEzF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAExF;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAItD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAA;CAAE,GAAG,QAAQ,CAAC,aAAa,CAAC;AACrG,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC"}
package/dist/compare.js CHANGED
@@ -1,21 +1,24 @@
1
- import { inferSharedTimeZone as e, normalizeRange as t } from "./_tz.js";
2
- import { toInstant as n } from "./_convert.js";
3
- import { floorToUnit as r } from "./_floor.js";
4
- import { Temporal as i } from "@js-temporal/polyfill";
1
+ import { inferSharedTimeZone as e } from "./_tz.js";
2
+ import { toInstant as t } from "./_convert.js";
3
+ import { floorToUnit as n } from "./_floor.js";
4
+ import { Temporal as r } from "@js-temporal/polyfill";
5
5
  //#region src/compare.ts
6
- function a(t, a, o) {
7
- if (!o.unit) return i.Instant.compare(n(t, o), n(a, o));
6
+ function i(e, t) {
7
+ return r.Instant.compare(e, t) <= 0 ? [e, t] : [t, e];
8
+ }
9
+ function a(i, a, o) {
10
+ if (!o.unit) return r.Instant.compare(t(i, o), t(a, o));
8
11
  let s = {
9
- timeZone: e([t, a], o),
12
+ timeZone: e([i, a], o),
10
13
  weekStartsOn: o.weekStartsOn
11
14
  };
12
- return i.Instant.compare(r(t, o.unit, s), r(a, o.unit, s));
15
+ return r.Instant.compare(n(i, o.unit, s), n(a, o.unit, s));
13
16
  }
14
- function o({ end: i, start: a, value: o, ...s }) {
17
+ function o({ end: r, start: a, value: o, ...s }) {
15
18
  if (!s.unit) {
16
- let e = n(o, s), [r, c] = t(n(a, s), n(i, s));
19
+ let e = t(o, s), [n, c] = i(t(a, s), t(r, s));
17
20
  return {
18
- lower: r,
21
+ lower: n,
19
22
  target: e,
20
23
  upper: c
21
24
  };
@@ -24,10 +27,10 @@ function o({ end: i, start: a, value: o, ...s }) {
24
27
  timeZone: e([
25
28
  o,
26
29
  a,
27
- i
30
+ r
28
31
  ], s),
29
32
  weekStartsOn: s.weekStartsOn
30
- }, l = r(o, s.unit, c), [u, d] = t(r(a, s.unit, c), r(i, s.unit, c));
33
+ }, l = n(o, s.unit, c), [u, d] = i(n(a, s.unit, c), n(r, s.unit, c));
31
34
  return {
32
35
  lower: u,
33
36
  target: l,
@@ -44,12 +47,12 @@ function l(e, t, n = {}) {
44
47
  return a(e, t, n) === 0;
45
48
  }
46
49
  function u(e) {
47
- let { lower: t, target: n, upper: r } = o(e);
48
- return i.Instant.compare(t, n) <= 0 && i.Instant.compare(n, r) <= 0;
50
+ let { lower: t, target: n, upper: i } = o(e);
51
+ return r.Instant.compare(t, n) <= 0 && r.Instant.compare(n, i) <= 0;
49
52
  }
50
53
  function d(e) {
51
- let { lower: t, target: n, upper: r } = o(e), a = i.Instant.compare(n, t) < 0 ? t : i.Instant.compare(n, r) > 0 ? r : n;
52
- return e.value instanceof i.ZonedDateTime ? a.toZonedDateTimeISO(e.timeZone ?? e.value.timeZoneId) : a;
54
+ let { lower: t, target: n, upper: i } = o(e), a = r.Instant.compare(n, t) < 0 ? t : r.Instant.compare(n, i) > 0 ? i : n;
55
+ return e.value instanceof r.ZonedDateTime ? a.toZonedDateTimeISO(e.timeZone ?? e.value.timeZoneId) : a;
53
56
  }
54
57
  //#endregion
55
58
  export { d as clamp, u as contains, c as isAfter, s as isBefore, l as isSame };
@@ -1 +1 @@
1
- {"version":3,"file":"compare.js","names":[],"sources":["../src/compare.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { ClampInput, ContainsInput, CompareOptions, TimeInput } from './types';\n\nimport { toInstant } from './_convert';\nimport { floorToUnit } from './_floor';\nimport { inferSharedTimeZone, normalizeRange } from './_tz';\n\nfunction compareByUnit(a: TimeInput, b: TimeInput, options: CompareOptions): number {\n if (!options.unit) return Temporal.Instant.compare(toInstant(a, options), toInstant(b, options));\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n\n return Temporal.Instant.compare(floorToUnit(a, options.unit, unitOptions), floorToUnit(b, options.unit, unitOptions));\n}\n\nfunction resolveRange({ end, start, value, ...options }: ContainsInput | ClampInput): {\n lower: Temporal.Instant;\n target: Temporal.Instant;\n upper: Temporal.Instant;\n} {\n if (!options.unit) {\n const target = toInstant(value, options);\n const [lower, upper] = normalizeRange(toInstant(start, options), toInstant(end, options));\n\n return { lower, target, upper };\n }\n\n const timeZone = inferSharedTimeZone([value, start, end], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n const target = floorToUnit(value, options.unit, unitOptions);\n const [lower, upper] = normalizeRange(\n floorToUnit(start, options.unit, unitOptions),\n floorToUnit(end, options.unit, unitOptions),\n );\n\n return { lower, target, upper };\n}\n\nexport function isBefore(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) < 0;\n}\n\nexport function isAfter(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) > 0;\n}\n\nexport function isSame(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) === 0;\n}\n\nexport function contains(input: ContainsInput): boolean {\n const { lower, target, upper } = resolveRange(input);\n\n return Temporal.Instant.compare(lower, target) <= 0 && Temporal.Instant.compare(target, upper) <= 0;\n}\n\nexport function clamp(input: ClampInput & { value: Temporal.ZonedDateTime }): Temporal.ZonedDateTime;\nexport function clamp(input: ClampInput): Temporal.Instant;\nexport function clamp(input: ClampInput): Temporal.Instant | Temporal.ZonedDateTime {\n const { lower, target, upper } = resolveRange(input);\n const clamped =\n Temporal.Instant.compare(target, lower) < 0 ? lower : Temporal.Instant.compare(target, upper) > 0 ? upper : target;\n\n return input.value instanceof Temporal.ZonedDateTime\n ? clamped.toZonedDateTimeISO(input.timeZone ?? input.value.timeZoneId)\n : clamped;\n}\n"],"mappings":";;;;;AAQA,SAAS,EAAc,GAAc,GAAc,GAAiC;CAClF,IAAI,CAAC,EAAQ,MAAM,OAAO,EAAS,QAAQ,QAAQ,EAAU,GAAG,CAAO,GAAG,EAAU,GAAG,CAAO,CAAC;CAG/F,IAAM,IAAc;EAAE,UADL,EAAoB,CAAC,GAAG,CAAC,GAAG,CACvB;EAAU,cAAc,EAAQ;CAAa;CAEnE,OAAO,EAAS,QAAQ,QAAQ,EAAY,GAAG,EAAQ,MAAM,CAAW,GAAG,EAAY,GAAG,EAAQ,MAAM,CAAW,CAAC;AACtH;AAEA,SAAS,EAAa,EAAE,QAAK,UAAO,UAAO,GAAG,KAI5C;CACA,IAAI,CAAC,EAAQ,MAAM;EACjB,IAAM,IAAS,EAAU,GAAO,CAAO,GACjC,CAAC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["import { Temporal } from '@js-temporal/polyfill';\nimport { toInstant } from './_convert';\nimport { floorToUnit } from './_floor';\nimport { inferSharedTimeZone } from './_tz';\nimport type { ClampInput, CompareOptions, ContainsInput, TimeInput } from './types';\n\nfunction normalizeRange(start: Temporal.Instant, end: Temporal.Instant): [Temporal.Instant, Temporal.Instant] {\n return Temporal.Instant.compare(start, end) <= 0 ? [start, end] : [end, start];\n}\n\nfunction compareByUnit(a: TimeInput, b: TimeInput, options: CompareOptions): number {\n if (!options.unit) return Temporal.Instant.compare(toInstant(a, options), toInstant(b, options));\n\n const timeZone = inferSharedTimeZone([a, b], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n\n return Temporal.Instant.compare(floorToUnit(a, options.unit, unitOptions), floorToUnit(b, options.unit, unitOptions));\n}\n\nfunction resolveRange({ end, start, value, ...options }: ContainsInput | ClampInput): {\n lower: Temporal.Instant;\n target: Temporal.Instant;\n upper: Temporal.Instant;\n} {\n if (!options.unit) {\n const target = toInstant(value, options);\n const [lower, upper] = normalizeRange(toInstant(start, options), toInstant(end, options));\n\n return { lower, target, upper };\n }\n\n const timeZone = inferSharedTimeZone([value, start, end], options);\n const unitOptions = { timeZone, weekStartsOn: options.weekStartsOn };\n const target = floorToUnit(value, options.unit, unitOptions);\n const [lower, upper] = normalizeRange(\n floorToUnit(start, options.unit, unitOptions),\n floorToUnit(end, options.unit, unitOptions),\n );\n\n return { lower, target, upper };\n}\n\nexport function isBefore(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) < 0;\n}\n\nexport function isAfter(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) > 0;\n}\n\nexport function isSame(a: TimeInput, b: TimeInput, options: CompareOptions = {}): boolean {\n return compareByUnit(a, b, options) === 0;\n}\n\nexport function contains(input: ContainsInput): boolean {\n const { lower, target, upper } = resolveRange(input);\n\n return Temporal.Instant.compare(lower, target) <= 0 && Temporal.Instant.compare(target, upper) <= 0;\n}\n\nexport function clamp(input: ClampInput & { value: Temporal.ZonedDateTime }): Temporal.ZonedDateTime;\nexport function clamp(input: ClampInput): Temporal.Instant;\nexport function clamp(input: ClampInput): Temporal.Instant | Temporal.ZonedDateTime {\n const { lower, target, upper } = resolveRange(input);\n const clamped =\n Temporal.Instant.compare(target, lower) < 0 ? lower : Temporal.Instant.compare(target, upper) > 0 ? upper : target;\n\n return input.value instanceof Temporal.ZonedDateTime\n ? clamped.toZonedDateTimeISO(input.timeZone ?? input.value.timeZoneId)\n : clamped;\n}\n"],"mappings":";;;;;AAMA,SAAS,EAAe,GAAyB,GAA6D;CAC5G,OAAO,EAAS,QAAQ,QAAQ,GAAO,CAAG,KAAK,IAAI,CAAC,GAAO,CAAG,IAAI,CAAC,GAAK,CAAK;AAC/E;AAEA,SAAS,EAAc,GAAc,GAAc,GAAiC;CAClF,IAAI,CAAC,EAAQ,MAAM,OAAO,EAAS,QAAQ,QAAQ,EAAU,GAAG,CAAO,GAAG,EAAU,GAAG,CAAO,CAAC;CAG/F,IAAM,IAAc;EAAE,UADL,EAAoB,CAAC,GAAG,CAAC,GAAG,CACvB;EAAU,cAAc,EAAQ;CAAa;CAEnE,OAAO,EAAS,QAAQ,QAAQ,EAAY,GAAG,EAAQ,MAAM,CAAW,GAAG,EAAY,GAAG,EAAQ,MAAM,CAAW,CAAC;AACtH;AAEA,SAAS,EAAa,EAAE,QAAK,UAAO,UAAO,GAAG,KAI5C;CACA,IAAI,CAAC,EAAQ,MAAM;EACjB,IAAM,IAAS,EAAU,GAAO,CAAO,GACjC,CAAC,GAAO,KAAS,EAAe,EAAU,GAAO,CAAO,GAAG,EAAU,GAAK,CAAO,CAAC;EAExF,OAAO;GAAE;GAAO;GAAQ;EAAM;CAChC;CAGA,IAAM,IAAc;EAAE,UADL,EAAoB;GAAC;GAAO;GAAO;EAAG,GAAG,CACpC;EAAU,cAAc,EAAQ;CAAa,GAC7D,IAAS,EAAY,GAAO,EAAQ,MAAM,CAAW,GACrD,CAAC,GAAO,KAAS,EACrB,EAAY,GAAO,EAAQ,MAAM,CAAW,GAC5C,EAAY,GAAK,EAAQ,MAAM,CAAW,CAC5C;CAEA,OAAO;EAAE;EAAO;EAAQ;CAAM;AAChC;AAEA,SAAgB,EAAS,GAAc,GAAc,IAA0B,CAAC,GAAY;CAC1F,OAAO,EAAc,GAAG,GAAG,CAAO,IAAI;AACxC;AAEA,SAAgB,EAAQ,GAAc,GAAc,IAA0B,CAAC,GAAY;CACzF,OAAO,EAAc,GAAG,GAAG,CAAO,IAAI;AACxC;AAEA,SAAgB,EAAO,GAAc,GAAc,IAA0B,CAAC,GAAY;CACxF,OAAO,EAAc,GAAG,GAAG,CAAO,MAAM;AAC1C;AAEA,SAAgB,EAAS,GAA+B;CACtD,IAAM,EAAE,UAAO,WAAQ,aAAU,EAAa,CAAK;CAEnD,OAAO,EAAS,QAAQ,QAAQ,GAAO,CAAM,KAAK,KAAK,EAAS,QAAQ,QAAQ,GAAQ,CAAK,KAAK;AACpG;AAIA,SAAgB,EAAM,GAA8D;CAClF,IAAM,EAAE,UAAO,WAAQ,aAAU,EAAa,CAAK,GAC7C,IACJ,EAAS,QAAQ,QAAQ,GAAQ,CAAK,IAAI,IAAI,IAAQ,EAAS,QAAQ,QAAQ,GAAQ,CAAK,IAAI,IAAI,IAAQ;CAE9G,OAAO,EAAM,iBAAiB,EAAS,gBACnC,EAAQ,mBAAmB,EAAM,YAAY,EAAM,MAAM,UAAU,IACnE;AACN"}
package/dist/core.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`);\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":"0HAaA,SAAgB,EAAM,EAAe,EAAqC,CACxE,GAAI,CAOF,OANI,EAAQ,KAAO,gBAAwB,EAAA,SAAS,cAAc,KAAK,CAAK,EAExE,EAAQ,KAAO,UAAkB,EAAA,SAAS,QAAQ,KAAK,CAAK,EAE5D,EAAQ,KAAO,gBAAwB,EAAA,SAAS,cAAc,KAAK,CAAK,EAErE,EAAA,SAAS,UAAU,KAAK,CAAK,CACtC,MAAQ,CACN,EAAA,KAAK,WAAW,EAAQ,GAAG,qBAAqB,EAAM,GAAG,CAC3D,CACF,CAEA,SAAgB,EAAI,EAAuD,CACzE,OAAO,EAAA,SAAS,IAAI,iBAAiB,EAAA,iBAAiB,EAAQ,QAAQ,CAAC,CACzE,CAEA,SAAgB,GAA+B,CAC7C,OAAO,EAAA,SAAS,IAAI,QAAQ,CAC9B,CAYA,SAAgB,EACd,EACA,EACA,EAAwB,CAAC,EACD,CACxB,IAAM,EAAW,EAAA,cAAc,EAAO,CAAO,EAE7C,OAAO,EAAA,QAAQ,EAAO,CAAE,eAAgB,EAAQ,eAAgB,UAAS,CAAC,CAAC,CAAC,IAAI,CAAQ,CAC1F,CAEA,SAAgB,EAAW,EAA2C,CACpE,GAAM,CAAE,MAAK,cAAa,oBAAmB,eAAc,eAAc,SAAU,EAC7E,EAAW,CAAE,cAAa,oBAAmB,eAAc,cAAa,EAK9E,GAAI,EAHD,IAAgB,IAAA,IAAa,EAAA,eAAe,IAAI,CAA2B,GAC3E,IAAiB,IAAA,IAAa,EAAA,eAAe,IAAI,CAA4B,IAE1D,aAAiB,EAAA,SAAS,SAAW,aAAe,EAAA,SAAS,QACjF,OAAO,EAAI,MAAM,EAAO,CAAyD,EAGnF,IAAM,EAAW,EAAA,oBAAoB,CAAC,EAAO,CAAG,EAAG,CAAK,EAClD,EAAU,CAAE,eAAgB,EAAM,eAAgB,UAAS,EAEjE,OAAO,EAAA,QAAQ,EAAK,CAAO,CAAC,CAAC,MAAM,EAAA,QAAQ,EAAO,CAAO,EAAG,CAAQ,CACtE,CAEA,SAAgB,EAAQ,EAAoC,CAC1D,OACE,aAAiB,EAAA,SAAS,SAC1B,aAAiB,EAAA,SAAS,eAC1B,aAAiB,EAAA,SAAS,eAC1B,aAAiB,EAAA,SAAS,SAE9B"}
1
+ {"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`);\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":"0HAWA,SAAgB,EAAM,EAAe,EAAqC,CACxE,GAAI,CAOF,OANI,EAAQ,KAAO,gBAAwB,EAAA,SAAS,cAAc,KAAK,CAAK,EAExE,EAAQ,KAAO,UAAkB,EAAA,SAAS,QAAQ,KAAK,CAAK,EAE5D,EAAQ,KAAO,gBAAwB,EAAA,SAAS,c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AAC1B,wBAAgB,KAAK,CACnB,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,EACjD,QAAQ,EAAE,QAAQ,CAAC,YAAY,EAC/B,OAAO,EAAE,YAAY,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC3C,QAAQ,CAAC,aAAa,CAAC;AAW1B,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,QAAQ,CAAC,QAAQ,CAepE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAO1D"}
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`);\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":";;;;;AAaA,SAAgB,EAAM,GAAe,GAAqC;CACxE,IAAI;EAOF,OANI,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAExE,EAAQ,OAAO,YAAkB,EAAS,QAAQ,KAAK,CAAK,IAE5D,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAErE,EAAS,UAAU,KAAK,CAAK;CACtC,QAAQ;EACN,EAAK,WAAW,EAAQ,GAAG,qBAAqB,EAAM,GAAG;CAC3D;AACF;AAEA,SAAgB,EAAI,GAAuD;CACzE,OAAO,EAAS,IAAI,iBAAiB,EAAiB,EAAQ,QAAQ,CAAC;AACzE;AAEA,SAAgB,IAA+B;CAC7C,OAAO,EAAS,IAAI,QAAQ;AAC9B;AAYA,SAAgB,EACd,GACA,GACA,IAAwB,CAAC,GACD;CACxB,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAQ,GAAO;EAAE,gBAAgB,EAAQ;EAAgB;CAAS,CAAC,CAAC,CAAC,IAAI,CAAQ;AAC1F;AAEA,SAAgB,EAAW,GAA2C;CACpE,IAAM,EAAE,QAAK,gBAAa,sBAAmB,iBAAc,iBAAc,aAAU,GAC7E,IAAW;EAAE;EAAa;EAAmB;EAAc;CAAa;CAK9E,IAAI,EAHD,MAAgB,KAAA,KAAa,EAAe,IAAI,CAA2B,KAC3E,MAAiB,KAAA,KAAa,EAAe,IAAI,CAA4B,MAE1D,aAAiB,EAAS,WAAW,aAAe,EAAS,SACjF,OAAO,EAAI,MAAM,GAAO,CAAyD;CAGnF,IAAM,IAAW,EAAoB,CAAC,GAAO,CAAG,GAAG,CAAK,GAClD,IAAU;EAAE,gBAAgB,EAAM;EAAgB;CAAS;CAEjE,OAAO,EAAQ,GAAK,CAAO,CAAC,CAAC,MAAM,EAAQ,GAAO,CAAO,GAAG,CAAQ;AACtE;AAEA,SAAgB,EAAQ,GAAoC;CAC1D,OACE,aAAiB,EAAS,WAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS;AAE9B"}
1
+ {"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { toZoned } from './_convert';\nimport { CALENDAR_UNITS, inferSharedTimeZone, inferTimeZone, validateTimeZone } from './_tz';\nimport { fail } from './errors';\nimport type { CalendarUnit, DifferenceInput, ParseAs, ShiftOptions, TimeInput } from './types';\n\n/** Parse intentionally requires an explicit result kind: time strings are ambiguous at system boundaries. */\nexport function parse(input: string, options: { as: 'zonedDateTime' }): Temporal.ZonedDateTime;\nexport function parse(input: string, options: { as: 'instant' }): Temporal.Instant;\nexport function parse(input: string, options: { as: 'plainDateTime' }): Temporal.PlainDateTime;\nexport function parse(input: string, options: { as: 'plainDate' }): Temporal.PlainDate;\nexport function parse(input: string, options: { as: ParseAs }): TimeInput {\n try {\n if (options.as === 'zonedDateTime') return Temporal.ZonedDateTime.from(input);\n\n if (options.as === 'instant') return Temporal.Instant.from(input);\n\n if (options.as === 'plainDateTime') return Temporal.PlainDateTime.from(input);\n\n return Temporal.PlainDate.from(input);\n } catch {\n fail(`Invalid ${options.as} ISO 8601 string: \"${input}\".`);\n }\n}\n\nexport function now(options: { timeZone: string }): Temporal.ZonedDateTime {\n return Temporal.Now.zonedDateTimeISO(validateTimeZone(options.timeZone));\n}\n\nexport function nowInstant(): Temporal.Instant {\n return Temporal.Now.instant();\n}\n\nexport function shift(\n input: Temporal.ZonedDateTime,\n duration: Temporal.DurationLike,\n options?: ShiftOptions,\n): Temporal.ZonedDateTime;\nexport function shift(\n input: Exclude<TimeInput, Temporal.ZonedDateTime>,\n duration: Temporal.DurationLike,\n options: ShiftOptions & { timeZone: string },\n): Temporal.ZonedDateTime;\nexport function shift(\n input: TimeInput,\n duration: Temporal.DurationLike,\n options: ShiftOptions = {},\n): Temporal.ZonedDateTime {\n const timeZone = inferTimeZone(input, options);\n\n return toZoned(input, { disambiguation: options.disambiguation, timeZone }).add(duration);\n}\n\nexport function difference(input: DifferenceInput): Temporal.Duration {\n const { end, largestUnit, roundingIncrement, roundingMode, smallestUnit, start } = input;\n const rounding = { largestUnit, roundingIncrement, roundingMode, smallestUnit };\n const needsCalendar =\n (largestUnit !== undefined && CALENDAR_UNITS.has(largestUnit as CalendarUnit)) ||\n (smallestUnit !== undefined && CALENDAR_UNITS.has(smallestUnit as CalendarUnit));\n\n if (!needsCalendar && start instanceof Temporal.Instant && end instanceof Temporal.Instant) {\n return end.since(start, rounding as Temporal.DifferenceOptions<Temporal.TimeUnit>);\n }\n\n const timeZone = inferSharedTimeZone([start, end], input);\n const options = { disambiguation: input.disambiguation, timeZone };\n\n return toZoned(end, options).since(toZoned(start, options), rounding);\n}\n\nexport function isValid(value: unknown): value is TimeInput {\n return (\n value instanceof Temporal.Instant ||\n value instanceof Temporal.ZonedDateTime ||\n value instanceof Temporal.PlainDateTime ||\n value instanceof Temporal.PlainDate\n );\n}\n"],"mappings":";;;;;AAWA,SAAgB,EAAM,GAAe,GAAqC;CACxE,IAAI;EAOF,OANI,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAExE,EAAQ,OAAO,YAAkB,EAAS,QAAQ,KAAK,CAAK,IAE5D,EAAQ,OAAO,kBAAwB,EAAS,cAAc,KAAK,CAAK,IAErE,EAAS,UAAU,KAAK,CAAK;CACtC,QAAQ;EACN,EAAK,WAAW,EAAQ,GAAG,qBAAqB,EAAM,GAAG;CAC3D;AACF;AAEA,SAAgB,EAAI,GAAuD;CACzE,OAAO,EAAS,IAAI,iBAAiB,EAAiB,EAAQ,QAAQ,CAAC;AACzE;AAEA,SAAgB,IAA+B;CAC7C,OAAO,EAAS,IAAI,QAAQ;AAC9B;AAYA,SAAgB,EACd,GACA,GACA,IAAwB,CAAC,GACD;CACxB,IAAM,IAAW,EAAc,GAAO,CAAO;CAE7C,OAAO,EAAQ,GAAO;EAAE,gBAAgB,EAAQ;EAAgB;CAAS,CAAC,CAAC,CAAC,IAAI,CAAQ;AAC1F;AAEA,SAAgB,EAAW,GAA2C;CACpE,IAAM,EAAE,QAAK,gBAAa,sBAAmB,iBAAc,iBAAc,aAAU,GAC7E,IAAW;EAAE;EAAa;EAAmB;EAAc;CAAa;CAK9E,IAAI,EAHD,MAAgB,KAAA,KAAa,EAAe,IAAI,CAA2B,KAC3E,MAAiB,KAAA,KAAa,EAAe,IAAI,CAA4B,MAE1D,aAAiB,EAAS,WAAW,aAAe,EAAS,SACjF,OAAO,EAAI,MAAM,GAAO,CAAyD;CAGnF,IAAM,IAAW,EAAoB,CAAC,GAAO,CAAG,GAAG,CAAK,GAClD,IAAU;EAAE,gBAAgB,EAAM;EAAgB;CAAS;CAEjE,OAAO,EAAQ,GAAK,CAAO,CAAC,CAAC,MAAM,EAAQ,GAAO,CAAO,GAAG,CAAQ;AACtE;AAEA,SAAgB,EAAQ,GAAoC;CAC1D,OACE,aAAiB,EAAS,WAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS,iBAC1B,aAAiB,EAAS;AAE9B"}
package/dist/errors.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{},n=class extends e{},r=class extends e{},i=class extends e{};function a(e,n=t){throw new n(e)}exports.TempoError=e,exports.TempoInvalidInputError=t,exports.TempoInvalidTzError=n,exports.TempoMissingTzError=r,exports.TempoUnsupportedInputError=i,exports.fail=a;
1
+ var e=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},t=class extends e{},n=class extends e{},r=class extends e{},i=class extends e{};function a(e,n=t){throw new n(e)}exports.TempoError=e,exports.TempoInvalidInputError=t,exports.TempoInvalidTzError=n,exports.TempoMissingTzError=r,exports.TempoUnsupportedInputError=i,exports.fail=a;
2
2
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is TempoError {\n return err instanceof TempoError;\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAA4C,CAAW,CAAC,EAG3C,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAgD,CAAW,CAAC,EAM5D,SAAgB,EAAK,EAAiB,EAAwB,EAA+B,CAC3F,MAAM,IAAI,EAAM,CAAO,CACzB"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":"AACA,IAAa,EAAb,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,EAAb,cAA4C,CAAW,CAAC,EAG3C,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAyC,CAAW,CAAC,EAGxC,EAAb,cAAgD,CAAW,CAAC,EAM5D,SAAgB,EAAK,EAAiB,EAAwB,EAA+B,CAC3F,MAAM,IAAI,EAAM,CAAO,CACzB"}
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */
2
2
  export declare class TempoError extends Error {
3
3
  constructor(message: string, opts?: ErrorOptions);
4
- static is(err: unknown): err is TempoError;
5
4
  }
6
5
  /** Thrown when a date/time input string or value cannot be parsed. */
7
6
  export declare class TempoInvalidInputError extends TempoError {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;IAMhD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,UAAU;CAG3C;AAED,sEAAsE;AACtE,qBAAa,sBAAuB,SAAQ,UAAU;CAAG;AAEzD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,0BAA2B,SAAQ,UAAU;CAAG;AAI7D,KAAK,cAAc,GAAG,KAAK,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;AAE1D,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,cAAuC,GAAG,KAAK,CAE3F"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,sEAAsE;AACtE,qBAAa,sBAAuB,SAAQ,UAAU;CAAG;AAEzD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,UAAU;CAAG;AAEtD,0EAA0E;AAC1E,qBAAa,0BAA2B,SAAQ,UAAU;CAAG;AAI7D,KAAK,cAAc,GAAG,KAAK,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC;AAE1D,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,cAAuC,GAAG,KAAK,CAE3F"}
package/dist/errors.js CHANGED
@@ -1,11 +1,8 @@
1
1
  //#region src/errors.ts
2
- var e = class e extends Error {
2
+ var e = class extends Error {
3
3
  constructor(e, t) {
4
4
  super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
5
  }
6
- static is(t) {
7
- return t instanceof e;
8
- }
9
6
  }, t = class extends e {}, n = class extends e {}, r = class extends e {}, i = class extends e {};
10
7
  function a(e, n = t) {
11
8
  throw new n(e);
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is TempoError {\n return err instanceof TempoError;\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAmB,MAAM;CACpC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;CAEA,OAAO,GAAG,GAAiC;EACzC,OAAO,aAAe;CACxB;AACF,GAGa,IAAb,cAA4C,EAAW,CAAC,GAG3C,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAgD,EAAW,CAAC;AAM5D,SAAgB,EAAK,GAAiB,IAAwB,GAA+B;CAC3F,MAAM,IAAI,EAAM,CAAO;AACzB"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all tempo errors. Use `instanceof TempoError` to catch any tempo-originated error. */\nexport class TempoError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a date/time input string or value cannot be parsed. */\nexport class TempoInvalidInputError extends TempoError {}\n\n/** Thrown when the provided timezone identifier is unknown or invalid. */\nexport class TempoInvalidTzError extends TempoError {}\n\n/** Thrown when an operation requires a timezone but none was supplied. */\nexport class TempoMissingTzError extends TempoError {}\n\n/** Thrown when an input type is not supported by the called operation. */\nexport class TempoUnsupportedInputError extends TempoError {}\n\n// ─── Error helpers ────────────────────────────────────────────────────────────\n\ntype TempoErrorCtor = new (message: string) => TempoError;\n\nexport function fail(message: string, Class: TempoErrorCtor = TempoInvalidInputError): never {\n throw new Class(message);\n}\n"],"mappings":";AACA,IAAa,IAAb,cAAgC,MAAM;CACpC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,IAAb,cAA4C,EAAW,CAAC,GAG3C,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAyC,EAAW,CAAC,GAGxC,IAAb,cAAgD,EAAW,CAAC;AAM5D,SAAgB,EAAK,GAAiB,IAAwB,GAA+B;CAC3F,MAAM,IAAI,EAAM,CAAO;AACzB"}