minotor 12.0.1 → 13.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +7 -4
  3. package/dist/cli/perf.d.ts +4 -4
  4. package/dist/cli.mjs +1558 -1488
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/gtfs/__tests__/logging.test.d.ts +1 -0
  7. package/dist/gtfs/logging.d.ts +8 -0
  8. package/dist/parser.cjs.js +108 -98
  9. package/dist/parser.cjs.js.map +1 -1
  10. package/dist/parser.d.ts +4 -2
  11. package/dist/parser.esm.js +108 -99
  12. package/dist/parser.esm.js.map +1 -1
  13. package/dist/router.cjs.js +1 -1
  14. package/dist/router.cjs.js.map +1 -1
  15. package/dist/router.d.ts +2 -1
  16. package/dist/router.esm.js +1 -1
  17. package/dist/router.esm.js.map +1 -1
  18. package/dist/router.umd.js +1 -1
  19. package/dist/router.umd.js.map +1 -1
  20. package/dist/routing/rangeResult.d.ts +34 -25
  21. package/dist/routing/result.d.ts +28 -9
  22. package/dist/routing/resultInternals.d.ts +4 -0
  23. package/dist/routing/routingResult.d.ts +29 -0
  24. package/package.json +1 -1
  25. package/src/cli/minotor.ts +4 -12
  26. package/src/cli/perf.ts +5 -5
  27. package/src/cli/repl.ts +1 -1
  28. package/src/gtfs/__tests__/logging.test.ts +100 -0
  29. package/src/gtfs/frequencies.ts +1 -2
  30. package/src/gtfs/logging.ts +15 -0
  31. package/src/gtfs/parser.ts +1 -2
  32. package/src/gtfs/routes.ts +1 -2
  33. package/src/gtfs/stops.ts +1 -2
  34. package/src/gtfs/transfers.ts +1 -2
  35. package/src/gtfs/trips.ts +1 -2
  36. package/src/parser.ts +4 -0
  37. package/src/router.ts +3 -0
  38. package/src/routing/__tests__/plotter.test.ts +0 -11
  39. package/src/routing/__tests__/rangeResult.test.ts +1470 -46
  40. package/src/routing/__tests__/rangeRouter.test.ts +14 -8
  41. package/src/routing/__tests__/result.test.ts +375 -76
  42. package/src/routing/plainRouter.ts +1 -6
  43. package/src/routing/plotter.ts +6 -5
  44. package/src/routing/rangeResult.ts +67 -52
  45. package/src/routing/rangeRouter.ts +3 -8
  46. package/src/routing/result.ts +95 -36
  47. package/src/routing/resultInternals.ts +5 -0
  48. package/src/routing/routingResult.ts +34 -0
package/dist/cli.mjs CHANGED
@@ -61,6 +61,19 @@ function __asyncValues(o) {
61
61
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
62
62
  }
63
63
 
64
+ function __classPrivateFieldGet(receiver, state, kind, f) {
65
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
66
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
67
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
68
+ }
69
+
70
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
71
+ if (kind === "m") throw new TypeError("Private method is not writable");
72
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
73
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
74
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
75
+ }
76
+
64
77
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
65
78
  var e = new Error(message);
66
79
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -4232,1431 +4245,1057 @@ function useColor() {
4232
4245
 
4233
4246
  new Command();
4234
4247
 
4235
- function getDefaultExportFromCjs (x) {
4236
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
4237
- }
4248
+ // these aren't really private, but nor are they really useful to document
4238
4249
 
4239
- var loglevel$1 = {exports: {}};
4250
+ /**
4251
+ * @private
4252
+ */
4253
+ class LuxonError extends Error {}
4240
4254
 
4241
- /*
4242
- * loglevel - https://github.com/pimterry/loglevel
4243
- *
4244
- * Copyright (c) 2013 Tim Perry
4245
- * Licensed under the MIT license.
4246
- */
4247
- var loglevel = loglevel$1.exports;
4255
+ /**
4256
+ * @private
4257
+ */
4258
+ class InvalidDateTimeError extends LuxonError {
4259
+ constructor(reason) {
4260
+ super(`Invalid DateTime: ${reason.toMessage()}`);
4261
+ }
4262
+ }
4248
4263
 
4249
- var hasRequiredLoglevel;
4264
+ /**
4265
+ * @private
4266
+ */
4267
+ class InvalidIntervalError extends LuxonError {
4268
+ constructor(reason) {
4269
+ super(`Invalid Interval: ${reason.toMessage()}`);
4270
+ }
4271
+ }
4250
4272
 
4251
- function requireLoglevel () {
4252
- if (hasRequiredLoglevel) return loglevel$1.exports;
4253
- hasRequiredLoglevel = 1;
4254
- (function (module) {
4255
- (function (root, definition) {
4256
- if (module.exports) {
4257
- module.exports = definition();
4258
- } else {
4259
- root.log = definition();
4260
- }
4261
- }(loglevel, function () {
4273
+ /**
4274
+ * @private
4275
+ */
4276
+ class InvalidDurationError extends LuxonError {
4277
+ constructor(reason) {
4278
+ super(`Invalid Duration: ${reason.toMessage()}`);
4279
+ }
4280
+ }
4262
4281
 
4263
- // Slightly dubious tricks to cut down minimized file size
4264
- var noop = function() {};
4265
- var undefinedType = "undefined";
4266
- var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (
4267
- /Trident\/|MSIE /.test(window.navigator.userAgent)
4268
- );
4282
+ /**
4283
+ * @private
4284
+ */
4285
+ class ConflictingSpecificationError extends LuxonError {}
4269
4286
 
4270
- var logMethods = [
4271
- "trace",
4272
- "debug",
4273
- "info",
4274
- "warn",
4275
- "error"
4276
- ];
4287
+ /**
4288
+ * @private
4289
+ */
4290
+ class InvalidUnitError extends LuxonError {
4291
+ constructor(unit) {
4292
+ super(`Invalid unit ${unit}`);
4293
+ }
4294
+ }
4277
4295
 
4278
- var _loggersByName = {};
4279
- var defaultLogger = null;
4296
+ /**
4297
+ * @private
4298
+ */
4299
+ class InvalidArgumentError extends LuxonError {}
4280
4300
 
4281
- // Cross-browser bind equivalent that works at least back to IE6
4282
- function bindMethod(obj, methodName) {
4283
- var method = obj[methodName];
4284
- if (typeof method.bind === 'function') {
4285
- return method.bind(obj);
4286
- } else {
4287
- try {
4288
- return Function.prototype.bind.call(method, obj);
4289
- } catch (e) {
4290
- // Missing bind shim or IE8 + Modernizr, fallback to wrapping
4291
- return function() {
4292
- return Function.prototype.apply.apply(method, [obj, arguments]);
4293
- };
4294
- }
4295
- }
4296
- }
4301
+ /**
4302
+ * @private
4303
+ */
4304
+ class ZoneIsAbstractError extends LuxonError {
4305
+ constructor() {
4306
+ super("Zone is an abstract class");
4307
+ }
4308
+ }
4297
4309
 
4298
- // Trace() doesn't print the message in IE, so for that case we need to wrap it
4299
- function traceForIE() {
4300
- if (console.log) {
4301
- if (console.log.apply) {
4302
- console.log.apply(console, arguments);
4303
- } else {
4304
- // In old IE, native console methods themselves don't have apply().
4305
- Function.prototype.apply.apply(console.log, [console, arguments]);
4306
- }
4307
- }
4308
- if (console.trace) console.trace();
4309
- }
4310
+ /**
4311
+ * @private
4312
+ */
4310
4313
 
4311
- // Build the best logging method possible for this env
4312
- // Wherever possible we want to bind, not wrap, to preserve stack traces
4313
- function realMethod(methodName) {
4314
- if (methodName === 'debug') {
4315
- methodName = 'log';
4316
- }
4314
+ const n$1 = "numeric",
4315
+ s$2 = "short",
4316
+ l$1 = "long";
4317
4317
 
4318
- if (typeof console === undefinedType) {
4319
- return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
4320
- } else if (methodName === 'trace' && isIE) {
4321
- return traceForIE;
4322
- } else if (console[methodName] !== undefined) {
4323
- return bindMethod(console, methodName);
4324
- } else if (console.log !== undefined) {
4325
- return bindMethod(console, 'log');
4326
- } else {
4327
- return noop;
4328
- }
4329
- }
4318
+ const DATE_SHORT = {
4319
+ year: n$1,
4320
+ month: n$1,
4321
+ day: n$1,
4322
+ };
4330
4323
 
4331
- // These private functions always need `this` to be set properly
4324
+ const DATE_MED = {
4325
+ year: n$1,
4326
+ month: s$2,
4327
+ day: n$1,
4328
+ };
4332
4329
 
4333
- function replaceLoggingMethods() {
4334
- /*jshint validthis:true */
4335
- var level = this.getLevel();
4330
+ const DATE_MED_WITH_WEEKDAY = {
4331
+ year: n$1,
4332
+ month: s$2,
4333
+ day: n$1,
4334
+ weekday: s$2,
4335
+ };
4336
4336
 
4337
- // Replace the actual methods.
4338
- for (var i = 0; i < logMethods.length; i++) {
4339
- var methodName = logMethods[i];
4340
- this[methodName] = (i < level) ?
4341
- noop :
4342
- this.methodFactory(methodName, level, this.name);
4343
- }
4337
+ const DATE_FULL = {
4338
+ year: n$1,
4339
+ month: l$1,
4340
+ day: n$1,
4341
+ };
4344
4342
 
4345
- // Define log.log as an alias for log.debug
4346
- this.log = this.debug;
4343
+ const DATE_HUGE = {
4344
+ year: n$1,
4345
+ month: l$1,
4346
+ day: n$1,
4347
+ weekday: l$1,
4348
+ };
4347
4349
 
4348
- // Return any important warnings.
4349
- if (typeof console === undefinedType && level < this.levels.SILENT) {
4350
- return "No console available for logging";
4351
- }
4352
- }
4350
+ const TIME_SIMPLE = {
4351
+ hour: n$1,
4352
+ minute: n$1,
4353
+ };
4353
4354
 
4354
- // In old IE versions, the console isn't present until you first open it.
4355
- // We build realMethod() replacements here that regenerate logging methods
4356
- function enableLoggingWhenConsoleArrives(methodName) {
4357
- return function () {
4358
- if (typeof console !== undefinedType) {
4359
- replaceLoggingMethods.call(this);
4360
- this[methodName].apply(this, arguments);
4361
- }
4362
- };
4363
- }
4355
+ const TIME_WITH_SECONDS = {
4356
+ hour: n$1,
4357
+ minute: n$1,
4358
+ second: n$1,
4359
+ };
4364
4360
 
4365
- // By default, we use closely bound real methods wherever possible, and
4366
- // otherwise we wait for a console to appear, and then try again.
4367
- function defaultMethodFactory(methodName, _level, _loggerName) {
4368
- /*jshint validthis:true */
4369
- return realMethod(methodName) ||
4370
- enableLoggingWhenConsoleArrives.apply(this, arguments);
4371
- }
4361
+ const TIME_WITH_SHORT_OFFSET = {
4362
+ hour: n$1,
4363
+ minute: n$1,
4364
+ second: n$1,
4365
+ timeZoneName: s$2,
4366
+ };
4372
4367
 
4373
- function Logger(name, factory) {
4374
- // Private instance variables.
4375
- var self = this;
4376
- /**
4377
- * The level inherited from a parent logger (or a global default). We
4378
- * cache this here rather than delegating to the parent so that it stays
4379
- * in sync with the actual logging methods that we have installed (the
4380
- * parent could change levels but we might not have rebuilt the loggers
4381
- * in this child yet).
4382
- * @type {number}
4383
- */
4384
- var inheritedLevel;
4385
- /**
4386
- * The default level for this logger, if any. If set, this overrides
4387
- * `inheritedLevel`.
4388
- * @type {number|null}
4389
- */
4390
- var defaultLevel;
4391
- /**
4392
- * A user-specific level for this logger. If set, this overrides
4393
- * `defaultLevel`.
4394
- * @type {number|null}
4395
- */
4396
- var userLevel;
4368
+ const TIME_WITH_LONG_OFFSET = {
4369
+ hour: n$1,
4370
+ minute: n$1,
4371
+ second: n$1,
4372
+ timeZoneName: l$1,
4373
+ };
4397
4374
 
4398
- var storageKey = "loglevel";
4399
- if (typeof name === "string") {
4400
- storageKey += ":" + name;
4401
- } else if (typeof name === "symbol") {
4402
- storageKey = undefined;
4403
- }
4375
+ const TIME_24_SIMPLE = {
4376
+ hour: n$1,
4377
+ minute: n$1,
4378
+ hourCycle: "h23",
4379
+ };
4404
4380
 
4405
- function persistLevelIfPossible(levelNum) {
4406
- var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
4381
+ const TIME_24_WITH_SECONDS = {
4382
+ hour: n$1,
4383
+ minute: n$1,
4384
+ second: n$1,
4385
+ hourCycle: "h23",
4386
+ };
4407
4387
 
4408
- if (typeof window === undefinedType || !storageKey) return;
4388
+ const TIME_24_WITH_SHORT_OFFSET = {
4389
+ hour: n$1,
4390
+ minute: n$1,
4391
+ second: n$1,
4392
+ hourCycle: "h23",
4393
+ timeZoneName: s$2,
4394
+ };
4409
4395
 
4410
- // Use localStorage if available
4411
- try {
4412
- window.localStorage[storageKey] = levelName;
4413
- return;
4414
- } catch (ignore) {}
4396
+ const TIME_24_WITH_LONG_OFFSET = {
4397
+ hour: n$1,
4398
+ minute: n$1,
4399
+ second: n$1,
4400
+ hourCycle: "h23",
4401
+ timeZoneName: l$1,
4402
+ };
4415
4403
 
4416
- // Use session cookie as fallback
4417
- try {
4418
- window.document.cookie =
4419
- encodeURIComponent(storageKey) + "=" + levelName + ";";
4420
- } catch (ignore) {}
4421
- }
4404
+ const DATETIME_SHORT = {
4405
+ year: n$1,
4406
+ month: n$1,
4407
+ day: n$1,
4408
+ hour: n$1,
4409
+ minute: n$1,
4410
+ };
4422
4411
 
4423
- function getPersistedLevel() {
4424
- var storedLevel;
4412
+ const DATETIME_SHORT_WITH_SECONDS = {
4413
+ year: n$1,
4414
+ month: n$1,
4415
+ day: n$1,
4416
+ hour: n$1,
4417
+ minute: n$1,
4418
+ second: n$1,
4419
+ };
4425
4420
 
4426
- if (typeof window === undefinedType || !storageKey) return;
4421
+ const DATETIME_MED = {
4422
+ year: n$1,
4423
+ month: s$2,
4424
+ day: n$1,
4425
+ hour: n$1,
4426
+ minute: n$1,
4427
+ };
4427
4428
 
4428
- try {
4429
- storedLevel = window.localStorage[storageKey];
4430
- } catch (ignore) {}
4429
+ const DATETIME_MED_WITH_SECONDS = {
4430
+ year: n$1,
4431
+ month: s$2,
4432
+ day: n$1,
4433
+ hour: n$1,
4434
+ minute: n$1,
4435
+ second: n$1,
4436
+ };
4431
4437
 
4432
- // Fallback to cookies if local storage gives us nothing
4433
- if (typeof storedLevel === undefinedType) {
4434
- try {
4435
- var cookie = window.document.cookie;
4436
- var cookieName = encodeURIComponent(storageKey);
4437
- var location = cookie.indexOf(cookieName + "=");
4438
- if (location !== -1) {
4439
- storedLevel = /^([^;]+)/.exec(
4440
- cookie.slice(location + cookieName.length + 1)
4441
- )[1];
4442
- }
4443
- } catch (ignore) {}
4444
- }
4438
+ const DATETIME_MED_WITH_WEEKDAY = {
4439
+ year: n$1,
4440
+ month: s$2,
4441
+ day: n$1,
4442
+ weekday: s$2,
4443
+ hour: n$1,
4444
+ minute: n$1,
4445
+ };
4445
4446
 
4446
- // If the stored level is not valid, treat it as if nothing was stored.
4447
- if (self.levels[storedLevel] === undefined) {
4448
- storedLevel = undefined;
4449
- }
4447
+ const DATETIME_FULL = {
4448
+ year: n$1,
4449
+ month: l$1,
4450
+ day: n$1,
4451
+ hour: n$1,
4452
+ minute: n$1,
4453
+ timeZoneName: s$2,
4454
+ };
4450
4455
 
4451
- return storedLevel;
4452
- }
4456
+ const DATETIME_FULL_WITH_SECONDS = {
4457
+ year: n$1,
4458
+ month: l$1,
4459
+ day: n$1,
4460
+ hour: n$1,
4461
+ minute: n$1,
4462
+ second: n$1,
4463
+ timeZoneName: s$2,
4464
+ };
4453
4465
 
4454
- function clearPersistedLevel() {
4455
- if (typeof window === undefinedType || !storageKey) return;
4466
+ const DATETIME_HUGE = {
4467
+ year: n$1,
4468
+ month: l$1,
4469
+ day: n$1,
4470
+ weekday: l$1,
4471
+ hour: n$1,
4472
+ minute: n$1,
4473
+ timeZoneName: l$1,
4474
+ };
4456
4475
 
4457
- // Use localStorage if available
4458
- try {
4459
- window.localStorage.removeItem(storageKey);
4460
- } catch (ignore) {}
4476
+ const DATETIME_HUGE_WITH_SECONDS = {
4477
+ year: n$1,
4478
+ month: l$1,
4479
+ day: n$1,
4480
+ weekday: l$1,
4481
+ hour: n$1,
4482
+ minute: n$1,
4483
+ second: n$1,
4484
+ timeZoneName: l$1,
4485
+ };
4461
4486
 
4462
- // Use session cookie as fallback
4463
- try {
4464
- window.document.cookie =
4465
- encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
4466
- } catch (ignore) {}
4467
- }
4487
+ /**
4488
+ * @interface
4489
+ */
4490
+ class Zone {
4491
+ /**
4492
+ * The type of zone
4493
+ * @abstract
4494
+ * @type {string}
4495
+ */
4496
+ get type() {
4497
+ throw new ZoneIsAbstractError();
4498
+ }
4468
4499
 
4469
- function normalizeLevel(input) {
4470
- var level = input;
4471
- if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
4472
- level = self.levels[level.toUpperCase()];
4473
- }
4474
- if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
4475
- return level;
4476
- } else {
4477
- throw new TypeError("log.setLevel() called with invalid level: " + input);
4478
- }
4479
- }
4500
+ /**
4501
+ * The name of this zone.
4502
+ * @abstract
4503
+ * @type {string}
4504
+ */
4505
+ get name() {
4506
+ throw new ZoneIsAbstractError();
4507
+ }
4480
4508
 
4481
- /*
4482
- *
4483
- * Public logger API - see https://github.com/pimterry/loglevel for details
4484
- *
4485
- */
4509
+ /**
4510
+ * The IANA name of this zone.
4511
+ * Defaults to `name` if not overwritten by a subclass.
4512
+ * @abstract
4513
+ * @type {string}
4514
+ */
4515
+ get ianaName() {
4516
+ return this.name;
4517
+ }
4486
4518
 
4487
- self.name = name;
4519
+ /**
4520
+ * Returns whether the offset is known to be fixed for the whole year.
4521
+ * @abstract
4522
+ * @type {boolean}
4523
+ */
4524
+ get isUniversal() {
4525
+ throw new ZoneIsAbstractError();
4526
+ }
4488
4527
 
4489
- self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
4490
- "ERROR": 4, "SILENT": 5};
4528
+ /**
4529
+ * Returns the offset's common name (such as EST) at the specified timestamp
4530
+ * @abstract
4531
+ * @param {number} ts - Epoch milliseconds for which to get the name
4532
+ * @param {Object} opts - Options to affect the format
4533
+ * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
4534
+ * @param {string} opts.locale - What locale to return the offset name in.
4535
+ * @return {string}
4536
+ */
4537
+ offsetName(ts, opts) {
4538
+ throw new ZoneIsAbstractError();
4539
+ }
4491
4540
 
4492
- self.methodFactory = factory || defaultMethodFactory;
4541
+ /**
4542
+ * Returns the offset's value as a string
4543
+ * @abstract
4544
+ * @param {number} ts - Epoch milliseconds for which to get the offset
4545
+ * @param {string} format - What style of offset to return.
4546
+ * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
4547
+ * @return {string}
4548
+ */
4549
+ formatOffset(ts, format) {
4550
+ throw new ZoneIsAbstractError();
4551
+ }
4493
4552
 
4494
- self.getLevel = function () {
4495
- if (userLevel != null) {
4496
- return userLevel;
4497
- } else if (defaultLevel != null) {
4498
- return defaultLevel;
4499
- } else {
4500
- return inheritedLevel;
4501
- }
4502
- };
4553
+ /**
4554
+ * Return the offset in minutes for this zone at the specified timestamp.
4555
+ * @abstract
4556
+ * @param {number} ts - Epoch milliseconds for which to compute the offset
4557
+ * @return {number}
4558
+ */
4559
+ offset(ts) {
4560
+ throw new ZoneIsAbstractError();
4561
+ }
4503
4562
 
4504
- self.setLevel = function (level, persist) {
4505
- userLevel = normalizeLevel(level);
4506
- if (persist !== false) { // defaults to true
4507
- persistLevelIfPossible(userLevel);
4508
- }
4509
-
4510
- // NOTE: in v2, this should call rebuild(), which updates children.
4511
- return replaceLoggingMethods.call(self);
4512
- };
4513
-
4514
- self.setDefaultLevel = function (level) {
4515
- defaultLevel = normalizeLevel(level);
4516
- if (!getPersistedLevel()) {
4517
- self.setLevel(level, false);
4518
- }
4519
- };
4520
-
4521
- self.resetLevel = function () {
4522
- userLevel = null;
4523
- clearPersistedLevel();
4524
- replaceLoggingMethods.call(self);
4525
- };
4526
-
4527
- self.enableAll = function(persist) {
4528
- self.setLevel(self.levels.TRACE, persist);
4529
- };
4530
-
4531
- self.disableAll = function(persist) {
4532
- self.setLevel(self.levels.SILENT, persist);
4533
- };
4534
-
4535
- self.rebuild = function () {
4536
- if (defaultLogger !== self) {
4537
- inheritedLevel = normalizeLevel(defaultLogger.getLevel());
4538
- }
4539
- replaceLoggingMethods.call(self);
4540
-
4541
- if (defaultLogger === self) {
4542
- for (var childName in _loggersByName) {
4543
- _loggersByName[childName].rebuild();
4544
- }
4545
- }
4546
- };
4547
-
4548
- // Initialize all the internal levels.
4549
- inheritedLevel = normalizeLevel(
4550
- defaultLogger ? defaultLogger.getLevel() : "WARN"
4551
- );
4552
- var initialLevel = getPersistedLevel();
4553
- if (initialLevel != null) {
4554
- userLevel = normalizeLevel(initialLevel);
4555
- }
4556
- replaceLoggingMethods.call(self);
4557
- }
4558
-
4559
- /*
4560
- *
4561
- * Top-level API
4562
- *
4563
- */
4564
-
4565
- defaultLogger = new Logger();
4566
-
4567
- defaultLogger.getLogger = function getLogger(name) {
4568
- if ((typeof name !== "symbol" && typeof name !== "string") || name === "") {
4569
- throw new TypeError("You must supply a name when creating a logger.");
4570
- }
4563
+ /**
4564
+ * Return whether this Zone is equal to another zone
4565
+ * @abstract
4566
+ * @param {Zone} otherZone - the zone to compare
4567
+ * @return {boolean}
4568
+ */
4569
+ equals(otherZone) {
4570
+ throw new ZoneIsAbstractError();
4571
+ }
4571
4572
 
4572
- var logger = _loggersByName[name];
4573
- if (!logger) {
4574
- logger = _loggersByName[name] = new Logger(
4575
- name,
4576
- defaultLogger.methodFactory
4577
- );
4578
- }
4579
- return logger;
4580
- };
4573
+ /**
4574
+ * Return whether this Zone is valid.
4575
+ * @abstract
4576
+ * @type {boolean}
4577
+ */
4578
+ get isValid() {
4579
+ throw new ZoneIsAbstractError();
4580
+ }
4581
+ }
4581
4582
 
4582
- // Grab the current global log variable in case of overwrite
4583
- var _log = (typeof window !== undefinedType) ? window.log : undefined;
4584
- defaultLogger.noConflict = function() {
4585
- if (typeof window !== undefinedType &&
4586
- window.log === defaultLogger) {
4587
- window.log = _log;
4588
- }
4583
+ let singleton$1 = null;
4589
4584
 
4590
- return defaultLogger;
4591
- };
4585
+ /**
4586
+ * Represents the local zone for this JavaScript environment.
4587
+ * @implements {Zone}
4588
+ */
4589
+ class SystemZone extends Zone {
4590
+ /**
4591
+ * Get a singleton instance of the local zone
4592
+ * @return {SystemZone}
4593
+ */
4594
+ static get instance() {
4595
+ if (singleton$1 === null) {
4596
+ singleton$1 = new SystemZone();
4597
+ }
4598
+ return singleton$1;
4599
+ }
4592
4600
 
4593
- defaultLogger.getLoggers = function getLoggers() {
4594
- return _loggersByName;
4595
- };
4601
+ /** @override **/
4602
+ get type() {
4603
+ return "system";
4604
+ }
4596
4605
 
4597
- // ES6 default export, for compatibility
4598
- defaultLogger['default'] = defaultLogger;
4606
+ /** @override **/
4607
+ get name() {
4608
+ return new Intl.DateTimeFormat().resolvedOptions().timeZone;
4609
+ }
4599
4610
 
4600
- return defaultLogger;
4601
- }));
4602
- } (loglevel$1));
4603
- return loglevel$1.exports;
4604
- }
4611
+ /** @override **/
4612
+ get isUniversal() {
4613
+ return false;
4614
+ }
4605
4615
 
4606
- var loglevelExports = requireLoglevel();
4607
- var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
4616
+ /** @override **/
4617
+ offsetName(ts, { format, locale }) {
4618
+ return parseZoneInfo(ts, format, locale);
4619
+ }
4608
4620
 
4609
- // these aren't really private, but nor are they really useful to document
4621
+ /** @override **/
4622
+ formatOffset(ts, format) {
4623
+ return formatOffset(this.offset(ts), format);
4624
+ }
4610
4625
 
4611
- /**
4612
- * @private
4613
- */
4614
- class LuxonError extends Error {}
4626
+ /** @override **/
4627
+ offset(ts) {
4628
+ return -new Date(ts).getTimezoneOffset();
4629
+ }
4615
4630
 
4616
- /**
4617
- * @private
4618
- */
4619
- class InvalidDateTimeError extends LuxonError {
4620
- constructor(reason) {
4621
- super(`Invalid DateTime: ${reason.toMessage()}`);
4631
+ /** @override **/
4632
+ equals(otherZone) {
4633
+ return otherZone.type === "system";
4622
4634
  }
4623
- }
4624
4635
 
4625
- /**
4626
- * @private
4627
- */
4628
- class InvalidIntervalError extends LuxonError {
4629
- constructor(reason) {
4630
- super(`Invalid Interval: ${reason.toMessage()}`);
4636
+ /** @override **/
4637
+ get isValid() {
4638
+ return true;
4631
4639
  }
4632
4640
  }
4633
4641
 
4634
- /**
4635
- * @private
4636
- */
4637
- class InvalidDurationError extends LuxonError {
4638
- constructor(reason) {
4639
- super(`Invalid Duration: ${reason.toMessage()}`);
4642
+ const dtfCache = new Map();
4643
+ function makeDTF(zoneName) {
4644
+ let dtf = dtfCache.get(zoneName);
4645
+ if (dtf === undefined) {
4646
+ dtf = new Intl.DateTimeFormat("en-US", {
4647
+ hour12: false,
4648
+ timeZone: zoneName,
4649
+ year: "numeric",
4650
+ month: "2-digit",
4651
+ day: "2-digit",
4652
+ hour: "2-digit",
4653
+ minute: "2-digit",
4654
+ second: "2-digit",
4655
+ era: "short",
4656
+ });
4657
+ dtfCache.set(zoneName, dtf);
4640
4658
  }
4659
+ return dtf;
4641
4660
  }
4642
4661
 
4643
- /**
4644
- * @private
4645
- */
4646
- class ConflictingSpecificationError extends LuxonError {}
4662
+ const typeToPos = {
4663
+ year: 0,
4664
+ month: 1,
4665
+ day: 2,
4666
+ era: 3,
4667
+ hour: 4,
4668
+ minute: 5,
4669
+ second: 6,
4670
+ };
4647
4671
 
4648
- /**
4649
- * @private
4650
- */
4651
- class InvalidUnitError extends LuxonError {
4652
- constructor(unit) {
4653
- super(`Invalid unit ${unit}`);
4654
- }
4672
+ function hackyOffset(dtf, date) {
4673
+ const formatted = dtf.format(date).replace(/\u200E/g, ""),
4674
+ parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted),
4675
+ [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed;
4676
+ return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
4655
4677
  }
4656
4678
 
4657
- /**
4658
- * @private
4659
- */
4660
- class InvalidArgumentError extends LuxonError {}
4679
+ function partsOffset(dtf, date) {
4680
+ const formatted = dtf.formatToParts(date);
4681
+ const filled = [];
4682
+ for (let i = 0; i < formatted.length; i++) {
4683
+ const { type, value } = formatted[i];
4684
+ const pos = typeToPos[type];
4661
4685
 
4662
- /**
4663
- * @private
4664
- */
4665
- class ZoneIsAbstractError extends LuxonError {
4666
- constructor() {
4667
- super("Zone is an abstract class");
4686
+ if (type === "era") {
4687
+ filled[pos] = value;
4688
+ } else if (!isUndefined(pos)) {
4689
+ filled[pos] = parseInt(value, 10);
4690
+ }
4668
4691
  }
4692
+ return filled;
4669
4693
  }
4670
4694
 
4695
+ const ianaZoneCache = new Map();
4671
4696
  /**
4672
- * @private
4697
+ * A zone identified by an IANA identifier, like America/New_York
4698
+ * @implements {Zone}
4673
4699
  */
4700
+ class IANAZone extends Zone {
4701
+ /**
4702
+ * @param {string} name - Zone name
4703
+ * @return {IANAZone}
4704
+ */
4705
+ static create(name) {
4706
+ let zone = ianaZoneCache.get(name);
4707
+ if (zone === undefined) {
4708
+ ianaZoneCache.set(name, (zone = new IANAZone(name)));
4709
+ }
4710
+ return zone;
4711
+ }
4674
4712
 
4675
- const n$1 = "numeric",
4676
- s$2 = "short",
4677
- l$1 = "long";
4678
-
4679
- const DATE_SHORT = {
4680
- year: n$1,
4681
- month: n$1,
4682
- day: n$1,
4683
- };
4684
-
4685
- const DATE_MED = {
4686
- year: n$1,
4687
- month: s$2,
4688
- day: n$1,
4689
- };
4690
-
4691
- const DATE_MED_WITH_WEEKDAY = {
4692
- year: n$1,
4693
- month: s$2,
4694
- day: n$1,
4695
- weekday: s$2,
4696
- };
4697
-
4698
- const DATE_FULL = {
4699
- year: n$1,
4700
- month: l$1,
4701
- day: n$1,
4702
- };
4703
-
4704
- const DATE_HUGE = {
4705
- year: n$1,
4706
- month: l$1,
4707
- day: n$1,
4708
- weekday: l$1,
4709
- };
4710
-
4711
- const TIME_SIMPLE = {
4712
- hour: n$1,
4713
- minute: n$1,
4714
- };
4715
-
4716
- const TIME_WITH_SECONDS = {
4717
- hour: n$1,
4718
- minute: n$1,
4719
- second: n$1,
4720
- };
4721
-
4722
- const TIME_WITH_SHORT_OFFSET = {
4723
- hour: n$1,
4724
- minute: n$1,
4725
- second: n$1,
4726
- timeZoneName: s$2,
4727
- };
4728
-
4729
- const TIME_WITH_LONG_OFFSET = {
4730
- hour: n$1,
4731
- minute: n$1,
4732
- second: n$1,
4733
- timeZoneName: l$1,
4734
- };
4735
-
4736
- const TIME_24_SIMPLE = {
4737
- hour: n$1,
4738
- minute: n$1,
4739
- hourCycle: "h23",
4740
- };
4741
-
4742
- const TIME_24_WITH_SECONDS = {
4743
- hour: n$1,
4744
- minute: n$1,
4745
- second: n$1,
4746
- hourCycle: "h23",
4747
- };
4748
-
4749
- const TIME_24_WITH_SHORT_OFFSET = {
4750
- hour: n$1,
4751
- minute: n$1,
4752
- second: n$1,
4753
- hourCycle: "h23",
4754
- timeZoneName: s$2,
4755
- };
4756
-
4757
- const TIME_24_WITH_LONG_OFFSET = {
4758
- hour: n$1,
4759
- minute: n$1,
4760
- second: n$1,
4761
- hourCycle: "h23",
4762
- timeZoneName: l$1,
4763
- };
4764
-
4765
- const DATETIME_SHORT = {
4766
- year: n$1,
4767
- month: n$1,
4768
- day: n$1,
4769
- hour: n$1,
4770
- minute: n$1,
4771
- };
4772
-
4773
- const DATETIME_SHORT_WITH_SECONDS = {
4774
- year: n$1,
4775
- month: n$1,
4776
- day: n$1,
4777
- hour: n$1,
4778
- minute: n$1,
4779
- second: n$1,
4780
- };
4781
-
4782
- const DATETIME_MED = {
4783
- year: n$1,
4784
- month: s$2,
4785
- day: n$1,
4786
- hour: n$1,
4787
- minute: n$1,
4788
- };
4789
-
4790
- const DATETIME_MED_WITH_SECONDS = {
4791
- year: n$1,
4792
- month: s$2,
4793
- day: n$1,
4794
- hour: n$1,
4795
- minute: n$1,
4796
- second: n$1,
4797
- };
4798
-
4799
- const DATETIME_MED_WITH_WEEKDAY = {
4800
- year: n$1,
4801
- month: s$2,
4802
- day: n$1,
4803
- weekday: s$2,
4804
- hour: n$1,
4805
- minute: n$1,
4806
- };
4807
-
4808
- const DATETIME_FULL = {
4809
- year: n$1,
4810
- month: l$1,
4811
- day: n$1,
4812
- hour: n$1,
4813
- minute: n$1,
4814
- timeZoneName: s$2,
4815
- };
4816
-
4817
- const DATETIME_FULL_WITH_SECONDS = {
4818
- year: n$1,
4819
- month: l$1,
4820
- day: n$1,
4821
- hour: n$1,
4822
- minute: n$1,
4823
- second: n$1,
4824
- timeZoneName: s$2,
4825
- };
4826
-
4827
- const DATETIME_HUGE = {
4828
- year: n$1,
4829
- month: l$1,
4830
- day: n$1,
4831
- weekday: l$1,
4832
- hour: n$1,
4833
- minute: n$1,
4834
- timeZoneName: l$1,
4835
- };
4713
+ /**
4714
+ * Reset local caches. Should only be necessary in testing scenarios.
4715
+ * @return {void}
4716
+ */
4717
+ static resetCache() {
4718
+ ianaZoneCache.clear();
4719
+ dtfCache.clear();
4720
+ }
4836
4721
 
4837
- const DATETIME_HUGE_WITH_SECONDS = {
4838
- year: n$1,
4839
- month: l$1,
4840
- day: n$1,
4841
- weekday: l$1,
4842
- hour: n$1,
4843
- minute: n$1,
4844
- second: n$1,
4845
- timeZoneName: l$1,
4846
- };
4722
+ /**
4723
+ * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
4724
+ * @param {string} s - The string to check validity on
4725
+ * @example IANAZone.isValidSpecifier("America/New_York") //=> true
4726
+ * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
4727
+ * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
4728
+ * @return {boolean}
4729
+ */
4730
+ static isValidSpecifier(s) {
4731
+ return this.isValidZone(s);
4732
+ }
4847
4733
 
4848
- /**
4849
- * @interface
4850
- */
4851
- class Zone {
4852
4734
  /**
4853
- * The type of zone
4854
- * @abstract
4855
- * @type {string}
4735
+ * Returns whether the provided string identifies a real zone
4736
+ * @param {string} zone - The string to check
4737
+ * @example IANAZone.isValidZone("America/New_York") //=> true
4738
+ * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
4739
+ * @example IANAZone.isValidZone("Sport~~blorp") //=> false
4740
+ * @return {boolean}
4856
4741
  */
4857
- get type() {
4858
- throw new ZoneIsAbstractError();
4742
+ static isValidZone(zone) {
4743
+ if (!zone) {
4744
+ return false;
4745
+ }
4746
+ try {
4747
+ new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
4748
+ return true;
4749
+ } catch (e) {
4750
+ return false;
4751
+ }
4752
+ }
4753
+
4754
+ constructor(name) {
4755
+ super();
4756
+ /** @private **/
4757
+ this.zoneName = name;
4758
+ /** @private **/
4759
+ this.valid = IANAZone.isValidZone(name);
4859
4760
  }
4860
4761
 
4861
4762
  /**
4862
- * The name of this zone.
4863
- * @abstract
4763
+ * The type of zone. `iana` for all instances of `IANAZone`.
4764
+ * @override
4864
4765
  * @type {string}
4865
4766
  */
4866
- get name() {
4867
- throw new ZoneIsAbstractError();
4767
+ get type() {
4768
+ return "iana";
4868
4769
  }
4869
4770
 
4870
4771
  /**
4871
- * The IANA name of this zone.
4872
- * Defaults to `name` if not overwritten by a subclass.
4873
- * @abstract
4772
+ * The name of this zone (i.e. the IANA zone name).
4773
+ * @override
4874
4774
  * @type {string}
4875
4775
  */
4876
- get ianaName() {
4877
- return this.name;
4776
+ get name() {
4777
+ return this.zoneName;
4878
4778
  }
4879
4779
 
4880
4780
  /**
4881
- * Returns whether the offset is known to be fixed for the whole year.
4882
- * @abstract
4781
+ * Returns whether the offset is known to be fixed for the whole year:
4782
+ * Always returns false for all IANA zones.
4783
+ * @override
4883
4784
  * @type {boolean}
4884
4785
  */
4885
4786
  get isUniversal() {
4886
- throw new ZoneIsAbstractError();
4787
+ return false;
4887
4788
  }
4888
4789
 
4889
4790
  /**
4890
4791
  * Returns the offset's common name (such as EST) at the specified timestamp
4891
- * @abstract
4792
+ * @override
4892
4793
  * @param {number} ts - Epoch milliseconds for which to get the name
4893
4794
  * @param {Object} opts - Options to affect the format
4894
4795
  * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
4895
4796
  * @param {string} opts.locale - What locale to return the offset name in.
4896
4797
  * @return {string}
4897
4798
  */
4898
- offsetName(ts, opts) {
4899
- throw new ZoneIsAbstractError();
4799
+ offsetName(ts, { format, locale }) {
4800
+ return parseZoneInfo(ts, format, locale, this.name);
4900
4801
  }
4901
4802
 
4902
4803
  /**
4903
4804
  * Returns the offset's value as a string
4904
- * @abstract
4805
+ * @override
4905
4806
  * @param {number} ts - Epoch milliseconds for which to get the offset
4906
4807
  * @param {string} format - What style of offset to return.
4907
4808
  * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
4908
4809
  * @return {string}
4909
4810
  */
4910
4811
  formatOffset(ts, format) {
4911
- throw new ZoneIsAbstractError();
4812
+ return formatOffset(this.offset(ts), format);
4912
4813
  }
4913
4814
 
4914
4815
  /**
4915
4816
  * Return the offset in minutes for this zone at the specified timestamp.
4916
- * @abstract
4817
+ * @override
4917
4818
  * @param {number} ts - Epoch milliseconds for which to compute the offset
4918
4819
  * @return {number}
4919
4820
  */
4920
4821
  offset(ts) {
4921
- throw new ZoneIsAbstractError();
4822
+ if (!this.valid) return NaN;
4823
+ const date = new Date(ts);
4824
+
4825
+ if (isNaN(date)) return NaN;
4826
+
4827
+ const dtf = makeDTF(this.name);
4828
+ let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts
4829
+ ? partsOffset(dtf, date)
4830
+ : hackyOffset(dtf, date);
4831
+
4832
+ if (adOrBc === "BC") {
4833
+ year = -Math.abs(year) + 1;
4834
+ }
4835
+
4836
+ // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
4837
+ const adjustedHour = hour === 24 ? 0 : hour;
4838
+
4839
+ const asUTC = objToLocalTS({
4840
+ year,
4841
+ month,
4842
+ day,
4843
+ hour: adjustedHour,
4844
+ minute,
4845
+ second,
4846
+ millisecond: 0,
4847
+ });
4848
+
4849
+ let asTS = +date;
4850
+ const over = asTS % 1000;
4851
+ asTS -= over >= 0 ? over : 1000 + over;
4852
+ return (asUTC - asTS) / (60 * 1000);
4922
4853
  }
4923
4854
 
4924
4855
  /**
4925
4856
  * Return whether this Zone is equal to another zone
4926
- * @abstract
4857
+ * @override
4927
4858
  * @param {Zone} otherZone - the zone to compare
4928
4859
  * @return {boolean}
4929
4860
  */
4930
4861
  equals(otherZone) {
4931
- throw new ZoneIsAbstractError();
4862
+ return otherZone.type === "iana" && otherZone.name === this.name;
4932
4863
  }
4933
4864
 
4934
4865
  /**
4935
4866
  * Return whether this Zone is valid.
4936
- * @abstract
4867
+ * @override
4937
4868
  * @type {boolean}
4938
4869
  */
4939
4870
  get isValid() {
4940
- throw new ZoneIsAbstractError();
4871
+ return this.valid;
4941
4872
  }
4942
4873
  }
4943
4874
 
4944
- let singleton$1 = null;
4875
+ // todo - remap caching
4945
4876
 
4946
- /**
4947
- * Represents the local zone for this JavaScript environment.
4948
- * @implements {Zone}
4949
- */
4950
- class SystemZone extends Zone {
4951
- /**
4952
- * Get a singleton instance of the local zone
4953
- * @return {SystemZone}
4954
- */
4955
- static get instance() {
4956
- if (singleton$1 === null) {
4957
- singleton$1 = new SystemZone();
4958
- }
4959
- return singleton$1;
4877
+ let intlLFCache = {};
4878
+ function getCachedLF(locString, opts = {}) {
4879
+ const key = JSON.stringify([locString, opts]);
4880
+ let dtf = intlLFCache[key];
4881
+ if (!dtf) {
4882
+ dtf = new Intl.ListFormat(locString, opts);
4883
+ intlLFCache[key] = dtf;
4960
4884
  }
4885
+ return dtf;
4886
+ }
4961
4887
 
4962
- /** @override **/
4963
- get type() {
4964
- return "system";
4888
+ const intlDTCache = new Map();
4889
+ function getCachedDTF(locString, opts = {}) {
4890
+ const key = JSON.stringify([locString, opts]);
4891
+ let dtf = intlDTCache.get(key);
4892
+ if (dtf === undefined) {
4893
+ dtf = new Intl.DateTimeFormat(locString, opts);
4894
+ intlDTCache.set(key, dtf);
4965
4895
  }
4896
+ return dtf;
4897
+ }
4966
4898
 
4967
- /** @override **/
4968
- get name() {
4969
- return new Intl.DateTimeFormat().resolvedOptions().timeZone;
4899
+ const intlNumCache = new Map();
4900
+ function getCachedINF(locString, opts = {}) {
4901
+ const key = JSON.stringify([locString, opts]);
4902
+ let inf = intlNumCache.get(key);
4903
+ if (inf === undefined) {
4904
+ inf = new Intl.NumberFormat(locString, opts);
4905
+ intlNumCache.set(key, inf);
4970
4906
  }
4907
+ return inf;
4908
+ }
4971
4909
 
4972
- /** @override **/
4973
- get isUniversal() {
4974
- return false;
4910
+ const intlRelCache = new Map();
4911
+ function getCachedRTF(locString, opts = {}) {
4912
+ const { base, ...cacheKeyOpts } = opts; // exclude `base` from the options
4913
+ const key = JSON.stringify([locString, cacheKeyOpts]);
4914
+ let inf = intlRelCache.get(key);
4915
+ if (inf === undefined) {
4916
+ inf = new Intl.RelativeTimeFormat(locString, opts);
4917
+ intlRelCache.set(key, inf);
4975
4918
  }
4919
+ return inf;
4920
+ }
4976
4921
 
4977
- /** @override **/
4978
- offsetName(ts, { format, locale }) {
4979
- return parseZoneInfo(ts, format, locale);
4922
+ let sysLocaleCache = null;
4923
+ function systemLocale() {
4924
+ if (sysLocaleCache) {
4925
+ return sysLocaleCache;
4926
+ } else {
4927
+ sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
4928
+ return sysLocaleCache;
4980
4929
  }
4930
+ }
4981
4931
 
4982
- /** @override **/
4983
- formatOffset(ts, format) {
4984
- return formatOffset(this.offset(ts), format);
4932
+ const intlResolvedOptionsCache = new Map();
4933
+ function getCachedIntResolvedOptions(locString) {
4934
+ let opts = intlResolvedOptionsCache.get(locString);
4935
+ if (opts === undefined) {
4936
+ opts = new Intl.DateTimeFormat(locString).resolvedOptions();
4937
+ intlResolvedOptionsCache.set(locString, opts);
4985
4938
  }
4939
+ return opts;
4940
+ }
4986
4941
 
4987
- /** @override **/
4988
- offset(ts) {
4989
- return -new Date(ts).getTimezoneOffset();
4942
+ const weekInfoCache = new Map();
4943
+ function getCachedWeekInfo(locString) {
4944
+ let data = weekInfoCache.get(locString);
4945
+ if (!data) {
4946
+ const locale = new Intl.Locale(locString);
4947
+ // browsers currently implement this as a property, but spec says it should be a getter function
4948
+ data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
4949
+ // minimalDays was removed from WeekInfo: https://github.com/tc39/proposal-intl-locale-info/issues/86
4950
+ if (!("minimalDays" in data)) {
4951
+ data = { ...fallbackWeekSettings, ...data };
4952
+ }
4953
+ weekInfoCache.set(locString, data);
4990
4954
  }
4955
+ return data;
4956
+ }
4991
4957
 
4992
- /** @override **/
4993
- equals(otherZone) {
4994
- return otherZone.type === "system";
4995
- }
4958
+ function parseLocaleString(localeStr) {
4959
+ // I really want to avoid writing a BCP 47 parser
4960
+ // see, e.g. https://github.com/wooorm/bcp-47
4961
+ // Instead, we'll do this:
4996
4962
 
4997
- /** @override **/
4998
- get isValid() {
4999
- return true;
5000
- }
5001
- }
4963
+ // a) if the string has no -u extensions, just leave it alone
4964
+ // b) if it does, use Intl to resolve everything
4965
+ // c) if Intl fails, try again without the -u
5002
4966
 
5003
- const dtfCache = new Map();
5004
- function makeDTF(zoneName) {
5005
- let dtf = dtfCache.get(zoneName);
5006
- if (dtf === undefined) {
5007
- dtf = new Intl.DateTimeFormat("en-US", {
5008
- hour12: false,
5009
- timeZone: zoneName,
5010
- year: "numeric",
5011
- month: "2-digit",
5012
- day: "2-digit",
5013
- hour: "2-digit",
5014
- minute: "2-digit",
5015
- second: "2-digit",
5016
- era: "short",
5017
- });
5018
- dtfCache.set(zoneName, dtf);
4967
+ // private subtags and unicode subtags have ordering requirements,
4968
+ // and we're not properly parsing this, so just strip out the
4969
+ // private ones if they exist.
4970
+ const xIndex = localeStr.indexOf("-x-");
4971
+ if (xIndex !== -1) {
4972
+ localeStr = localeStr.substring(0, xIndex);
5019
4973
  }
5020
- return dtf;
5021
- }
5022
4974
 
5023
- const typeToPos = {
5024
- year: 0,
5025
- month: 1,
5026
- day: 2,
5027
- era: 3,
5028
- hour: 4,
5029
- minute: 5,
5030
- second: 6,
5031
- };
4975
+ const uIndex = localeStr.indexOf("-u-");
4976
+ if (uIndex === -1) {
4977
+ return [localeStr];
4978
+ } else {
4979
+ let options;
4980
+ let selectedStr;
4981
+ try {
4982
+ options = getCachedDTF(localeStr).resolvedOptions();
4983
+ selectedStr = localeStr;
4984
+ } catch (e) {
4985
+ const smaller = localeStr.substring(0, uIndex);
4986
+ options = getCachedDTF(smaller).resolvedOptions();
4987
+ selectedStr = smaller;
4988
+ }
5032
4989
 
5033
- function hackyOffset(dtf, date) {
5034
- const formatted = dtf.format(date).replace(/\u200E/g, ""),
5035
- parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted),
5036
- [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed;
5037
- return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
4990
+ const { numberingSystem, calendar } = options;
4991
+ return [selectedStr, numberingSystem, calendar];
4992
+ }
5038
4993
  }
5039
4994
 
5040
- function partsOffset(dtf, date) {
5041
- const formatted = dtf.formatToParts(date);
5042
- const filled = [];
5043
- for (let i = 0; i < formatted.length; i++) {
5044
- const { type, value } = formatted[i];
5045
- const pos = typeToPos[type];
4995
+ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
4996
+ if (outputCalendar || numberingSystem) {
4997
+ if (!localeStr.includes("-u-")) {
4998
+ localeStr += "-u";
4999
+ }
5046
5000
 
5047
- if (type === "era") {
5048
- filled[pos] = value;
5049
- } else if (!isUndefined(pos)) {
5050
- filled[pos] = parseInt(value, 10);
5001
+ if (outputCalendar) {
5002
+ localeStr += `-ca-${outputCalendar}`;
5003
+ }
5004
+
5005
+ if (numberingSystem) {
5006
+ localeStr += `-nu-${numberingSystem}`;
5051
5007
  }
5008
+ return localeStr;
5009
+ } else {
5010
+ return localeStr;
5052
5011
  }
5053
- return filled;
5054
5012
  }
5055
5013
 
5056
- const ianaZoneCache = new Map();
5057
- /**
5058
- * A zone identified by an IANA identifier, like America/New_York
5059
- * @implements {Zone}
5060
- */
5061
- class IANAZone extends Zone {
5062
- /**
5063
- * @param {string} name - Zone name
5064
- * @return {IANAZone}
5065
- */
5066
- static create(name) {
5067
- let zone = ianaZoneCache.get(name);
5068
- if (zone === undefined) {
5069
- ianaZoneCache.set(name, (zone = new IANAZone(name)));
5070
- }
5071
- return zone;
5014
+ function mapMonths(f) {
5015
+ const ms = [];
5016
+ for (let i = 1; i <= 12; i++) {
5017
+ const dt = DateTime.utc(2009, i, 1);
5018
+ ms.push(f(dt));
5072
5019
  }
5020
+ return ms;
5021
+ }
5073
5022
 
5074
- /**
5075
- * Reset local caches. Should only be necessary in testing scenarios.
5076
- * @return {void}
5077
- */
5078
- static resetCache() {
5079
- ianaZoneCache.clear();
5080
- dtfCache.clear();
5023
+ function mapWeekdays(f) {
5024
+ const ms = [];
5025
+ for (let i = 1; i <= 7; i++) {
5026
+ const dt = DateTime.utc(2016, 11, 13 + i);
5027
+ ms.push(f(dt));
5081
5028
  }
5029
+ return ms;
5030
+ }
5082
5031
 
5083
- /**
5084
- * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
5085
- * @param {string} s - The string to check validity on
5086
- * @example IANAZone.isValidSpecifier("America/New_York") //=> true
5087
- * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
5088
- * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
5089
- * @return {boolean}
5090
- */
5091
- static isValidSpecifier(s) {
5092
- return this.isValidZone(s);
5093
- }
5032
+ function listStuff(loc, length, englishFn, intlFn) {
5033
+ const mode = loc.listingMode();
5094
5034
 
5095
- /**
5096
- * Returns whether the provided string identifies a real zone
5097
- * @param {string} zone - The string to check
5098
- * @example IANAZone.isValidZone("America/New_York") //=> true
5099
- * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
5100
- * @example IANAZone.isValidZone("Sport~~blorp") //=> false
5101
- * @return {boolean}
5102
- */
5103
- static isValidZone(zone) {
5104
- if (!zone) {
5105
- return false;
5106
- }
5107
- try {
5108
- new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
5109
- return true;
5110
- } catch (e) {
5111
- return false;
5112
- }
5035
+ if (mode === "error") {
5036
+ return null;
5037
+ } else if (mode === "en") {
5038
+ return englishFn(length);
5039
+ } else {
5040
+ return intlFn(length);
5113
5041
  }
5042
+ }
5114
5043
 
5115
- constructor(name) {
5116
- super();
5117
- /** @private **/
5118
- this.zoneName = name;
5119
- /** @private **/
5120
- this.valid = IANAZone.isValidZone(name);
5044
+ function supportsFastNumbers(loc) {
5045
+ if (loc.numberingSystem && loc.numberingSystem !== "latn") {
5046
+ return false;
5047
+ } else {
5048
+ return (
5049
+ loc.numberingSystem === "latn" ||
5050
+ !loc.locale ||
5051
+ loc.locale.startsWith("en") ||
5052
+ getCachedIntResolvedOptions(loc.locale).numberingSystem === "latn"
5053
+ );
5121
5054
  }
5055
+ }
5122
5056
 
5123
- /**
5124
- * The type of zone. `iana` for all instances of `IANAZone`.
5125
- * @override
5126
- * @type {string}
5127
- */
5128
- get type() {
5129
- return "iana";
5130
- }
5057
+ /**
5058
+ * @private
5059
+ */
5131
5060
 
5132
- /**
5133
- * The name of this zone (i.e. the IANA zone name).
5134
- * @override
5135
- * @type {string}
5136
- */
5137
- get name() {
5138
- return this.zoneName;
5139
- }
5061
+ class PolyNumberFormatter {
5062
+ constructor(intl, forceSimple, opts) {
5063
+ this.padTo = opts.padTo || 0;
5064
+ this.floor = opts.floor || false;
5140
5065
 
5141
- /**
5142
- * Returns whether the offset is known to be fixed for the whole year:
5143
- * Always returns false for all IANA zones.
5144
- * @override
5145
- * @type {boolean}
5146
- */
5147
- get isUniversal() {
5148
- return false;
5149
- }
5066
+ const { padTo, floor, ...otherOpts } = opts;
5150
5067
 
5151
- /**
5152
- * Returns the offset's common name (such as EST) at the specified timestamp
5153
- * @override
5154
- * @param {number} ts - Epoch milliseconds for which to get the name
5155
- * @param {Object} opts - Options to affect the format
5156
- * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
5157
- * @param {string} opts.locale - What locale to return the offset name in.
5158
- * @return {string}
5159
- */
5160
- offsetName(ts, { format, locale }) {
5161
- return parseZoneInfo(ts, format, locale, this.name);
5068
+ if (!forceSimple || Object.keys(otherOpts).length > 0) {
5069
+ const intlOpts = { useGrouping: false, ...opts };
5070
+ if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
5071
+ this.inf = getCachedINF(intl, intlOpts);
5072
+ }
5162
5073
  }
5163
5074
 
5164
- /**
5165
- * Returns the offset's value as a string
5166
- * @override
5167
- * @param {number} ts - Epoch milliseconds for which to get the offset
5168
- * @param {string} format - What style of offset to return.
5169
- * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
5170
- * @return {string}
5171
- */
5172
- formatOffset(ts, format) {
5173
- return formatOffset(this.offset(ts), format);
5075
+ format(i) {
5076
+ if (this.inf) {
5077
+ const fixed = this.floor ? Math.floor(i) : i;
5078
+ return this.inf.format(fixed);
5079
+ } else {
5080
+ // to match the browser's numberformatter defaults
5081
+ const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
5082
+ return padStart(fixed, this.padTo);
5083
+ }
5174
5084
  }
5085
+ }
5175
5086
 
5176
- /**
5177
- * Return the offset in minutes for this zone at the specified timestamp.
5178
- * @override
5179
- * @param {number} ts - Epoch milliseconds for which to compute the offset
5180
- * @return {number}
5181
- */
5182
- offset(ts) {
5183
- if (!this.valid) return NaN;
5184
- const date = new Date(ts);
5185
-
5186
- if (isNaN(date)) return NaN;
5087
+ /**
5088
+ * @private
5089
+ */
5187
5090
 
5188
- const dtf = makeDTF(this.name);
5189
- let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts
5190
- ? partsOffset(dtf, date)
5191
- : hackyOffset(dtf, date);
5091
+ class PolyDateFormatter {
5092
+ constructor(dt, intl, opts) {
5093
+ this.opts = opts;
5094
+ this.originalZone = undefined;
5192
5095
 
5193
- if (adOrBc === "BC") {
5194
- year = -Math.abs(year) + 1;
5096
+ let z = undefined;
5097
+ if (this.opts.timeZone) {
5098
+ // Don't apply any workarounds if a timeZone is explicitly provided in opts
5099
+ this.dt = dt;
5100
+ } else if (dt.zone.type === "fixed") {
5101
+ // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
5102
+ // That is why fixed-offset TZ is set to that unless it is:
5103
+ // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
5104
+ // 2. Unsupported by the browser:
5105
+ // - some do not support Etc/
5106
+ // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
5107
+ const gmtOffset = -1 * (dt.offset / 60);
5108
+ const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
5109
+ if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
5110
+ z = offsetZ;
5111
+ this.dt = dt;
5112
+ } else {
5113
+ // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
5114
+ // we manually apply the offset and substitute the zone as needed.
5115
+ z = "UTC";
5116
+ this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
5117
+ this.originalZone = dt.zone;
5118
+ }
5119
+ } else if (dt.zone.type === "system") {
5120
+ this.dt = dt;
5121
+ } else if (dt.zone.type === "iana") {
5122
+ this.dt = dt;
5123
+ z = dt.zone.name;
5124
+ } else {
5125
+ // Custom zones can have any offset / offsetName so we just manually
5126
+ // apply the offset and substitute the zone as needed.
5127
+ z = "UTC";
5128
+ this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
5129
+ this.originalZone = dt.zone;
5195
5130
  }
5196
5131
 
5197
- // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
5198
- const adjustedHour = hour === 24 ? 0 : hour;
5199
-
5200
- const asUTC = objToLocalTS({
5201
- year,
5202
- month,
5203
- day,
5204
- hour: adjustedHour,
5205
- minute,
5206
- second,
5207
- millisecond: 0,
5208
- });
5209
-
5210
- let asTS = +date;
5211
- const over = asTS % 1000;
5212
- asTS -= over >= 0 ? over : 1000 + over;
5213
- return (asUTC - asTS) / (60 * 1000);
5214
- }
5215
-
5216
- /**
5217
- * Return whether this Zone is equal to another zone
5218
- * @override
5219
- * @param {Zone} otherZone - the zone to compare
5220
- * @return {boolean}
5221
- */
5222
- equals(otherZone) {
5223
- return otherZone.type === "iana" && otherZone.name === this.name;
5132
+ const intlOpts = { ...this.opts };
5133
+ intlOpts.timeZone = intlOpts.timeZone || z;
5134
+ this.dtf = getCachedDTF(intl, intlOpts);
5224
5135
  }
5225
5136
 
5226
- /**
5227
- * Return whether this Zone is valid.
5228
- * @override
5229
- * @type {boolean}
5230
- */
5231
- get isValid() {
5232
- return this.valid;
5137
+ format() {
5138
+ if (this.originalZone) {
5139
+ // If we have to substitute in the actual zone name, we have to use
5140
+ // formatToParts so that the timezone can be replaced.
5141
+ return this.formatToParts()
5142
+ .map(({ value }) => value)
5143
+ .join("");
5144
+ }
5145
+ return this.dtf.format(this.dt.toJSDate());
5233
5146
  }
5234
- }
5235
5147
 
5236
- // todo - remap caching
5148
+ formatToParts() {
5149
+ const parts = this.dtf.formatToParts(this.dt.toJSDate());
5150
+ if (this.originalZone) {
5151
+ return parts.map((part) => {
5152
+ if (part.type === "timeZoneName") {
5153
+ const offsetName = this.originalZone.offsetName(this.dt.ts, {
5154
+ locale: this.dt.locale,
5155
+ format: this.opts.timeZoneName,
5156
+ });
5157
+ return {
5158
+ ...part,
5159
+ value: offsetName,
5160
+ };
5161
+ } else {
5162
+ return part;
5163
+ }
5164
+ });
5165
+ }
5166
+ return parts;
5167
+ }
5237
5168
 
5238
- let intlLFCache = {};
5239
- function getCachedLF(locString, opts = {}) {
5240
- const key = JSON.stringify([locString, opts]);
5241
- let dtf = intlLFCache[key];
5242
- if (!dtf) {
5243
- dtf = new Intl.ListFormat(locString, opts);
5244
- intlLFCache[key] = dtf;
5169
+ resolvedOptions() {
5170
+ return this.dtf.resolvedOptions();
5245
5171
  }
5246
- return dtf;
5247
5172
  }
5248
5173
 
5249
- const intlDTCache = new Map();
5250
- function getCachedDTF(locString, opts = {}) {
5251
- const key = JSON.stringify([locString, opts]);
5252
- let dtf = intlDTCache.get(key);
5253
- if (dtf === undefined) {
5254
- dtf = new Intl.DateTimeFormat(locString, opts);
5255
- intlDTCache.set(key, dtf);
5174
+ /**
5175
+ * @private
5176
+ */
5177
+ class PolyRelFormatter {
5178
+ constructor(intl, isEnglish, opts) {
5179
+ this.opts = { style: "long", ...opts };
5180
+ if (!isEnglish && hasRelative()) {
5181
+ this.rtf = getCachedRTF(intl, opts);
5182
+ }
5256
5183
  }
5257
- return dtf;
5258
- }
5259
5184
 
5260
- const intlNumCache = new Map();
5261
- function getCachedINF(locString, opts = {}) {
5262
- const key = JSON.stringify([locString, opts]);
5263
- let inf = intlNumCache.get(key);
5264
- if (inf === undefined) {
5265
- inf = new Intl.NumberFormat(locString, opts);
5266
- intlNumCache.set(key, inf);
5185
+ format(count, unit) {
5186
+ if (this.rtf) {
5187
+ return this.rtf.format(count, unit);
5188
+ } else {
5189
+ return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
5190
+ }
5267
5191
  }
5268
- return inf;
5269
- }
5270
5192
 
5271
- const intlRelCache = new Map();
5272
- function getCachedRTF(locString, opts = {}) {
5273
- const { base, ...cacheKeyOpts } = opts; // exclude `base` from the options
5274
- const key = JSON.stringify([locString, cacheKeyOpts]);
5275
- let inf = intlRelCache.get(key);
5276
- if (inf === undefined) {
5277
- inf = new Intl.RelativeTimeFormat(locString, opts);
5278
- intlRelCache.set(key, inf);
5193
+ formatToParts(count, unit) {
5194
+ if (this.rtf) {
5195
+ return this.rtf.formatToParts(count, unit);
5196
+ } else {
5197
+ return [];
5198
+ }
5279
5199
  }
5280
- return inf;
5281
5200
  }
5282
5201
 
5283
- let sysLocaleCache = null;
5284
- function systemLocale() {
5285
- if (sysLocaleCache) {
5286
- return sysLocaleCache;
5287
- } else {
5288
- sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
5289
- return sysLocaleCache;
5202
+ const fallbackWeekSettings = {
5203
+ firstDay: 1,
5204
+ minimalDays: 4,
5205
+ weekend: [6, 7],
5206
+ };
5207
+
5208
+ /**
5209
+ * @private
5210
+ */
5211
+ class Locale {
5212
+ static fromOpts(opts) {
5213
+ return Locale.create(
5214
+ opts.locale,
5215
+ opts.numberingSystem,
5216
+ opts.outputCalendar,
5217
+ opts.weekSettings,
5218
+ opts.defaultToEN
5219
+ );
5290
5220
  }
5291
- }
5292
5221
 
5293
- const intlResolvedOptionsCache = new Map();
5294
- function getCachedIntResolvedOptions(locString) {
5295
- let opts = intlResolvedOptionsCache.get(locString);
5296
- if (opts === undefined) {
5297
- opts = new Intl.DateTimeFormat(locString).resolvedOptions();
5298
- intlResolvedOptionsCache.set(locString, opts);
5222
+ static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
5223
+ const specifiedLocale = locale || Settings.defaultLocale;
5224
+ // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
5225
+ const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
5226
+ const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
5227
+ const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
5228
+ const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
5229
+ return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
5299
5230
  }
5300
- return opts;
5301
- }
5302
5231
 
5303
- const weekInfoCache = new Map();
5304
- function getCachedWeekInfo(locString) {
5305
- let data = weekInfoCache.get(locString);
5306
- if (!data) {
5307
- const locale = new Intl.Locale(locString);
5308
- // browsers currently implement this as a property, but spec says it should be a getter function
5309
- data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
5310
- // minimalDays was removed from WeekInfo: https://github.com/tc39/proposal-intl-locale-info/issues/86
5311
- if (!("minimalDays" in data)) {
5312
- data = { ...fallbackWeekSettings, ...data };
5313
- }
5314
- weekInfoCache.set(locString, data);
5232
+ static resetCache() {
5233
+ sysLocaleCache = null;
5234
+ intlDTCache.clear();
5235
+ intlNumCache.clear();
5236
+ intlRelCache.clear();
5237
+ intlResolvedOptionsCache.clear();
5238
+ weekInfoCache.clear();
5315
5239
  }
5316
- return data;
5317
- }
5318
5240
 
5319
- function parseLocaleString(localeStr) {
5320
- // I really want to avoid writing a BCP 47 parser
5321
- // see, e.g. https://github.com/wooorm/bcp-47
5322
- // Instead, we'll do this:
5241
+ static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
5242
+ return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
5243
+ }
5323
5244
 
5324
- // a) if the string has no -u extensions, just leave it alone
5325
- // b) if it does, use Intl to resolve everything
5326
- // c) if Intl fails, try again without the -u
5245
+ constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
5246
+ const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
5327
5247
 
5328
- // private subtags and unicode subtags have ordering requirements,
5329
- // and we're not properly parsing this, so just strip out the
5330
- // private ones if they exist.
5331
- const xIndex = localeStr.indexOf("-x-");
5332
- if (xIndex !== -1) {
5333
- localeStr = localeStr.substring(0, xIndex);
5334
- }
5248
+ this.locale = parsedLocale;
5249
+ this.numberingSystem = numbering || parsedNumberingSystem || null;
5250
+ this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
5251
+ this.weekSettings = weekSettings;
5252
+ this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
5335
5253
 
5336
- const uIndex = localeStr.indexOf("-u-");
5337
- if (uIndex === -1) {
5338
- return [localeStr];
5339
- } else {
5340
- let options;
5341
- let selectedStr;
5342
- try {
5343
- options = getCachedDTF(localeStr).resolvedOptions();
5344
- selectedStr = localeStr;
5345
- } catch (e) {
5346
- const smaller = localeStr.substring(0, uIndex);
5347
- options = getCachedDTF(smaller).resolvedOptions();
5348
- selectedStr = smaller;
5349
- }
5254
+ this.weekdaysCache = { format: {}, standalone: {} };
5255
+ this.monthsCache = { format: {}, standalone: {} };
5256
+ this.meridiemCache = null;
5257
+ this.eraCache = {};
5350
5258
 
5351
- const { numberingSystem, calendar } = options;
5352
- return [selectedStr, numberingSystem, calendar];
5259
+ this.specifiedLocale = specifiedLocale;
5260
+ this.fastNumbersCached = null;
5353
5261
  }
5354
- }
5355
-
5356
- function intlConfigString(localeStr, numberingSystem, outputCalendar) {
5357
- if (outputCalendar || numberingSystem) {
5358
- if (!localeStr.includes("-u-")) {
5359
- localeStr += "-u";
5360
- }
5361
5262
 
5362
- if (outputCalendar) {
5363
- localeStr += `-ca-${outputCalendar}`;
5263
+ get fastNumbers() {
5264
+ if (this.fastNumbersCached == null) {
5265
+ this.fastNumbersCached = supportsFastNumbers(this);
5364
5266
  }
5365
5267
 
5366
- if (numberingSystem) {
5367
- localeStr += `-nu-${numberingSystem}`;
5368
- }
5369
- return localeStr;
5370
- } else {
5371
- return localeStr;
5268
+ return this.fastNumbersCached;
5372
5269
  }
5373
- }
5374
5270
 
5375
- function mapMonths(f) {
5376
- const ms = [];
5377
- for (let i = 1; i <= 12; i++) {
5378
- const dt = DateTime.utc(2009, i, 1);
5379
- ms.push(f(dt));
5271
+ listingMode() {
5272
+ const isActuallyEn = this.isEnglish();
5273
+ const hasNoWeirdness =
5274
+ (this.numberingSystem === null || this.numberingSystem === "latn") &&
5275
+ (this.outputCalendar === null || this.outputCalendar === "gregory");
5276
+ return isActuallyEn && hasNoWeirdness ? "en" : "intl";
5380
5277
  }
5381
- return ms;
5382
- }
5383
5278
 
5384
- function mapWeekdays(f) {
5385
- const ms = [];
5386
- for (let i = 1; i <= 7; i++) {
5387
- const dt = DateTime.utc(2016, 11, 13 + i);
5388
- ms.push(f(dt));
5279
+ clone(alts) {
5280
+ if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
5281
+ return this;
5282
+ } else {
5283
+ return Locale.create(
5284
+ alts.locale || this.specifiedLocale,
5285
+ alts.numberingSystem || this.numberingSystem,
5286
+ alts.outputCalendar || this.outputCalendar,
5287
+ validateWeekSettings(alts.weekSettings) || this.weekSettings,
5288
+ alts.defaultToEN || false
5289
+ );
5290
+ }
5389
5291
  }
5390
- return ms;
5391
- }
5392
5292
 
5393
- function listStuff(loc, length, englishFn, intlFn) {
5394
- const mode = loc.listingMode();
5293
+ redefaultToEN(alts = {}) {
5294
+ return this.clone({ ...alts, defaultToEN: true });
5295
+ }
5395
5296
 
5396
- if (mode === "error") {
5397
- return null;
5398
- } else if (mode === "en") {
5399
- return englishFn(length);
5400
- } else {
5401
- return intlFn(length);
5402
- }
5403
- }
5404
-
5405
- function supportsFastNumbers(loc) {
5406
- if (loc.numberingSystem && loc.numberingSystem !== "latn") {
5407
- return false;
5408
- } else {
5409
- return (
5410
- loc.numberingSystem === "latn" ||
5411
- !loc.locale ||
5412
- loc.locale.startsWith("en") ||
5413
- getCachedIntResolvedOptions(loc.locale).numberingSystem === "latn"
5414
- );
5415
- }
5416
- }
5417
-
5418
- /**
5419
- * @private
5420
- */
5421
-
5422
- class PolyNumberFormatter {
5423
- constructor(intl, forceSimple, opts) {
5424
- this.padTo = opts.padTo || 0;
5425
- this.floor = opts.floor || false;
5426
-
5427
- const { padTo, floor, ...otherOpts } = opts;
5428
-
5429
- if (!forceSimple || Object.keys(otherOpts).length > 0) {
5430
- const intlOpts = { useGrouping: false, ...opts };
5431
- if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
5432
- this.inf = getCachedINF(intl, intlOpts);
5433
- }
5434
- }
5435
-
5436
- format(i) {
5437
- if (this.inf) {
5438
- const fixed = this.floor ? Math.floor(i) : i;
5439
- return this.inf.format(fixed);
5440
- } else {
5441
- // to match the browser's numberformatter defaults
5442
- const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
5443
- return padStart(fixed, this.padTo);
5444
- }
5445
- }
5446
- }
5447
-
5448
- /**
5449
- * @private
5450
- */
5451
-
5452
- class PolyDateFormatter {
5453
- constructor(dt, intl, opts) {
5454
- this.opts = opts;
5455
- this.originalZone = undefined;
5456
-
5457
- let z = undefined;
5458
- if (this.opts.timeZone) {
5459
- // Don't apply any workarounds if a timeZone is explicitly provided in opts
5460
- this.dt = dt;
5461
- } else if (dt.zone.type === "fixed") {
5462
- // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
5463
- // That is why fixed-offset TZ is set to that unless it is:
5464
- // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
5465
- // 2. Unsupported by the browser:
5466
- // - some do not support Etc/
5467
- // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
5468
- const gmtOffset = -1 * (dt.offset / 60);
5469
- const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
5470
- if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
5471
- z = offsetZ;
5472
- this.dt = dt;
5473
- } else {
5474
- // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
5475
- // we manually apply the offset and substitute the zone as needed.
5476
- z = "UTC";
5477
- this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
5478
- this.originalZone = dt.zone;
5479
- }
5480
- } else if (dt.zone.type === "system") {
5481
- this.dt = dt;
5482
- } else if (dt.zone.type === "iana") {
5483
- this.dt = dt;
5484
- z = dt.zone.name;
5485
- } else {
5486
- // Custom zones can have any offset / offsetName so we just manually
5487
- // apply the offset and substitute the zone as needed.
5488
- z = "UTC";
5489
- this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
5490
- this.originalZone = dt.zone;
5491
- }
5492
-
5493
- const intlOpts = { ...this.opts };
5494
- intlOpts.timeZone = intlOpts.timeZone || z;
5495
- this.dtf = getCachedDTF(intl, intlOpts);
5496
- }
5497
-
5498
- format() {
5499
- if (this.originalZone) {
5500
- // If we have to substitute in the actual zone name, we have to use
5501
- // formatToParts so that the timezone can be replaced.
5502
- return this.formatToParts()
5503
- .map(({ value }) => value)
5504
- .join("");
5505
- }
5506
- return this.dtf.format(this.dt.toJSDate());
5507
- }
5508
-
5509
- formatToParts() {
5510
- const parts = this.dtf.formatToParts(this.dt.toJSDate());
5511
- if (this.originalZone) {
5512
- return parts.map((part) => {
5513
- if (part.type === "timeZoneName") {
5514
- const offsetName = this.originalZone.offsetName(this.dt.ts, {
5515
- locale: this.dt.locale,
5516
- format: this.opts.timeZoneName,
5517
- });
5518
- return {
5519
- ...part,
5520
- value: offsetName,
5521
- };
5522
- } else {
5523
- return part;
5524
- }
5525
- });
5526
- }
5527
- return parts;
5528
- }
5529
-
5530
- resolvedOptions() {
5531
- return this.dtf.resolvedOptions();
5532
- }
5533
- }
5534
-
5535
- /**
5536
- * @private
5537
- */
5538
- class PolyRelFormatter {
5539
- constructor(intl, isEnglish, opts) {
5540
- this.opts = { style: "long", ...opts };
5541
- if (!isEnglish && hasRelative()) {
5542
- this.rtf = getCachedRTF(intl, opts);
5543
- }
5544
- }
5545
-
5546
- format(count, unit) {
5547
- if (this.rtf) {
5548
- return this.rtf.format(count, unit);
5549
- } else {
5550
- return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
5551
- }
5552
- }
5553
-
5554
- formatToParts(count, unit) {
5555
- if (this.rtf) {
5556
- return this.rtf.formatToParts(count, unit);
5557
- } else {
5558
- return [];
5559
- }
5560
- }
5561
- }
5562
-
5563
- const fallbackWeekSettings = {
5564
- firstDay: 1,
5565
- minimalDays: 4,
5566
- weekend: [6, 7],
5567
- };
5568
-
5569
- /**
5570
- * @private
5571
- */
5572
- class Locale {
5573
- static fromOpts(opts) {
5574
- return Locale.create(
5575
- opts.locale,
5576
- opts.numberingSystem,
5577
- opts.outputCalendar,
5578
- opts.weekSettings,
5579
- opts.defaultToEN
5580
- );
5581
- }
5582
-
5583
- static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
5584
- const specifiedLocale = locale || Settings.defaultLocale;
5585
- // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
5586
- const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
5587
- const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
5588
- const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
5589
- const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
5590
- return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
5591
- }
5592
-
5593
- static resetCache() {
5594
- sysLocaleCache = null;
5595
- intlDTCache.clear();
5596
- intlNumCache.clear();
5597
- intlRelCache.clear();
5598
- intlResolvedOptionsCache.clear();
5599
- weekInfoCache.clear();
5600
- }
5601
-
5602
- static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
5603
- return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
5604
- }
5605
-
5606
- constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
5607
- const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
5608
-
5609
- this.locale = parsedLocale;
5610
- this.numberingSystem = numbering || parsedNumberingSystem || null;
5611
- this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
5612
- this.weekSettings = weekSettings;
5613
- this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
5614
-
5615
- this.weekdaysCache = { format: {}, standalone: {} };
5616
- this.monthsCache = { format: {}, standalone: {} };
5617
- this.meridiemCache = null;
5618
- this.eraCache = {};
5619
-
5620
- this.specifiedLocale = specifiedLocale;
5621
- this.fastNumbersCached = null;
5622
- }
5623
-
5624
- get fastNumbers() {
5625
- if (this.fastNumbersCached == null) {
5626
- this.fastNumbersCached = supportsFastNumbers(this);
5627
- }
5628
-
5629
- return this.fastNumbersCached;
5630
- }
5631
-
5632
- listingMode() {
5633
- const isActuallyEn = this.isEnglish();
5634
- const hasNoWeirdness =
5635
- (this.numberingSystem === null || this.numberingSystem === "latn") &&
5636
- (this.outputCalendar === null || this.outputCalendar === "gregory");
5637
- return isActuallyEn && hasNoWeirdness ? "en" : "intl";
5638
- }
5639
-
5640
- clone(alts) {
5641
- if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
5642
- return this;
5643
- } else {
5644
- return Locale.create(
5645
- alts.locale || this.specifiedLocale,
5646
- alts.numberingSystem || this.numberingSystem,
5647
- alts.outputCalendar || this.outputCalendar,
5648
- validateWeekSettings(alts.weekSettings) || this.weekSettings,
5649
- alts.defaultToEN || false
5650
- );
5651
- }
5652
- }
5653
-
5654
- redefaultToEN(alts = {}) {
5655
- return this.clone({ ...alts, defaultToEN: true });
5656
- }
5657
-
5658
- redefaultToSystem(alts = {}) {
5659
- return this.clone({ ...alts, defaultToEN: false });
5297
+ redefaultToSystem(alts = {}) {
5298
+ return this.clone({ ...alts, defaultToEN: false });
5660
5299
  }
5661
5300
 
5662
5301
  months(length, format = false) {
@@ -12581,158 +12220,542 @@ class DateTime {
12581
12220
  return DATE_HUGE;
12582
12221
  }
12583
12222
 
12584
- /**
12585
- * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
12586
- * @type {Object}
12587
- */
12588
- static get TIME_SIMPLE() {
12589
- return TIME_SIMPLE;
12590
- }
12223
+ /**
12224
+ * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
12225
+ * @type {Object}
12226
+ */
12227
+ static get TIME_SIMPLE() {
12228
+ return TIME_SIMPLE;
12229
+ }
12230
+
12231
+ /**
12232
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
12233
+ * @type {Object}
12234
+ */
12235
+ static get TIME_WITH_SECONDS() {
12236
+ return TIME_WITH_SECONDS;
12237
+ }
12238
+
12239
+ /**
12240
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
12241
+ * @type {Object}
12242
+ */
12243
+ static get TIME_WITH_SHORT_OFFSET() {
12244
+ return TIME_WITH_SHORT_OFFSET;
12245
+ }
12246
+
12247
+ /**
12248
+ * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12249
+ * @type {Object}
12250
+ */
12251
+ static get TIME_WITH_LONG_OFFSET() {
12252
+ return TIME_WITH_LONG_OFFSET;
12253
+ }
12254
+
12255
+ /**
12256
+ * {@link DateTime#toLocaleString} format like '09:30', always 24-hour.
12257
+ * @type {Object}
12258
+ */
12259
+ static get TIME_24_SIMPLE() {
12260
+ return TIME_24_SIMPLE;
12261
+ }
12262
+
12263
+ /**
12264
+ * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
12265
+ * @type {Object}
12266
+ */
12267
+ static get TIME_24_WITH_SECONDS() {
12268
+ return TIME_24_WITH_SECONDS;
12269
+ }
12270
+
12271
+ /**
12272
+ * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour.
12273
+ * @type {Object}
12274
+ */
12275
+ static get TIME_24_WITH_SHORT_OFFSET() {
12276
+ return TIME_24_WITH_SHORT_OFFSET;
12277
+ }
12278
+
12279
+ /**
12280
+ * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
12281
+ * @type {Object}
12282
+ */
12283
+ static get TIME_24_WITH_LONG_OFFSET() {
12284
+ return TIME_24_WITH_LONG_OFFSET;
12285
+ }
12286
+
12287
+ /**
12288
+ * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
12289
+ * @type {Object}
12290
+ */
12291
+ static get DATETIME_SHORT() {
12292
+ return DATETIME_SHORT;
12293
+ }
12294
+
12295
+ /**
12296
+ * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
12297
+ * @type {Object}
12298
+ */
12299
+ static get DATETIME_SHORT_WITH_SECONDS() {
12300
+ return DATETIME_SHORT_WITH_SECONDS;
12301
+ }
12302
+
12303
+ /**
12304
+ * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
12305
+ * @type {Object}
12306
+ */
12307
+ static get DATETIME_MED() {
12308
+ return DATETIME_MED;
12309
+ }
12310
+
12311
+ /**
12312
+ * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
12313
+ * @type {Object}
12314
+ */
12315
+ static get DATETIME_MED_WITH_SECONDS() {
12316
+ return DATETIME_MED_WITH_SECONDS;
12317
+ }
12318
+
12319
+ /**
12320
+ * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
12321
+ * @type {Object}
12322
+ */
12323
+ static get DATETIME_MED_WITH_WEEKDAY() {
12324
+ return DATETIME_MED_WITH_WEEKDAY;
12325
+ }
12326
+
12327
+ /**
12328
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
12329
+ * @type {Object}
12330
+ */
12331
+ static get DATETIME_FULL() {
12332
+ return DATETIME_FULL;
12333
+ }
12334
+
12335
+ /**
12336
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
12337
+ * @type {Object}
12338
+ */
12339
+ static get DATETIME_FULL_WITH_SECONDS() {
12340
+ return DATETIME_FULL_WITH_SECONDS;
12341
+ }
12342
+
12343
+ /**
12344
+ * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12345
+ * @type {Object}
12346
+ */
12347
+ static get DATETIME_HUGE() {
12348
+ return DATETIME_HUGE;
12349
+ }
12350
+
12351
+ /**
12352
+ * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12353
+ * @type {Object}
12354
+ */
12355
+ static get DATETIME_HUGE_WITH_SECONDS() {
12356
+ return DATETIME_HUGE_WITH_SECONDS;
12357
+ }
12358
+ }
12359
+
12360
+ /**
12361
+ * @private
12362
+ */
12363
+ function friendlyDateTime(dateTimeish) {
12364
+ if (DateTime.isDateTime(dateTimeish)) {
12365
+ return dateTimeish;
12366
+ } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
12367
+ return DateTime.fromJSDate(dateTimeish);
12368
+ } else if (dateTimeish && typeof dateTimeish === "object") {
12369
+ return DateTime.fromObject(dateTimeish);
12370
+ } else {
12371
+ throw new InvalidArgumentError(
12372
+ `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`
12373
+ );
12374
+ }
12375
+ }
12376
+
12377
+ function getDefaultExportFromCjs (x) {
12378
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
12379
+ }
12380
+
12381
+ var loglevel$1 = {exports: {}};
12382
+
12383
+ /*
12384
+ * loglevel - https://github.com/pimterry/loglevel
12385
+ *
12386
+ * Copyright (c) 2013 Tim Perry
12387
+ * Licensed under the MIT license.
12388
+ */
12389
+ var loglevel = loglevel$1.exports;
12390
+
12391
+ var hasRequiredLoglevel;
12392
+
12393
+ function requireLoglevel () {
12394
+ if (hasRequiredLoglevel) return loglevel$1.exports;
12395
+ hasRequiredLoglevel = 1;
12396
+ (function (module) {
12397
+ (function (root, definition) {
12398
+ if (module.exports) {
12399
+ module.exports = definition();
12400
+ } else {
12401
+ root.log = definition();
12402
+ }
12403
+ }(loglevel, function () {
12404
+
12405
+ // Slightly dubious tricks to cut down minimized file size
12406
+ var noop = function() {};
12407
+ var undefinedType = "undefined";
12408
+ var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (
12409
+ /Trident\/|MSIE /.test(window.navigator.userAgent)
12410
+ );
12411
+
12412
+ var logMethods = [
12413
+ "trace",
12414
+ "debug",
12415
+ "info",
12416
+ "warn",
12417
+ "error"
12418
+ ];
12419
+
12420
+ var _loggersByName = {};
12421
+ var defaultLogger = null;
12422
+
12423
+ // Cross-browser bind equivalent that works at least back to IE6
12424
+ function bindMethod(obj, methodName) {
12425
+ var method = obj[methodName];
12426
+ if (typeof method.bind === 'function') {
12427
+ return method.bind(obj);
12428
+ } else {
12429
+ try {
12430
+ return Function.prototype.bind.call(method, obj);
12431
+ } catch (e) {
12432
+ // Missing bind shim or IE8 + Modernizr, fallback to wrapping
12433
+ return function() {
12434
+ return Function.prototype.apply.apply(method, [obj, arguments]);
12435
+ };
12436
+ }
12437
+ }
12438
+ }
12439
+
12440
+ // Trace() doesn't print the message in IE, so for that case we need to wrap it
12441
+ function traceForIE() {
12442
+ if (console.log) {
12443
+ if (console.log.apply) {
12444
+ console.log.apply(console, arguments);
12445
+ } else {
12446
+ // In old IE, native console methods themselves don't have apply().
12447
+ Function.prototype.apply.apply(console.log, [console, arguments]);
12448
+ }
12449
+ }
12450
+ if (console.trace) console.trace();
12451
+ }
12452
+
12453
+ // Build the best logging method possible for this env
12454
+ // Wherever possible we want to bind, not wrap, to preserve stack traces
12455
+ function realMethod(methodName) {
12456
+ if (methodName === 'debug') {
12457
+ methodName = 'log';
12458
+ }
12459
+
12460
+ if (typeof console === undefinedType) {
12461
+ return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
12462
+ } else if (methodName === 'trace' && isIE) {
12463
+ return traceForIE;
12464
+ } else if (console[methodName] !== undefined) {
12465
+ return bindMethod(console, methodName);
12466
+ } else if (console.log !== undefined) {
12467
+ return bindMethod(console, 'log');
12468
+ } else {
12469
+ return noop;
12470
+ }
12471
+ }
12472
+
12473
+ // These private functions always need `this` to be set properly
12474
+
12475
+ function replaceLoggingMethods() {
12476
+ /*jshint validthis:true */
12477
+ var level = this.getLevel();
12478
+
12479
+ // Replace the actual methods.
12480
+ for (var i = 0; i < logMethods.length; i++) {
12481
+ var methodName = logMethods[i];
12482
+ this[methodName] = (i < level) ?
12483
+ noop :
12484
+ this.methodFactory(methodName, level, this.name);
12485
+ }
12486
+
12487
+ // Define log.log as an alias for log.debug
12488
+ this.log = this.debug;
12489
+
12490
+ // Return any important warnings.
12491
+ if (typeof console === undefinedType && level < this.levels.SILENT) {
12492
+ return "No console available for logging";
12493
+ }
12494
+ }
12495
+
12496
+ // In old IE versions, the console isn't present until you first open it.
12497
+ // We build realMethod() replacements here that regenerate logging methods
12498
+ function enableLoggingWhenConsoleArrives(methodName) {
12499
+ return function () {
12500
+ if (typeof console !== undefinedType) {
12501
+ replaceLoggingMethods.call(this);
12502
+ this[methodName].apply(this, arguments);
12503
+ }
12504
+ };
12505
+ }
12506
+
12507
+ // By default, we use closely bound real methods wherever possible, and
12508
+ // otherwise we wait for a console to appear, and then try again.
12509
+ function defaultMethodFactory(methodName, _level, _loggerName) {
12510
+ /*jshint validthis:true */
12511
+ return realMethod(methodName) ||
12512
+ enableLoggingWhenConsoleArrives.apply(this, arguments);
12513
+ }
12514
+
12515
+ function Logger(name, factory) {
12516
+ // Private instance variables.
12517
+ var self = this;
12518
+ /**
12519
+ * The level inherited from a parent logger (or a global default). We
12520
+ * cache this here rather than delegating to the parent so that it stays
12521
+ * in sync with the actual logging methods that we have installed (the
12522
+ * parent could change levels but we might not have rebuilt the loggers
12523
+ * in this child yet).
12524
+ * @type {number}
12525
+ */
12526
+ var inheritedLevel;
12527
+ /**
12528
+ * The default level for this logger, if any. If set, this overrides
12529
+ * `inheritedLevel`.
12530
+ * @type {number|null}
12531
+ */
12532
+ var defaultLevel;
12533
+ /**
12534
+ * A user-specific level for this logger. If set, this overrides
12535
+ * `defaultLevel`.
12536
+ * @type {number|null}
12537
+ */
12538
+ var userLevel;
12539
+
12540
+ var storageKey = "loglevel";
12541
+ if (typeof name === "string") {
12542
+ storageKey += ":" + name;
12543
+ } else if (typeof name === "symbol") {
12544
+ storageKey = undefined;
12545
+ }
12546
+
12547
+ function persistLevelIfPossible(levelNum) {
12548
+ var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
12549
+
12550
+ if (typeof window === undefinedType || !storageKey) return;
12551
+
12552
+ // Use localStorage if available
12553
+ try {
12554
+ window.localStorage[storageKey] = levelName;
12555
+ return;
12556
+ } catch (ignore) {}
12557
+
12558
+ // Use session cookie as fallback
12559
+ try {
12560
+ window.document.cookie =
12561
+ encodeURIComponent(storageKey) + "=" + levelName + ";";
12562
+ } catch (ignore) {}
12563
+ }
12564
+
12565
+ function getPersistedLevel() {
12566
+ var storedLevel;
12567
+
12568
+ if (typeof window === undefinedType || !storageKey) return;
12569
+
12570
+ try {
12571
+ storedLevel = window.localStorage[storageKey];
12572
+ } catch (ignore) {}
12573
+
12574
+ // Fallback to cookies if local storage gives us nothing
12575
+ if (typeof storedLevel === undefinedType) {
12576
+ try {
12577
+ var cookie = window.document.cookie;
12578
+ var cookieName = encodeURIComponent(storageKey);
12579
+ var location = cookie.indexOf(cookieName + "=");
12580
+ if (location !== -1) {
12581
+ storedLevel = /^([^;]+)/.exec(
12582
+ cookie.slice(location + cookieName.length + 1)
12583
+ )[1];
12584
+ }
12585
+ } catch (ignore) {}
12586
+ }
12587
+
12588
+ // If the stored level is not valid, treat it as if nothing was stored.
12589
+ if (self.levels[storedLevel] === undefined) {
12590
+ storedLevel = undefined;
12591
+ }
12592
+
12593
+ return storedLevel;
12594
+ }
12595
+
12596
+ function clearPersistedLevel() {
12597
+ if (typeof window === undefinedType || !storageKey) return;
12598
+
12599
+ // Use localStorage if available
12600
+ try {
12601
+ window.localStorage.removeItem(storageKey);
12602
+ } catch (ignore) {}
12603
+
12604
+ // Use session cookie as fallback
12605
+ try {
12606
+ window.document.cookie =
12607
+ encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
12608
+ } catch (ignore) {}
12609
+ }
12610
+
12611
+ function normalizeLevel(input) {
12612
+ var level = input;
12613
+ if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
12614
+ level = self.levels[level.toUpperCase()];
12615
+ }
12616
+ if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
12617
+ return level;
12618
+ } else {
12619
+ throw new TypeError("log.setLevel() called with invalid level: " + input);
12620
+ }
12621
+ }
12622
+
12623
+ /*
12624
+ *
12625
+ * Public logger API - see https://github.com/pimterry/loglevel for details
12626
+ *
12627
+ */
12628
+
12629
+ self.name = name;
12630
+
12631
+ self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
12632
+ "ERROR": 4, "SILENT": 5};
12633
+
12634
+ self.methodFactory = factory || defaultMethodFactory;
12635
+
12636
+ self.getLevel = function () {
12637
+ if (userLevel != null) {
12638
+ return userLevel;
12639
+ } else if (defaultLevel != null) {
12640
+ return defaultLevel;
12641
+ } else {
12642
+ return inheritedLevel;
12643
+ }
12644
+ };
12645
+
12646
+ self.setLevel = function (level, persist) {
12647
+ userLevel = normalizeLevel(level);
12648
+ if (persist !== false) { // defaults to true
12649
+ persistLevelIfPossible(userLevel);
12650
+ }
12651
+
12652
+ // NOTE: in v2, this should call rebuild(), which updates children.
12653
+ return replaceLoggingMethods.call(self);
12654
+ };
12591
12655
 
12592
- /**
12593
- * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
12594
- * @type {Object}
12595
- */
12596
- static get TIME_WITH_SECONDS() {
12597
- return TIME_WITH_SECONDS;
12598
- }
12656
+ self.setDefaultLevel = function (level) {
12657
+ defaultLevel = normalizeLevel(level);
12658
+ if (!getPersistedLevel()) {
12659
+ self.setLevel(level, false);
12660
+ }
12661
+ };
12599
12662
 
12600
- /**
12601
- * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
12602
- * @type {Object}
12603
- */
12604
- static get TIME_WITH_SHORT_OFFSET() {
12605
- return TIME_WITH_SHORT_OFFSET;
12606
- }
12663
+ self.resetLevel = function () {
12664
+ userLevel = null;
12665
+ clearPersistedLevel();
12666
+ replaceLoggingMethods.call(self);
12667
+ };
12607
12668
 
12608
- /**
12609
- * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12610
- * @type {Object}
12611
- */
12612
- static get TIME_WITH_LONG_OFFSET() {
12613
- return TIME_WITH_LONG_OFFSET;
12614
- }
12669
+ self.enableAll = function(persist) {
12670
+ self.setLevel(self.levels.TRACE, persist);
12671
+ };
12615
12672
 
12616
- /**
12617
- * {@link DateTime#toLocaleString} format like '09:30', always 24-hour.
12618
- * @type {Object}
12619
- */
12620
- static get TIME_24_SIMPLE() {
12621
- return TIME_24_SIMPLE;
12622
- }
12673
+ self.disableAll = function(persist) {
12674
+ self.setLevel(self.levels.SILENT, persist);
12675
+ };
12623
12676
 
12624
- /**
12625
- * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
12626
- * @type {Object}
12627
- */
12628
- static get TIME_24_WITH_SECONDS() {
12629
- return TIME_24_WITH_SECONDS;
12630
- }
12677
+ self.rebuild = function () {
12678
+ if (defaultLogger !== self) {
12679
+ inheritedLevel = normalizeLevel(defaultLogger.getLevel());
12680
+ }
12681
+ replaceLoggingMethods.call(self);
12631
12682
 
12632
- /**
12633
- * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour.
12634
- * @type {Object}
12635
- */
12636
- static get TIME_24_WITH_SHORT_OFFSET() {
12637
- return TIME_24_WITH_SHORT_OFFSET;
12638
- }
12683
+ if (defaultLogger === self) {
12684
+ for (var childName in _loggersByName) {
12685
+ _loggersByName[childName].rebuild();
12686
+ }
12687
+ }
12688
+ };
12639
12689
 
12640
- /**
12641
- * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
12642
- * @type {Object}
12643
- */
12644
- static get TIME_24_WITH_LONG_OFFSET() {
12645
- return TIME_24_WITH_LONG_OFFSET;
12646
- }
12690
+ // Initialize all the internal levels.
12691
+ inheritedLevel = normalizeLevel(
12692
+ defaultLogger ? defaultLogger.getLevel() : "WARN"
12693
+ );
12694
+ var initialLevel = getPersistedLevel();
12695
+ if (initialLevel != null) {
12696
+ userLevel = normalizeLevel(initialLevel);
12697
+ }
12698
+ replaceLoggingMethods.call(self);
12699
+ }
12647
12700
 
12648
- /**
12649
- * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
12650
- * @type {Object}
12651
- */
12652
- static get DATETIME_SHORT() {
12653
- return DATETIME_SHORT;
12654
- }
12701
+ /*
12702
+ *
12703
+ * Top-level API
12704
+ *
12705
+ */
12655
12706
 
12656
- /**
12657
- * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
12658
- * @type {Object}
12659
- */
12660
- static get DATETIME_SHORT_WITH_SECONDS() {
12661
- return DATETIME_SHORT_WITH_SECONDS;
12662
- }
12707
+ defaultLogger = new Logger();
12663
12708
 
12664
- /**
12665
- * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
12666
- * @type {Object}
12667
- */
12668
- static get DATETIME_MED() {
12669
- return DATETIME_MED;
12670
- }
12709
+ defaultLogger.getLogger = function getLogger(name) {
12710
+ if ((typeof name !== "symbol" && typeof name !== "string") || name === "") {
12711
+ throw new TypeError("You must supply a name when creating a logger.");
12712
+ }
12671
12713
 
12672
- /**
12673
- * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
12674
- * @type {Object}
12675
- */
12676
- static get DATETIME_MED_WITH_SECONDS() {
12677
- return DATETIME_MED_WITH_SECONDS;
12678
- }
12714
+ var logger = _loggersByName[name];
12715
+ if (!logger) {
12716
+ logger = _loggersByName[name] = new Logger(
12717
+ name,
12718
+ defaultLogger.methodFactory
12719
+ );
12720
+ }
12721
+ return logger;
12722
+ };
12679
12723
 
12680
- /**
12681
- * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
12682
- * @type {Object}
12683
- */
12684
- static get DATETIME_MED_WITH_WEEKDAY() {
12685
- return DATETIME_MED_WITH_WEEKDAY;
12686
- }
12724
+ // Grab the current global log variable in case of overwrite
12725
+ var _log = (typeof window !== undefinedType) ? window.log : undefined;
12726
+ defaultLogger.noConflict = function() {
12727
+ if (typeof window !== undefinedType &&
12728
+ window.log === defaultLogger) {
12729
+ window.log = _log;
12730
+ }
12687
12731
 
12688
- /**
12689
- * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
12690
- * @type {Object}
12691
- */
12692
- static get DATETIME_FULL() {
12693
- return DATETIME_FULL;
12694
- }
12732
+ return defaultLogger;
12733
+ };
12695
12734
 
12696
- /**
12697
- * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
12698
- * @type {Object}
12699
- */
12700
- static get DATETIME_FULL_WITH_SECONDS() {
12701
- return DATETIME_FULL_WITH_SECONDS;
12702
- }
12735
+ defaultLogger.getLoggers = function getLoggers() {
12736
+ return _loggersByName;
12737
+ };
12703
12738
 
12704
- /**
12705
- * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12706
- * @type {Object}
12707
- */
12708
- static get DATETIME_HUGE() {
12709
- return DATETIME_HUGE;
12710
- }
12739
+ // ES6 default export, for compatibility
12740
+ defaultLogger['default'] = defaultLogger;
12711
12741
 
12712
- /**
12713
- * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12714
- * @type {Object}
12715
- */
12716
- static get DATETIME_HUGE_WITH_SECONDS() {
12717
- return DATETIME_HUGE_WITH_SECONDS;
12718
- }
12742
+ return defaultLogger;
12743
+ }));
12744
+ } (loglevel$1));
12745
+ return loglevel$1.exports;
12719
12746
  }
12720
12747
 
12748
+ var loglevelExports = requireLoglevel();
12749
+ var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
12750
+
12751
+ const parserLog = log.getLogger('minotor:gtfs');
12752
+ parserLog.setLevel('warn', false);
12721
12753
  /**
12722
- * @private
12754
+ * Set logging for all GTFS parser instances in this module.
12755
+ * Defaults to warn.
12723
12756
  */
12724
- function friendlyDateTime(dateTimeish) {
12725
- if (DateTime.isDateTime(dateTimeish)) {
12726
- return dateTimeish;
12727
- } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
12728
- return DateTime.fromJSDate(dateTimeish);
12729
- } else if (dateTimeish && typeof dateTimeish === "object") {
12730
- return DateTime.fromObject(dateTimeish);
12731
- } else {
12732
- throw new InvalidArgumentError(
12733
- `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`
12734
- );
12735
- }
12757
+ function setParserLogLevel(level) {
12758
+ parserLog.setLevel(level, false);
12736
12759
  }
12737
12760
 
12738
12761
  /**
@@ -20637,7 +20660,7 @@ const parseFrequencies = (stream, activeTripIds) => __awaiter(void 0, void 0, vo
20637
20660
  continue;
20638
20661
  }
20639
20662
  if (line.exact_times !== '1') {
20640
- log.warn(`${line.trip_id} will be treated as a scheduled-based trip.`);
20663
+ parserLog.warn(`${line.trip_id} will be treated as a scheduled-based trip.`);
20641
20664
  }
20642
20665
  const window = {
20643
20666
  startTime: toTime(line.start_time),
@@ -20711,7 +20734,7 @@ const parseRoutes = (routesStream_1, ...args_1) => __awaiter(void 0, [routesStre
20711
20734
  const line = rawLine;
20712
20735
  const routeType = profile.routeTypeParser(line.route_type);
20713
20736
  if (routeType === undefined) {
20714
- log.info(`Unsupported route type ${line.route_type} for route ${line.route_id}.`);
20737
+ parserLog.info(`Unsupported route type ${line.route_type} for route ${line.route_id}.`);
20715
20738
  continue;
20716
20739
  }
20717
20740
  routes.set(line.route_id, {
@@ -20741,7 +20764,7 @@ const indexRoutes = (gtfsRoutesMap, serviceRoutesMap) => {
20741
20764
  for (const [gtfsRouteId, serviceRouteId] of serviceRoutesMap) {
20742
20765
  const route = gtfsRoutesMap.get(gtfsRouteId);
20743
20766
  if (route === undefined) {
20744
- log.warn(`Route ${gtfsRouteId} not found.`);
20767
+ parserLog.warn(`Route ${gtfsRouteId} not found.`);
20745
20768
  continue;
20746
20769
  }
20747
20770
  serviceRoutes[serviceRouteId] = {
@@ -20888,7 +20911,7 @@ const parseStops = (stopsStream) => __awaiter(void 0, void 0, void 0, function*
20888
20911
  if (stop.parentSourceId) {
20889
20912
  const parentStop = parsedStops.get(stop.parentSourceId);
20890
20913
  if (!parentStop) {
20891
- log.warn(`Cannot find parent stop ${stop.parentSourceId} of ${sourceStopId}`);
20914
+ parserLog.warn(`Cannot find parent stop ${stop.parentSourceId} of ${sourceStopId}`);
20892
20915
  continue;
20893
20916
  }
20894
20917
  stop.parent = parentStop.id;
@@ -20921,7 +20944,7 @@ const processInSeatTransfer = (transferEntry, fromStop, toStop, tripContinuation
20921
20944
  transferEntry.from_trip_id === '' ||
20922
20945
  transferEntry.to_trip_id === undefined ||
20923
20946
  transferEntry.to_trip_id === '') {
20924
- log.warn(`Unsupported in-seat transfer, missing from_trip_id and/or to_trip_id.`);
20947
+ parserLog.warn(`Unsupported in-seat transfer, missing from_trip_id and/or to_trip_id.`);
20925
20948
  return;
20926
20949
  }
20927
20950
  const tripContinuationEntry = {
@@ -20957,7 +20980,7 @@ const processGuaranteedTripTransfer = (transferEntry, fromStop, toStop, guarante
20957
20980
  const processGuaranteedStopTransfer = (transferEntry, fromStop, toStop, transfers) => {
20958
20981
  // Reject transfers that specify route IDs - these are not supported for stop-to-stop transfers
20959
20982
  if (transferEntry.from_route_id || transferEntry.to_route_id) {
20960
- log.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between routes ${transferEntry.from_route_id} and ${transferEntry.to_route_id}.`);
20983
+ parserLog.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between routes ${transferEntry.from_route_id} and ${transferEntry.to_route_id}.`);
20961
20984
  return;
20962
20985
  }
20963
20986
  const transfer = Object.assign({ destination: toStop, type: TransferTypes.GUARANTEED }, (transferEntry.min_transfer_time !== undefined && {
@@ -20972,11 +20995,11 @@ const processGuaranteedStopTransfer = (transferEntry, fromStop, toStop, transfer
20972
20995
  */
20973
20996
  const processStopToStopTransfer = (transferEntry, fromStop, toStop, transfers) => {
20974
20997
  if (transferEntry.from_trip_id || transferEntry.to_trip_id) {
20975
- log.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between trips ${transferEntry.from_trip_id} and ${transferEntry.to_trip_id}.`);
20998
+ parserLog.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between trips ${transferEntry.from_trip_id} and ${transferEntry.to_trip_id}.`);
20976
20999
  return;
20977
21000
  }
20978
21001
  if (transferEntry.from_route_id || transferEntry.to_route_id) {
20979
- log.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between routes ${transferEntry.from_route_id} and ${transferEntry.to_route_id}.`);
21002
+ parserLog.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between routes ${transferEntry.from_route_id} and ${transferEntry.to_route_id}.`);
20980
21003
  return;
20981
21004
  }
20982
21005
  if (transferEntry.transfer_type === 2 &&
@@ -21024,13 +21047,13 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
21024
21047
  continue;
21025
21048
  }
21026
21049
  if (!transferEntry.from_stop_id || !transferEntry.to_stop_id) {
21027
- log.warn(`Missing transfer origin or destination stop.`);
21050
+ parserLog.warn(`Missing transfer origin or destination stop.`);
21028
21051
  continue;
21029
21052
  }
21030
21053
  const fromStop = stopsMap.get(transferEntry.from_stop_id);
21031
21054
  const toStop = stopsMap.get(transferEntry.to_stop_id);
21032
21055
  if (!fromStop || !toStop) {
21033
- log.warn(`Transfer references non-existent stop(s): from_stop_id=${transferEntry.from_stop_id}, to_stop_id=${transferEntry.to_stop_id}`);
21056
+ parserLog.warn(`Transfer references non-existent stop(s): from_stop_id=${transferEntry.from_stop_id}, to_stop_id=${transferEntry.to_stop_id}`);
21034
21057
  continue;
21035
21058
  }
21036
21059
  switch (transferEntry.transfer_type) {
@@ -21055,7 +21078,7 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
21055
21078
  transferEntry.to_trip_id ||
21056
21079
  transferEntry.from_route_id ||
21057
21080
  transferEntry.to_route_id) {
21058
- log.warn(`Unsupported transfer of type 3 with trip or route constraints: from_trip_id=${transferEntry.from_trip_id}, to_trip_id=${transferEntry.to_trip_id}, from_route_id=${transferEntry.from_route_id}, to_route_id=${transferEntry.to_route_id}.`);
21081
+ parserLog.warn(`Unsupported transfer of type 3 with trip or route constraints: from_trip_id=${transferEntry.from_trip_id}, to_trip_id=${transferEntry.to_trip_id}, from_route_id=${transferEntry.from_route_id}, to_route_id=${transferEntry.to_route_id}.`);
21059
21082
  break;
21060
21083
  }
21061
21084
  const forbiddenDestinations = (_d = forbiddenTransfers.get(fromStop.id)) !== null && _d !== void 0 ? _d : new Set();
@@ -21456,7 +21479,7 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21456
21479
  }
21457
21480
  const firstDeparture = departureTimes[0];
21458
21481
  if (firstDeparture === undefined) {
21459
- log.warn(`Empty trip ${currentTripId}`);
21482
+ parserLog.warn(`Empty trip ${currentTripId}`);
21460
21483
  stops = [];
21461
21484
  arrivalTimes = [];
21462
21485
  departureTimes = [];
@@ -21539,11 +21562,11 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21539
21562
  const rawLine = _c;
21540
21563
  const line = rawLine;
21541
21564
  if (line.trip_id === currentTripId && line.stop_sequence <= previousSeq) {
21542
- log.warn(`Stop sequences not increasing for trip ${line.trip_id}: ${line.stop_sequence} > ${previousSeq}.`);
21565
+ parserLog.warn(`Stop sequences not increasing for trip ${line.trip_id}: ${line.stop_sequence} > ${previousSeq}.`);
21543
21566
  continue;
21544
21567
  }
21545
21568
  if (!line.arrival_time && !line.departure_time) {
21546
- log.warn(`Missing arrival or departure time for ${line.trip_id} at stop ${line.stop_id}.`);
21569
+ parserLog.warn(`Missing arrival or departure time for ${line.trip_id} at stop ${line.stop_id}.`);
21547
21570
  continue;
21548
21571
  }
21549
21572
  if (line.pickup_type === '1' && line.drop_off_type === '1') {
@@ -21558,14 +21581,14 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21558
21581
  currentTripId = line.trip_id;
21559
21582
  const stopData = stopsMap.get(line.stop_id);
21560
21583
  if (!stopData) {
21561
- log.warn(`Unknown stop ID: ${line.stop_id}`);
21584
+ parserLog.warn(`Unknown stop ID: ${line.stop_id}`);
21562
21585
  continue;
21563
21586
  }
21564
21587
  stops.push(stopData.id);
21565
21588
  const departure = (_d = line.departure_time) !== null && _d !== void 0 ? _d : line.arrival_time;
21566
21589
  const arrival = (_e = line.arrival_time) !== null && _e !== void 0 ? _e : line.departure_time;
21567
21590
  if (!arrival || !departure) {
21568
- log.warn(`Missing time data for ${line.trip_id} at stop ${line.stop_id}`);
21591
+ parserLog.warn(`Missing time data for ${line.trip_id} at stop ${line.stop_id}`);
21569
21592
  continue;
21570
21593
  }
21571
21594
  arrivalTimes.push(toTime(arrival));
@@ -21638,52 +21661,51 @@ class GtfsParser {
21638
21661
  */
21639
21662
  parseTimetable(date) {
21640
21663
  return __awaiter(this, void 0, void 0, function* () {
21641
- log.setLevel('INFO');
21642
21664
  const zip = new StreamZip.async({ file: this.path });
21643
21665
  const entries = yield zip.entries();
21644
21666
  const datetime = DateTime.fromJSDate(date);
21645
21667
  const activeServiceIds = new Set();
21646
21668
  const activeStopIds = new Set();
21647
- log.info(`Parsing ${STOPS_FILE}`);
21669
+ parserLog.info(`Parsing ${STOPS_FILE}`);
21648
21670
  const stopsStart = performance.now();
21649
21671
  const stopsStream = yield zip.stream(STOPS_FILE);
21650
21672
  const parsedStops = yield parseStops(stopsStream);
21651
21673
  const stopsEnd = performance.now();
21652
- log.info(`${parsedStops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21674
+ parserLog.info(`${parsedStops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21653
21675
  if (entries[CALENDAR_FILE]) {
21654
- log.info(`Parsing ${CALENDAR_FILE}`);
21676
+ parserLog.info(`Parsing ${CALENDAR_FILE}`);
21655
21677
  const calendarStart = performance.now();
21656
21678
  const calendarStream = yield zip.stream(CALENDAR_FILE);
21657
21679
  yield parseCalendar(calendarStream, activeServiceIds, datetime);
21658
21680
  const calendarEnd = performance.now();
21659
- log.info(`${activeServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
21681
+ parserLog.info(`${activeServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
21660
21682
  }
21661
21683
  if (entries[CALENDAR_DATES_FILE]) {
21662
- log.info(`Parsing ${CALENDAR_DATES_FILE}`);
21684
+ parserLog.info(`Parsing ${CALENDAR_DATES_FILE}`);
21663
21685
  const calendarDatesStart = performance.now();
21664
21686
  const calendarDatesStream = yield zip.stream(CALENDAR_DATES_FILE);
21665
21687
  yield parseCalendarDates(calendarDatesStream, activeServiceIds, datetime);
21666
21688
  const calendarDatesEnd = performance.now();
21667
- log.info(`${activeServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
21689
+ parserLog.info(`${activeServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
21668
21690
  }
21669
- log.info(`Parsing ${ROUTES_FILE}`);
21691
+ parserLog.info(`Parsing ${ROUTES_FILE}`);
21670
21692
  const routesStart = performance.now();
21671
21693
  const routesStream = yield zip.stream(ROUTES_FILE);
21672
21694
  const validGtfsRoutes = yield parseRoutes(routesStream, this.profile);
21673
21695
  const routesEnd = performance.now();
21674
- log.info(`${validGtfsRoutes.size} valid GTFS routes. (${(routesEnd - routesStart).toFixed(2)}ms)`);
21675
- log.info(`Parsing ${TRIPS_FILE}`);
21696
+ parserLog.info(`${validGtfsRoutes.size} valid GTFS routes. (${(routesEnd - routesStart).toFixed(2)}ms)`);
21697
+ parserLog.info(`Parsing ${TRIPS_FILE}`);
21676
21698
  const tripsStart = performance.now();
21677
21699
  const tripsStream = yield zip.stream(TRIPS_FILE);
21678
21700
  const trips = yield parseTrips(tripsStream, activeServiceIds, validGtfsRoutes);
21679
21701
  const tripsEnd = performance.now();
21680
- log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21702
+ parserLog.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21681
21703
  let transfers = new Map();
21682
21704
  let forbiddenTransfers = new Map();
21683
21705
  let tripContinuationsList = [];
21684
21706
  let guaranteedTripTransfersList = [];
21685
21707
  if (entries[TRANSFERS_FILE]) {
21686
- log.info(`Parsing ${TRANSFERS_FILE}`);
21708
+ parserLog.info(`Parsing ${TRANSFERS_FILE}`);
21687
21709
  const transfersStart = performance.now();
21688
21710
  const transfersStream = yield zip.stream(TRANSFERS_FILE);
21689
21711
  const { transfers: parsedTransfers, forbiddenTransfers: parsedForbiddenTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops, activeServiceIds);
@@ -21692,32 +21714,32 @@ class GtfsParser {
21692
21714
  tripContinuationsList = parsedTripContinuations;
21693
21715
  guaranteedTripTransfersList = parsedGuaranteedTripTransfers;
21694
21716
  const transfersEnd = performance.now();
21695
- log.info(`${transfers.size} valid transfers and ${tripContinuationsList.length} trip continuations and ${guaranteedTripTransfersList.length} guaranteed trip transfers. (${(transfersEnd - transfersStart).toFixed(2)}ms)`);
21717
+ parserLog.info(`${transfers.size} valid transfers and ${tripContinuationsList.length} trip continuations and ${guaranteedTripTransfersList.length} guaranteed trip transfers. (${(transfersEnd - transfersStart).toFixed(2)}ms)`);
21696
21718
  }
21697
21719
  let frequenciesMap;
21698
21720
  if (entries[FREQUENCIES_FILE]) {
21699
- log.info(`Parsing ${FREQUENCIES_FILE}`);
21721
+ parserLog.info(`Parsing ${FREQUENCIES_FILE}`);
21700
21722
  const frequenciesStart = performance.now();
21701
21723
  const frequenciesStream = yield zip.stream(FREQUENCIES_FILE);
21702
21724
  frequenciesMap = yield parseFrequencies(frequenciesStream, new Set(trips.keys()));
21703
21725
  const frequenciesEnd = performance.now();
21704
- log.info(`${frequenciesMap.size} trips with frequency data. (${(frequenciesEnd - frequenciesStart).toFixed(2)}ms)`);
21726
+ parserLog.info(`${frequenciesMap.size} trips with frequency data. (${(frequenciesEnd - frequenciesStart).toFixed(2)}ms)`);
21705
21727
  }
21706
- log.info(`Parsing ${STOP_TIMES_FILE}`);
21728
+ parserLog.info(`Parsing ${STOP_TIMES_FILE}`);
21707
21729
  const stopTimesStart = performance.now();
21708
21730
  const stopTimesStream = yield zip.stream(STOP_TIMES_FILE);
21709
21731
  const { routes, serviceRoutesMap, tripsMapping } = yield parseStopTimes(stopTimesStream, parsedStops, trips, activeStopIds, frequenciesMap);
21710
21732
  const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
21711
21733
  const stopTimesEnd = performance.now();
21712
- log.info(`${routes.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
21734
+ parserLog.info(`${routes.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
21713
21735
  if (this.profile.deriveSiblingTransfers !== false) {
21714
21736
  const siblingTransfersStart = performance.now();
21715
21737
  const siblingTransfersAdded = addMissingSiblingTransfers(parsedStops, activeStopIds, transfers, forbiddenTransfers);
21716
21738
  const siblingTransfersEnd = performance.now();
21717
- log.info(`${siblingTransfersAdded} sibling transfers added. (${(siblingTransfersEnd - siblingTransfersStart).toFixed(2)}ms)`);
21739
+ parserLog.info(`${siblingTransfersAdded} sibling transfers added. (${(siblingTransfersEnd - siblingTransfersStart).toFixed(2)}ms)`);
21718
21740
  }
21719
21741
  if (this.transferGenerator) {
21720
- log.info('Generating virtual transfers');
21742
+ parserLog.info('Generating virtual transfers');
21721
21743
  const virtualTransfersStart = performance.now();
21722
21744
  // Only route-served stops with coordinates are worth connecting: a
21723
21745
  // transfer to a stop no route calls at is a dead end for the router.
@@ -21728,28 +21750,28 @@ class GtfsParser {
21728
21750
  const generatedTransfers = yield this.transferGenerator.generate(originStops, stopsIndex);
21729
21751
  const addedTransfers = addGeneratedTransfers(generatedTransfers, activeStopIds, transfers, forbiddenTransfers);
21730
21752
  const virtualTransfersEnd = performance.now();
21731
- log.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21753
+ parserLog.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21732
21754
  }
21733
- log.info('Building stops adjacency structure');
21755
+ parserLog.info('Building stops adjacency structure');
21734
21756
  const stopsAdjacencyStart = performance.now();
21735
21757
  const stopsAdjacency = buildStopsAdjacencyStructure(serviceRoutes, routes, transfers, parsedStops.size, activeStopIds);
21736
21758
  const stopsAdjacencyEnd = performance.now();
21737
- log.info(`${stopsAdjacency.length} valid stops in the structure. (${(stopsAdjacencyEnd - stopsAdjacencyStart).toFixed(2)}ms)`);
21759
+ parserLog.info(`${stopsAdjacency.length} valid stops in the structure. (${(stopsAdjacencyEnd - stopsAdjacencyStart).toFixed(2)}ms)`);
21738
21760
  yield zip.close();
21739
21761
  // temporary timetable for building continuations
21740
21762
  const timetable = new Timetable(stopsAdjacency, routes, serviceRoutes);
21741
- log.info('Building in-seat trip continuations');
21763
+ parserLog.info('Building in-seat trip continuations');
21742
21764
  const tripContinuationsStart = performance.now();
21743
21765
  const tripContinuations = buildTripTransfers(tripsMapping, tripContinuationsList, timetable, activeStopIds);
21744
21766
  const tripContinuationsEnd = performance.now();
21745
- log.info(`${tripContinuations.size} in-seat trip continuations origins created. (${(tripContinuationsEnd - tripContinuationsStart).toFixed(2)}ms)`);
21746
- log.info('Parsing complete.');
21747
- log.info('Building guaranteed trip transfers');
21767
+ parserLog.info(`${tripContinuations.size} in-seat trip continuations origins created. (${(tripContinuationsEnd - tripContinuationsStart).toFixed(2)}ms)`);
21768
+ parserLog.info('Parsing complete.');
21769
+ parserLog.info('Building guaranteed trip transfers');
21748
21770
  const guaranteedTripTransfersStart = performance.now();
21749
21771
  const guaranteedTripTransfers = buildTripTransfers(tripsMapping, guaranteedTripTransfersList, timetable, activeStopIds);
21750
21772
  const guaranteedTripTransfersEnd = performance.now();
21751
- log.info(`${guaranteedTripTransfers.size} guaranteed trip transfers origins created. (${(guaranteedTripTransfersEnd - guaranteedTripTransfersStart).toFixed(2)}ms)`);
21752
- log.info('Parsing complete.');
21773
+ parserLog.info(`${guaranteedTripTransfers.size} guaranteed trip transfers origins created. (${(guaranteedTripTransfersEnd - guaranteedTripTransfersStart).toFixed(2)}ms)`);
21774
+ parserLog.info('Parsing complete.');
21753
21775
  return new Timetable(stopsAdjacency, routes, serviceRoutes, tripContinuations, guaranteedTripTransfers);
21754
21776
  });
21755
21777
  }
@@ -21762,12 +21784,12 @@ class GtfsParser {
21762
21784
  parseStops() {
21763
21785
  return __awaiter(this, void 0, void 0, function* () {
21764
21786
  const zip = new StreamZip.async({ file: this.path });
21765
- log.info(`Parsing ${STOPS_FILE}`);
21787
+ parserLog.info(`Parsing ${STOPS_FILE}`);
21766
21788
  const stopsStart = performance.now();
21767
21789
  const stopsStream = yield zip.stream(STOPS_FILE);
21768
21790
  const stops = yield parseStops(stopsStream);
21769
21791
  const stopsEnd = performance.now();
21770
- log.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21792
+ parserLog.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21771
21793
  yield zip.close();
21772
21794
  return new StopsIndex(Array.from(stops.values()));
21773
21795
  });
@@ -21999,6 +22021,11 @@ class StraightLineTransferGenerator {
21999
22021
  }
22000
22022
  }
22001
22023
 
22024
+ /** Internal plotter access; deliberately not exported from the package entry point. */
22025
+ const resultGraph = Symbol('resultGraph');
22026
+ /** Internal access to query destinations for range result selection. */
22027
+ const resultDestinations = Symbol('resultDestinations');
22028
+
22002
22029
  /**
22003
22030
  * Configuration for DOT graph styling.
22004
22031
  */
@@ -22204,8 +22231,9 @@ class Plotter {
22204
22231
  */
22205
22232
  getStationInfo(stopId) {
22206
22233
  var _a;
22207
- const isOrigin = ((_a = this.result.routingState.graph[0]) === null || _a === void 0 ? void 0 : _a[stopId]) !== undefined;
22208
- const isDestination = this.result.routingState.destinations.includes(stopId);
22234
+ const { graph, destinations } = this.result[resultGraph]();
22235
+ const isOrigin = ((_a = graph[0]) === null || _a === void 0 ? void 0 : _a[stopId]) !== undefined;
22236
+ const isDestination = destinations.includes(stopId);
22209
22237
  return { isOrigin, isDestination };
22210
22238
  }
22211
22239
  /**
@@ -22355,7 +22383,7 @@ class Plotter {
22355
22383
  */
22356
22384
  collectStations() {
22357
22385
  const stations = new Set();
22358
- const graph = this.result.routingState.graph;
22386
+ const graph = this.result[resultGraph]().graph;
22359
22387
  for (const roundEdges of graph) {
22360
22388
  for (let stopId = 0; stopId < roundEdges.length; stopId++) {
22361
22389
  const edge = roundEdges[stopId];
@@ -22401,7 +22429,7 @@ class Plotter {
22401
22429
  collectEdges() {
22402
22430
  const edges = [];
22403
22431
  const continuationEdges = [];
22404
- const graph = this.result.routingState.graph;
22432
+ const graph = this.result[resultGraph]().graph;
22405
22433
  for (let round = 0; round < graph.length; round++) {
22406
22434
  const roundEdges = graph[round];
22407
22435
  if (!roundEdges)
@@ -22683,24 +22711,80 @@ class Route {
22683
22711
  }
22684
22712
  }
22685
22713
 
22714
+ var _Result_routingState;
22715
+ /**
22716
+ * A single-departure routing result.
22717
+ */
22686
22718
  class Result {
22687
- constructor(destinations, routingState, stopsIndex, timetable) {
22688
- this.destinations = destinations;
22689
- this.routingState = routingState;
22719
+ constructor(routingState, stopsIndex, timetable) {
22720
+ _Result_routingState.set(this, void 0);
22721
+ __classPrivateFieldSet(this, _Result_routingState, routingState, "f");
22690
22722
  this.stopsIndex = stopsIndex;
22691
22723
  this.timetable = timetable;
22692
22724
  }
22725
+ /** @internal Default query destinations for range result selection. */
22726
+ [(_Result_routingState = new WeakMap(), resultDestinations)]() {
22727
+ return __classPrivateFieldGet(this, _Result_routingState, "f").destinations;
22728
+ }
22729
+ /** @internal Routing graph and destination metadata for the graph plotter. */
22730
+ [resultGraph]() {
22731
+ return {
22732
+ graph: __classPrivateFieldGet(this, _Result_routingState, "f").graph,
22733
+ destinations: __classPrivateFieldGet(this, _Result_routingState, "f").destinations,
22734
+ };
22735
+ }
22736
+ /**
22737
+ * Iterates over reached stops, yielding each concrete stop ID, its earliest
22738
+ * arrival time, and the number of legs taken to reach it. Unreached stops
22739
+ * are omitted. Destination pruning may limit which stops were reached.
22740
+ * @param maxTransfers Optional transfer limit within retained data.
22741
+ */
22742
+ *arrivals(maxTransfers) {
22743
+ for (const reached of __classPrivateFieldGet(this, _Result_routingState, "f").arrivals()) {
22744
+ if (maxTransfers === undefined) {
22745
+ yield reached;
22746
+ }
22747
+ else {
22748
+ const arrival = this.concreteArrivalAt(reached.stop, maxTransfers);
22749
+ if (arrival !== undefined)
22750
+ yield Object.assign({ stop: reached.stop }, arrival);
22751
+ }
22752
+ }
22753
+ }
22754
+ /** Looks up one concrete stop without expanding equivalent stops. */
22755
+ concreteArrivalAt(stop, maxTransfers) {
22756
+ var _a;
22757
+ const best = __classPrivateFieldGet(this, _Result_routingState, "f").getArrival(stop);
22758
+ if (maxTransfers === undefined ||
22759
+ (best !== undefined && best.legNumber <= maxTransfers + 1)) {
22760
+ return best;
22761
+ }
22762
+ let earliest;
22763
+ const lastRound = Math.min(maxTransfers + 1, __classPrivateFieldGet(this, _Result_routingState, "f").graph.length - 1);
22764
+ for (let round = lastRound; round >= 0; round--) {
22765
+ const edge = (_a = __classPrivateFieldGet(this, _Result_routingState, "f").graph[round]) === null || _a === void 0 ? void 0 : _a[stop];
22766
+ if (edge !== undefined &&
22767
+ (earliest === undefined || edge.arrival < earliest.arrival)) {
22768
+ earliest = { arrival: edge.arrival, legNumber: round };
22769
+ }
22770
+ }
22771
+ return earliest;
22772
+ }
22693
22773
  /**
22694
22774
  * Expands a target stop or stop set to all equivalent concrete stop IDs.
22695
22775
  *
22696
- * When `to` is omitted, defaults to the resolved destinations stored on this
22697
- * result.
22776
+ * When `to` is omitted, defaults to the resolved destinations in the
22777
+ * query.
22698
22778
  *
22699
22779
  * Equivalent stops are expanded here so destination handling has a single
22700
22780
  * source of truth shared by route reconstruction and arrival lookups.
22701
22781
  */
22702
22782
  expandDestinations(to) {
22703
- const targets = to instanceof Set ? to : to !== undefined ? [to] : this.destinations;
22783
+ const targets = to instanceof Set
22784
+ ? to
22785
+ : to !== undefined
22786
+ ? [to]
22787
+ : __classPrivateFieldGet(this, _Result_routingState, "f").destinations;
22704
22788
  const expanded = new Set();
22705
22789
  for (const target of targets) {
22706
22790
  for (const equivalentStop of this.stopsIndex.equivalentStops(target)) {
@@ -22715,9 +22799,10 @@ class Result {
22715
22799
  * destination set)
22716
22800
  *
22717
22801
  * @param to The destination stop by SourceStopId.
22802
+ * @param maxTransfers Optional transfer limit within retained data.
22718
22803
  * @returns a route to the destination stop if it exists.
22719
22804
  */
22720
- bestRouteToSourceStopId(to) {
22805
+ bestRouteToSourceStopId(to, maxTransfers) {
22721
22806
  var _a;
22722
22807
  if (to instanceof Set) {
22723
22808
  const stopIds = new Set();
@@ -22726,10 +22811,14 @@ class Result {
22726
22811
  if (found !== undefined)
22727
22812
  stopIds.add(found.id);
22728
22813
  }
22729
- return stopIds.size === 0 ? undefined : this.bestRoute(stopIds);
22814
+ return stopIds.size === 0
22815
+ ? undefined
22816
+ : this.bestRoute(stopIds, maxTransfers);
22730
22817
  }
22731
22818
  const stopId = (_a = this.stopsIndex.findStopBySourceStopId(to)) === null || _a === void 0 ? void 0 : _a.id;
22732
- return stopId === undefined ? undefined : this.bestRoute(stopId);
22819
+ return stopId === undefined
22820
+ ? undefined
22821
+ : this.bestRoute(stopId, maxTransfers);
22733
22822
  }
22734
22823
  /**
22735
22824
  * Reconstructs the best route to a stop.
@@ -22738,9 +22827,10 @@ class Result {
22738
22827
  *
22739
22828
  * @param to The destination stop. Defaults to this result's resolved
22740
22829
  * destinations.
22830
+ * @param maxTransfers Optional transfer limit within retained data.
22741
22831
  * @returns a route to the destination stop if it exists.
22742
22832
  */
22743
- bestRoute(to) {
22833
+ bestRoute(to, maxTransfers) {
22744
22834
  var _a;
22745
22835
  const destinationStops = this.expandDestinations(to);
22746
22836
  // Find the fastest-reached destination across all equivalent stops.
@@ -22748,7 +22838,7 @@ class Result {
22748
22838
  let fastestArrivalTime = undefined;
22749
22839
  let fastestLegNumber = undefined;
22750
22840
  for (const destination of destinationStops) {
22751
- const arrivalData = this.routingState.getArrival(destination);
22841
+ const arrivalData = this.concreteArrivalAt(destination, maxTransfers);
22752
22842
  if (arrivalData !== undefined &&
22753
22843
  (fastestArrivalTime === undefined ||
22754
22844
  arrivalData.arrival < fastestArrivalTime)) {
@@ -22766,7 +22856,7 @@ class Result {
22766
22856
  let round = fastestLegNumber;
22767
22857
  let previousVehicleEdge;
22768
22858
  while (round >= 0) {
22769
- const edge = (_a = this.routingState.graph[round]) === null || _a === void 0 ? void 0 : _a[currentStop];
22859
+ const edge = (_a = __classPrivateFieldGet(this, _Result_routingState, "f").graph[round]) === null || _a === void 0 ? void 0 : _a[currentStop];
22770
22860
  if (!edge) {
22771
22861
  if (round === 0)
22772
22862
  break;
@@ -22928,34 +23018,14 @@ class Result {
22928
23018
  * than this result's destination set.
22929
23019
  *
22930
23020
  * @param stop The target stop for which to return the arrival time.
22931
- * @param maxTransfers The optional maximum number of transfers allowed.
23021
+ * @param maxTransfers Optional transfer limit within retained data.
22932
23022
  * @returns The arrival time if the target stop is reachable, otherwise undefined.
22933
23023
  */
22934
23024
  arrivalAt(stop, maxTransfers) {
22935
- var _a, _b;
22936
23025
  const equivalentStops = this.stopsIndex.equivalentStops(stop);
22937
23026
  let earliestArrival = undefined;
22938
23027
  for (const equivalentStop of equivalentStops) {
22939
- let arrivalTime;
22940
- if (maxTransfers === undefined ||
22941
- ((_a = this.routingState.getArrival(equivalentStop.id)) === null || _a === void 0 ? void 0 : _a.legNumber) ===
22942
- maxTransfers + 1) {
22943
- arrivalTime = this.routingState.getArrival(equivalentStop.id);
22944
- }
22945
- else {
22946
- // We have no guarantee that the stop was visited in the last round,
22947
- // so we need to check all rounds if it's not found in the last one.
22948
- for (let i = maxTransfers + 1; i >= 0; i--) {
22949
- const arrivalEdge = (_b = this.routingState.graph[i]) === null || _b === void 0 ? void 0 : _b[equivalentStop.id];
22950
- if (arrivalEdge !== undefined) {
22951
- arrivalTime = {
22952
- arrival: arrivalEdge.arrival,
22953
- legNumber: i,
22954
- };
22955
- break;
22956
- }
22957
- }
22958
- }
23028
+ const arrivalTime = this.concreteArrivalAt(equivalentStop.id, maxTransfers);
22959
23029
  if (arrivalTime !== undefined) {
22960
23030
  if (earliestArrival === undefined ||
22961
23031
  arrivalTime.arrival < earliestArrival.arrival) {
@@ -23366,7 +23436,7 @@ class PlainRouter {
23366
23436
  .map((destination) => destination.id);
23367
23437
  const routingState = new RoutingState(query.departureTime, destinations, accessLegs, this.timetable.nbStops(), query.options.maxTransfers + 1, query.options.maxDuration);
23368
23438
  this.raptor.run(query.options, routingState);
23369
- return new Result(new Set(destinations), routingState, this.stopsIndex, this.timetable);
23439
+ return new Result(routingState, this.stopsIndex, this.timetable);
23370
23440
  }
23371
23441
  }
23372
23442
 
@@ -23385,53 +23455,50 @@ class PlainRouter {
23385
23455
  * strictly earlier *and* arrives strictly earlier than the previous one,
23386
23456
  * forming the classic staircase Pareto frontier.
23387
23457
  *
23388
- * **Full-network mode** (empty `destinations`): when no destinations are
23458
+ * **Full-network mode** (no query destinations): when no destinations are
23389
23459
  * supplied to the range query every departure slot in the window becomes its
23390
23460
  * own run, because destination-based Pareto pruning cannot be applied.
23391
- * In this mode the destination-specific helpers ({@link getRoutes},
23461
+ * In this mode the destination-specific helpers ({@link routes},
23392
23462
  * {@link bestRoute}, {@link latestDepartureRoute}, {@link fastestRoute})
23393
- * return empty results; use {@link allEarliestArrivals},
23394
- * {@link allShortestDurations}, {@link earliestArrivalAt}, or
23463
+ * return empty results; use {@link arrivals},
23464
+ * {@link shortestDurations}, {@link arrivalAt}, or
23395
23465
  * {@link shortestDurationTo} instead.
23396
23466
  *
23397
23467
  * Destination handling is delegated to {@link Result}, which expands
23398
23468
  * equivalent stops when reconstructing routes or looking up arrivals.
23399
23469
  */
23400
23470
  class RangeResult {
23401
- constructor(runs, destinations) {
23471
+ constructor(runs) {
23402
23472
  this._runs = runs;
23403
- this._destinations = destinations;
23404
- }
23405
- /** The resolved destination stop IDs for this result. */
23406
- get destinations() {
23407
- return this._destinations;
23408
23473
  }
23409
23474
  normalizeTargets(to) {
23475
+ var _a;
23410
23476
  if (to instanceof Set)
23411
23477
  return new Set(to);
23412
23478
  if (to !== undefined)
23413
23479
  return new Set([to]);
23414
- return new Set(this._destinations);
23480
+ return new Set((_a = this._runs[0]) === null || _a === void 0 ? void 0 : _a.result[resultDestinations]());
23415
23481
  }
23416
23482
  /**
23417
- * Returns all non-dominated routes to this result's default destination set,
23483
+ * Lazily yields all non-dominated routes to this result's default destination set,
23418
23484
  * ordered from the earliest departure to the latest departure.
23419
23485
  *
23420
- * Each route in the list departs strictly earlier *and* arrives strictly
23421
- * earlier than its predecessor.
23486
+ * Each route in the list departs strictly later *and* arrives strictly
23487
+ * later than its predecessor.
23422
23488
  *
23423
- * Returns an empty array when no destinations were provided (full-network
23424
- * mode). Use {@link allEarliestArrivals} or {@link allShortestDurations}
23489
+ * Yields nothing when no destinations were provided (full-network
23490
+ * mode). Use {@link arrivals} or {@link shortestDurations}
23425
23491
  * to query individual stops in that case.
23426
23492
  */
23427
- getRoutes() {
23428
- const routes = [];
23429
- for (const { result } of this._runs) {
23430
- const route = result.bestRoute();
23493
+ *routes() {
23494
+ for (let index = this._runs.length - 1; index >= 0; index--) {
23495
+ const run = this._runs[index];
23496
+ if (run === undefined)
23497
+ continue;
23498
+ const route = run.result.bestRoute();
23431
23499
  if (route !== undefined)
23432
- routes.push(route);
23500
+ yield route;
23433
23501
  }
23434
- return routes.reverse();
23435
23502
  }
23436
23503
  /**
23437
23504
  * The route that arrives **earliest** at the given stop(s) across all
@@ -23446,16 +23513,17 @@ class RangeResult {
23446
23513
  * (no destinations), otherwise `undefined` is returned.
23447
23514
  *
23448
23515
  * @param to Optional destination stop ID or set of stop IDs.
23516
+ * @param maxTransfers Optional transfer limit within retained data.
23449
23517
  * @returns The reconstructed {@link Route} with the earliest arrival,
23450
23518
  * or `undefined` if the target is unreachable in every run.
23451
23519
  */
23452
- bestRoute(to) {
23520
+ bestRoute(to, maxTransfers) {
23453
23521
  const targetStops = this.normalizeTargets(to);
23454
23522
  let bestRun;
23455
23523
  let bestArrival;
23456
23524
  for (const run of this._runs) {
23457
23525
  for (const stopId of targetStops) {
23458
- const arrival = run.result.arrivalAt(stopId);
23526
+ const arrival = run.result.arrivalAt(stopId, maxTransfers);
23459
23527
  if (arrival === undefined)
23460
23528
  continue;
23461
23529
  if (bestArrival === undefined || arrival.arrival < bestArrival) {
@@ -23464,7 +23532,7 @@ class RangeResult {
23464
23532
  }
23465
23533
  }
23466
23534
  }
23467
- return bestRun === null || bestRun === void 0 ? void 0 : bestRun.result.bestRoute(targetStops);
23535
+ return bestRun === null || bestRun === void 0 ? void 0 : bestRun.result.bestRoute(targetStops, maxTransfers);
23468
23536
  }
23469
23537
  /**
23470
23538
  * The route with the **latest possible departure** from the origin among all
@@ -23480,13 +23548,14 @@ class RangeResult {
23480
23548
  * (no destinations), otherwise `undefined` is returned.
23481
23549
  *
23482
23550
  * @param to Optional destination stop ID or set of stop IDs.
23551
+ * @param maxTransfers Optional transfer limit within retained data.
23483
23552
  * @returns The reconstructed {@link Route} with the latest departure,
23484
23553
  * or `undefined` if the target is unreachable in every run.
23485
23554
  */
23486
- latestDepartureRoute(to) {
23555
+ latestDepartureRoute(to, maxTransfers) {
23487
23556
  const targetStops = this.normalizeTargets(to);
23488
23557
  for (const { result } of this._runs) {
23489
- const route = result.bestRoute(targetStops);
23558
+ const route = result.bestRoute(targetStops, maxTransfers);
23490
23559
  if (route !== undefined)
23491
23560
  return route;
23492
23561
  }
@@ -23506,16 +23575,17 @@ class RangeResult {
23506
23575
  * (no destinations), otherwise `undefined` is returned.
23507
23576
  *
23508
23577
  * @param to Optional destination stop ID or set of stop IDs.
23578
+ * @param maxTransfers Optional transfer limit within retained data.
23509
23579
  * @returns The reconstructed fastest {@link Route}, or `undefined` if the
23510
23580
  * target is unreachable in every run.
23511
23581
  */
23512
- fastestRoute(to) {
23582
+ fastestRoute(to, maxTransfers) {
23513
23583
  const targetStops = this.normalizeTargets(to);
23514
23584
  let fastestRun;
23515
23585
  let shortestDuration = Infinity;
23516
23586
  for (const run of this._runs) {
23517
23587
  for (const stopId of targetStops) {
23518
- const arrival = run.result.arrivalAt(stopId);
23588
+ const arrival = run.result.arrivalAt(stopId, maxTransfers);
23519
23589
  if (arrival === undefined)
23520
23590
  continue;
23521
23591
  const duration = arrival.arrival - run.departureTime;
@@ -23528,7 +23598,7 @@ class RangeResult {
23528
23598
  }
23529
23599
  }
23530
23600
  }
23531
- return fastestRun === null || fastestRun === void 0 ? void 0 : fastestRun.result.bestRoute(targetStops);
23601
+ return fastestRun === null || fastestRun === void 0 ? void 0 : fastestRun.result.bestRoute(targetStops, maxTransfers);
23532
23602
  }
23533
23603
  /** Number of Pareto-optimal journeys found. */
23534
23604
  get size() {
@@ -23544,9 +23614,9 @@ class RangeResult {
23544
23614
  * Equivalent stops are handled by {@link Result.arrivalAt}.
23545
23615
  *
23546
23616
  * @param stop The target stop ID.
23547
- * @param maxTransfers Optional upper bound on the number of transfers.
23617
+ * @param maxTransfers Optional transfer limit within retained data.
23548
23618
  */
23549
- earliestArrivalAt(stop, maxTransfers) {
23619
+ arrivalAt(stop, maxTransfers) {
23550
23620
  let best;
23551
23621
  for (const { result } of this._runs) {
23552
23622
  const arrival = result.arrivalAt(stop, maxTransfers);
@@ -23573,7 +23643,7 @@ class RangeResult {
23573
23643
  * Returns `undefined` if `stop` is unreachable in every run.
23574
23644
  *
23575
23645
  * @param stop The target stop ID.
23576
- * @param maxTransfers Optional upper bound on the number of transfers.
23646
+ * @param maxTransfers Optional transfer limit within retained data.
23577
23647
  */
23578
23648
  shortestDurationTo(stop, maxTransfers) {
23579
23649
  let shortest;
@@ -23590,12 +23660,15 @@ class RangeResult {
23590
23660
  }
23591
23661
  /**
23592
23662
  * Shortest travel duration to **every reachable stop** across all
23593
- * Pareto-optimal runs, as a single `Map<StopId, DurationArrival>`.
23663
+ * Pareto-optimal runs, yielding the stop ID and arrival with duration.
23664
+ * All runs are aggregated before the first value is yielded. Ties retain
23665
+ * the first run's arrival and leg count.
23666
+ * @param maxTransfers Optional transfer limit within retained data.
23594
23667
  */
23595
- allShortestDurations() {
23668
+ *shortestDurations(maxTransfers) {
23596
23669
  const durations = new Map();
23597
23670
  for (const { departureTime, result } of this._runs) {
23598
- for (const { stop, arrival, legNumber, } of result.routingState.arrivals()) {
23671
+ for (const { stop, arrival, legNumber } of result.arrivals(maxTransfers)) {
23599
23672
  const duration = arrival - departureTime;
23600
23673
  const existing = durations.get(stop);
23601
23674
  if (existing === undefined || duration < existing.duration) {
@@ -23603,23 +23676,30 @@ class RangeResult {
23603
23676
  }
23604
23677
  }
23605
23678
  }
23606
- return durations;
23679
+ for (const [stop, arrival] of durations) {
23680
+ yield Object.assign({ stop }, arrival);
23681
+ }
23607
23682
  }
23608
23683
  /**
23609
23684
  * Earliest achievable arrival at **every reachable stop** across all
23610
- * Pareto-optimal runs, as a single `Map<StopId, Arrival>`.
23685
+ * Pareto-optimal runs, yielding the stop ID and arrival.
23686
+ * All runs are aggregated before the first value is yielded. Ties retain
23687
+ * the first run's arrival and leg count.
23688
+ * @param maxTransfers Optional transfer limit within retained data.
23611
23689
  */
23612
- allEarliestArrivals() {
23690
+ *arrivals(maxTransfers) {
23613
23691
  const arrivals = new Map();
23614
23692
  for (const { result } of this._runs) {
23615
- for (const { stop, arrival, legNumber, } of result.routingState.arrivals()) {
23693
+ for (const { stop, arrival, legNumber } of result.arrivals(maxTransfers)) {
23616
23694
  const existing = arrivals.get(stop);
23617
23695
  if (existing === undefined || arrival < existing.arrival) {
23618
23696
  arrivals.set(stop, { arrival, legNumber });
23619
23697
  }
23620
23698
  }
23621
23699
  }
23622
- return arrivals;
23700
+ for (const [stop, arrival] of arrivals) {
23701
+ yield Object.assign({ stop }, arrival);
23702
+ }
23623
23703
  }
23624
23704
  /**
23625
23705
  * Iterates over all Pareto-optimal `(departureTime, result)` pairs,
@@ -23771,7 +23851,7 @@ class RangeRouter {
23771
23851
  const accessLegs = this.accessFinder.collectAccessPaths(query.from, query.options.minTransferTime);
23772
23852
  const departureSlots = this.accessFinder.collectDepartureTimes(accessLegs, earliest, latest);
23773
23853
  if (departureSlots.length === 0) {
23774
- return new RangeResult([], new Set(destinations));
23854
+ return new RangeResult([]);
23775
23855
  }
23776
23856
  const maxRounds = query.options.maxTransfers + 1;
23777
23857
  const rangeState = new RangeRaptorState(maxRounds, this.timetable.nbStops(), latest);
@@ -23830,12 +23910,12 @@ class RangeRouter {
23830
23910
  if (isParetoOptimal) {
23831
23911
  paretoRuns.push({
23832
23912
  departureTime: depTime,
23833
- result: new Result(new Set(destinations), routingState, this.stopsIndex, this.timetable),
23913
+ result: new Result(routingState, this.stopsIndex, this.timetable),
23834
23914
  });
23835
23915
  routingState = null;
23836
23916
  }
23837
23917
  }
23838
- return new RangeResult(paretoRuns, new Set(destinations));
23918
+ return new RangeResult(paretoRuns);
23839
23919
  }
23840
23920
  }
23841
23921
 
@@ -24338,24 +24418,24 @@ const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
24338
24418
  return results;
24339
24419
  };
24340
24420
  /**
24341
- * Benchmarks {@link RangeResult.getRoutes} — the full Pareto-frontier
24421
+ * Benchmarks {@link RangeResult.routes} — the full Pareto-frontier
24342
24422
  * reconstruction phase — independently of the range routing phase.
24343
24423
  *
24344
24424
  * @param router - The router instance used to produce the range results that
24345
- * are then fed into `getRoutes`.
24425
+ * are then fed into `routes`.
24346
24426
  * @param tasks - The list of range queries to benchmark. One
24347
24427
  * {@link PerformanceResult} is produced per query.
24348
- * @param iterations - Number of times `getRoutes` is called per query.
24428
+ * @param iterations - Number of times `routes` is fully consumed per query.
24349
24429
  * @param stopsIndex - Used to resolve stop names for result labels.
24350
24430
  * @returns An array of {@link PerformanceResult} objects, one per query, each
24351
24431
  * containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
24352
- * `getRoutes` call alone.
24432
+ * full `routes` iteration alone.
24353
24433
  */
24354
24434
  const testRangeResultPerformance = (router, tasks, iterations, stopsIndex) => {
24355
24435
  const results = [];
24356
24436
  for (const task of tasks) {
24357
24437
  const rangeResult = router.rangeRoute(task);
24358
- results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => rangeResult.getRoutes(), iterations)));
24438
+ results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => [...rangeResult.routes()], iterations)));
24359
24439
  }
24360
24440
  return results;
24361
24441
  };
@@ -24556,7 +24636,7 @@ const startRepl = (stopsPath, timetablePath) => {
24556
24636
  console.log(`Found ${result.size} Pareto-optimal journey${result.size === 1 ? '' : 's'} ` +
24557
24637
  `from ${fromStop.name} to ${toStop.name} ` +
24558
24638
  `(window ${atTime}–${beforeTime}):`);
24559
- const routes = result.getRoutes();
24639
+ const routes = [...result.routes()];
24560
24640
  routes.forEach((route, index) => {
24561
24641
  const journeyNumber = index + 1;
24562
24642
  console.log(`\nJourney ${journeyNumber}:`);
@@ -24902,12 +24982,7 @@ program
24902
24982
  .option('--virtual-transfers-radius <meters>', 'Generate virtual walking transfers between stops within this radius (in meters). Disabled when omitted.')
24903
24983
  .option('-v, --verbose', 'Verbose mode', false)
24904
24984
  .action((gtfsPath, options) => __awaiter(void 0, void 0, void 0, function* () {
24905
- if (options.verbose) {
24906
- log.setDefaultLevel(log.levels.INFO);
24907
- }
24908
- else {
24909
- log.setDefaultLevel(log.levels.ERROR);
24910
- }
24985
+ setParserLogLevel(options.verbose ? 'info' : 'error');
24911
24986
  const radiusMeters = options.virtualTransfersRadius !== undefined
24912
24987
  ? parseInt(options.virtualTransfersRadius, 10)
24913
24988
  : undefined;
@@ -24930,12 +25005,7 @@ program
24930
25005
  .option('-p, --profileName <name>', 'Profile name for GTFS config', 'CH')
24931
25006
  .option('-v, --verbose', 'Verbose mode', false)
24932
25007
  .action((gtfsPath, options) => __awaiter(void 0, void 0, void 0, function* () {
24933
- if (options.verbose) {
24934
- log.setDefaultLevel(log.levels.INFO);
24935
- }
24936
- else {
24937
- log.setDefaultLevel(log.levels.ERROR);
24938
- }
25008
+ setParserLogLevel(options.verbose ? 'info' : 'error');
24939
25009
  const parser = new GtfsParser(gtfsPath, profiles[options.profileName]);
24940
25010
  const stopsIndex = yield parser.parseStops();
24941
25011
  fs$1.writeFileSync(options.stopsOutputPath, stopsIndex.serialize());
@@ -24978,7 +25048,7 @@ program
24978
25048
  const rangeRouterResults = testRangeRouterPerformance(router, rangeQueries, iterations, stopsIndex);
24979
25049
  prettyPrintPerformanceResults(rangeRouterResults, 'Range queries — router.rangeRoute()');
24980
25050
  const rangeResultResults = testRangeResultPerformance(router, rangeQueries, iterations, stopsIndex);
24981
- prettyPrintPerformanceResults(rangeResultResults, 'Range queries — rangeResult.getRoutes() (reconstruction only)');
25051
+ prettyPrintPerformanceResults(rangeResultResults, 'Range queries — rangeResult.routes() (reconstruction only)');
24982
25052
  });
24983
25053
  program.parse(process.argv);
24984
25054
  //# sourceMappingURL=cli.mjs.map