minotor 13.0.0 → 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.
package/dist/cli.mjs CHANGED
@@ -4245,1431 +4245,1057 @@ function useColor() {
4245
4245
 
4246
4246
  new Command();
4247
4247
 
4248
- function getDefaultExportFromCjs (x) {
4249
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
4250
- }
4248
+ // these aren't really private, but nor are they really useful to document
4251
4249
 
4252
- var loglevel$1 = {exports: {}};
4250
+ /**
4251
+ * @private
4252
+ */
4253
+ class LuxonError extends Error {}
4253
4254
 
4254
- /*
4255
- * loglevel - https://github.com/pimterry/loglevel
4256
- *
4257
- * Copyright (c) 2013 Tim Perry
4258
- * Licensed under the MIT license.
4259
- */
4260
- 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
+ }
4261
4263
 
4262
- var hasRequiredLoglevel;
4264
+ /**
4265
+ * @private
4266
+ */
4267
+ class InvalidIntervalError extends LuxonError {
4268
+ constructor(reason) {
4269
+ super(`Invalid Interval: ${reason.toMessage()}`);
4270
+ }
4271
+ }
4263
4272
 
4264
- function requireLoglevel () {
4265
- if (hasRequiredLoglevel) return loglevel$1.exports;
4266
- hasRequiredLoglevel = 1;
4267
- (function (module) {
4268
- (function (root, definition) {
4269
- if (module.exports) {
4270
- module.exports = definition();
4271
- } else {
4272
- root.log = definition();
4273
- }
4274
- }(loglevel, function () {
4273
+ /**
4274
+ * @private
4275
+ */
4276
+ class InvalidDurationError extends LuxonError {
4277
+ constructor(reason) {
4278
+ super(`Invalid Duration: ${reason.toMessage()}`);
4279
+ }
4280
+ }
4275
4281
 
4276
- // Slightly dubious tricks to cut down minimized file size
4277
- var noop = function() {};
4278
- var undefinedType = "undefined";
4279
- var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (
4280
- /Trident\/|MSIE /.test(window.navigator.userAgent)
4281
- );
4282
+ /**
4283
+ * @private
4284
+ */
4285
+ class ConflictingSpecificationError extends LuxonError {}
4282
4286
 
4283
- var logMethods = [
4284
- "trace",
4285
- "debug",
4286
- "info",
4287
- "warn",
4288
- "error"
4289
- ];
4287
+ /**
4288
+ * @private
4289
+ */
4290
+ class InvalidUnitError extends LuxonError {
4291
+ constructor(unit) {
4292
+ super(`Invalid unit ${unit}`);
4293
+ }
4294
+ }
4290
4295
 
4291
- var _loggersByName = {};
4292
- var defaultLogger = null;
4296
+ /**
4297
+ * @private
4298
+ */
4299
+ class InvalidArgumentError extends LuxonError {}
4293
4300
 
4294
- // Cross-browser bind equivalent that works at least back to IE6
4295
- function bindMethod(obj, methodName) {
4296
- var method = obj[methodName];
4297
- if (typeof method.bind === 'function') {
4298
- return method.bind(obj);
4299
- } else {
4300
- try {
4301
- return Function.prototype.bind.call(method, obj);
4302
- } catch (e) {
4303
- // Missing bind shim or IE8 + Modernizr, fallback to wrapping
4304
- return function() {
4305
- return Function.prototype.apply.apply(method, [obj, arguments]);
4306
- };
4307
- }
4308
- }
4309
- }
4301
+ /**
4302
+ * @private
4303
+ */
4304
+ class ZoneIsAbstractError extends LuxonError {
4305
+ constructor() {
4306
+ super("Zone is an abstract class");
4307
+ }
4308
+ }
4310
4309
 
4311
- // Trace() doesn't print the message in IE, so for that case we need to wrap it
4312
- function traceForIE() {
4313
- if (console.log) {
4314
- if (console.log.apply) {
4315
- console.log.apply(console, arguments);
4316
- } else {
4317
- // In old IE, native console methods themselves don't have apply().
4318
- Function.prototype.apply.apply(console.log, [console, arguments]);
4319
- }
4320
- }
4321
- if (console.trace) console.trace();
4322
- }
4310
+ /**
4311
+ * @private
4312
+ */
4323
4313
 
4324
- // Build the best logging method possible for this env
4325
- // Wherever possible we want to bind, not wrap, to preserve stack traces
4326
- function realMethod(methodName) {
4327
- if (methodName === 'debug') {
4328
- methodName = 'log';
4329
- }
4314
+ const n$1 = "numeric",
4315
+ s$2 = "short",
4316
+ l$1 = "long";
4330
4317
 
4331
- if (typeof console === undefinedType) {
4332
- return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
4333
- } else if (methodName === 'trace' && isIE) {
4334
- return traceForIE;
4335
- } else if (console[methodName] !== undefined) {
4336
- return bindMethod(console, methodName);
4337
- } else if (console.log !== undefined) {
4338
- return bindMethod(console, 'log');
4339
- } else {
4340
- return noop;
4341
- }
4342
- }
4318
+ const DATE_SHORT = {
4319
+ year: n$1,
4320
+ month: n$1,
4321
+ day: n$1,
4322
+ };
4343
4323
 
4344
- // 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
+ };
4345
4329
 
4346
- function replaceLoggingMethods() {
4347
- /*jshint validthis:true */
4348
- 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
+ };
4349
4336
 
4350
- // Replace the actual methods.
4351
- for (var i = 0; i < logMethods.length; i++) {
4352
- var methodName = logMethods[i];
4353
- this[methodName] = (i < level) ?
4354
- noop :
4355
- this.methodFactory(methodName, level, this.name);
4356
- }
4337
+ const DATE_FULL = {
4338
+ year: n$1,
4339
+ month: l$1,
4340
+ day: n$1,
4341
+ };
4357
4342
 
4358
- // Define log.log as an alias for log.debug
4359
- 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
+ };
4360
4349
 
4361
- // Return any important warnings.
4362
- if (typeof console === undefinedType && level < this.levels.SILENT) {
4363
- return "No console available for logging";
4364
- }
4365
- }
4350
+ const TIME_SIMPLE = {
4351
+ hour: n$1,
4352
+ minute: n$1,
4353
+ };
4366
4354
 
4367
- // In old IE versions, the console isn't present until you first open it.
4368
- // We build realMethod() replacements here that regenerate logging methods
4369
- function enableLoggingWhenConsoleArrives(methodName) {
4370
- return function () {
4371
- if (typeof console !== undefinedType) {
4372
- replaceLoggingMethods.call(this);
4373
- this[methodName].apply(this, arguments);
4374
- }
4375
- };
4376
- }
4355
+ const TIME_WITH_SECONDS = {
4356
+ hour: n$1,
4357
+ minute: n$1,
4358
+ second: n$1,
4359
+ };
4377
4360
 
4378
- // By default, we use closely bound real methods wherever possible, and
4379
- // otherwise we wait for a console to appear, and then try again.
4380
- function defaultMethodFactory(methodName, _level, _loggerName) {
4381
- /*jshint validthis:true */
4382
- return realMethod(methodName) ||
4383
- enableLoggingWhenConsoleArrives.apply(this, arguments);
4384
- }
4361
+ const TIME_WITH_SHORT_OFFSET = {
4362
+ hour: n$1,
4363
+ minute: n$1,
4364
+ second: n$1,
4365
+ timeZoneName: s$2,
4366
+ };
4385
4367
 
4386
- function Logger(name, factory) {
4387
- // Private instance variables.
4388
- var self = this;
4389
- /**
4390
- * The level inherited from a parent logger (or a global default). We
4391
- * cache this here rather than delegating to the parent so that it stays
4392
- * in sync with the actual logging methods that we have installed (the
4393
- * parent could change levels but we might not have rebuilt the loggers
4394
- * in this child yet).
4395
- * @type {number}
4396
- */
4397
- var inheritedLevel;
4398
- /**
4399
- * The default level for this logger, if any. If set, this overrides
4400
- * `inheritedLevel`.
4401
- * @type {number|null}
4402
- */
4403
- var defaultLevel;
4404
- /**
4405
- * A user-specific level for this logger. If set, this overrides
4406
- * `defaultLevel`.
4407
- * @type {number|null}
4408
- */
4409
- 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
+ };
4410
4374
 
4411
- var storageKey = "loglevel";
4412
- if (typeof name === "string") {
4413
- storageKey += ":" + name;
4414
- } else if (typeof name === "symbol") {
4415
- storageKey = undefined;
4416
- }
4417
-
4418
- function persistLevelIfPossible(levelNum) {
4419
- var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
4375
+ const TIME_24_SIMPLE = {
4376
+ hour: n$1,
4377
+ minute: n$1,
4378
+ hourCycle: "h23",
4379
+ };
4420
4380
 
4421
- if (typeof window === undefinedType || !storageKey) return;
4381
+ const TIME_24_WITH_SECONDS = {
4382
+ hour: n$1,
4383
+ minute: n$1,
4384
+ second: n$1,
4385
+ hourCycle: "h23",
4386
+ };
4422
4387
 
4423
- // Use localStorage if available
4424
- try {
4425
- window.localStorage[storageKey] = levelName;
4426
- return;
4427
- } catch (ignore) {}
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
+ };
4428
4395
 
4429
- // Use session cookie as fallback
4430
- try {
4431
- window.document.cookie =
4432
- encodeURIComponent(storageKey) + "=" + levelName + ";";
4433
- } catch (ignore) {}
4434
- }
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
+ };
4435
4403
 
4436
- function getPersistedLevel() {
4437
- var storedLevel;
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
+ };
4438
4411
 
4439
- if (typeof window === undefinedType || !storageKey) return;
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
+ };
4440
4420
 
4441
- try {
4442
- storedLevel = window.localStorage[storageKey];
4443
- } catch (ignore) {}
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
+ };
4444
4428
 
4445
- // Fallback to cookies if local storage gives us nothing
4446
- if (typeof storedLevel === undefinedType) {
4447
- try {
4448
- var cookie = window.document.cookie;
4449
- var cookieName = encodeURIComponent(storageKey);
4450
- var location = cookie.indexOf(cookieName + "=");
4451
- if (location !== -1) {
4452
- storedLevel = /^([^;]+)/.exec(
4453
- cookie.slice(location + cookieName.length + 1)
4454
- )[1];
4455
- }
4456
- } catch (ignore) {}
4457
- }
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
+ };
4458
4437
 
4459
- // If the stored level is not valid, treat it as if nothing was stored.
4460
- if (self.levels[storedLevel] === undefined) {
4461
- storedLevel = undefined;
4462
- }
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
+ };
4463
4446
 
4464
- return storedLevel;
4465
- }
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
+ };
4466
4455
 
4467
- function clearPersistedLevel() {
4468
- if (typeof window === undefinedType || !storageKey) return;
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
+ };
4469
4465
 
4470
- // Use localStorage if available
4471
- try {
4472
- window.localStorage.removeItem(storageKey);
4473
- } catch (ignore) {}
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
+ };
4474
4475
 
4475
- // Use session cookie as fallback
4476
- try {
4477
- window.document.cookie =
4478
- encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
4479
- } catch (ignore) {}
4480
- }
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
+ };
4481
4486
 
4482
- function normalizeLevel(input) {
4483
- var level = input;
4484
- if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
4485
- level = self.levels[level.toUpperCase()];
4486
- }
4487
- if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
4488
- return level;
4489
- } else {
4490
- throw new TypeError("log.setLevel() called with invalid level: " + input);
4491
- }
4492
- }
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
+ }
4493
4499
 
4494
- /*
4495
- *
4496
- * Public logger API - see https://github.com/pimterry/loglevel for details
4497
- *
4498
- */
4500
+ /**
4501
+ * The name of this zone.
4502
+ * @abstract
4503
+ * @type {string}
4504
+ */
4505
+ get name() {
4506
+ throw new ZoneIsAbstractError();
4507
+ }
4499
4508
 
4500
- self.name = name;
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
+ }
4501
4518
 
4502
- self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
4503
- "ERROR": 4, "SILENT": 5};
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
+ }
4504
4527
 
4505
- self.methodFactory = factory || defaultMethodFactory;
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
+ }
4506
4540
 
4507
- self.getLevel = function () {
4508
- if (userLevel != null) {
4509
- return userLevel;
4510
- } else if (defaultLevel != null) {
4511
- return defaultLevel;
4512
- } else {
4513
- return inheritedLevel;
4514
- }
4515
- };
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
+ }
4516
4552
 
4517
- self.setLevel = function (level, persist) {
4518
- userLevel = normalizeLevel(level);
4519
- if (persist !== false) { // defaults to true
4520
- persistLevelIfPossible(userLevel);
4521
- }
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
+ }
4522
4562
 
4523
- // NOTE: in v2, this should call rebuild(), which updates children.
4524
- return replaceLoggingMethods.call(self);
4525
- };
4526
-
4527
- self.setDefaultLevel = function (level) {
4528
- defaultLevel = normalizeLevel(level);
4529
- if (!getPersistedLevel()) {
4530
- self.setLevel(level, false);
4531
- }
4532
- };
4533
-
4534
- self.resetLevel = function () {
4535
- userLevel = null;
4536
- clearPersistedLevel();
4537
- replaceLoggingMethods.call(self);
4538
- };
4539
-
4540
- self.enableAll = function(persist) {
4541
- self.setLevel(self.levels.TRACE, persist);
4542
- };
4543
-
4544
- self.disableAll = function(persist) {
4545
- self.setLevel(self.levels.SILENT, persist);
4546
- };
4547
-
4548
- self.rebuild = function () {
4549
- if (defaultLogger !== self) {
4550
- inheritedLevel = normalizeLevel(defaultLogger.getLevel());
4551
- }
4552
- replaceLoggingMethods.call(self);
4553
-
4554
- if (defaultLogger === self) {
4555
- for (var childName in _loggersByName) {
4556
- _loggersByName[childName].rebuild();
4557
- }
4558
- }
4559
- };
4560
-
4561
- // Initialize all the internal levels.
4562
- inheritedLevel = normalizeLevel(
4563
- defaultLogger ? defaultLogger.getLevel() : "WARN"
4564
- );
4565
- var initialLevel = getPersistedLevel();
4566
- if (initialLevel != null) {
4567
- userLevel = normalizeLevel(initialLevel);
4568
- }
4569
- replaceLoggingMethods.call(self);
4570
- }
4571
-
4572
- /*
4573
- *
4574
- * Top-level API
4575
- *
4576
- */
4577
-
4578
- defaultLogger = new Logger();
4579
-
4580
- defaultLogger.getLogger = function getLogger(name) {
4581
- if ((typeof name !== "symbol" && typeof name !== "string") || name === "") {
4582
- throw new TypeError("You must supply a name when creating a logger.");
4583
- }
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
+ }
4584
4572
 
4585
- var logger = _loggersByName[name];
4586
- if (!logger) {
4587
- logger = _loggersByName[name] = new Logger(
4588
- name,
4589
- defaultLogger.methodFactory
4590
- );
4591
- }
4592
- return logger;
4593
- };
4573
+ /**
4574
+ * Return whether this Zone is valid.
4575
+ * @abstract
4576
+ * @type {boolean}
4577
+ */
4578
+ get isValid() {
4579
+ throw new ZoneIsAbstractError();
4580
+ }
4581
+ }
4594
4582
 
4595
- // Grab the current global log variable in case of overwrite
4596
- var _log = (typeof window !== undefinedType) ? window.log : undefined;
4597
- defaultLogger.noConflict = function() {
4598
- if (typeof window !== undefinedType &&
4599
- window.log === defaultLogger) {
4600
- window.log = _log;
4601
- }
4583
+ let singleton$1 = null;
4602
4584
 
4603
- return defaultLogger;
4604
- };
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
+ }
4605
4600
 
4606
- defaultLogger.getLoggers = function getLoggers() {
4607
- return _loggersByName;
4608
- };
4601
+ /** @override **/
4602
+ get type() {
4603
+ return "system";
4604
+ }
4609
4605
 
4610
- // ES6 default export, for compatibility
4611
- defaultLogger['default'] = defaultLogger;
4606
+ /** @override **/
4607
+ get name() {
4608
+ return new Intl.DateTimeFormat().resolvedOptions().timeZone;
4609
+ }
4612
4610
 
4613
- return defaultLogger;
4614
- }));
4615
- } (loglevel$1));
4616
- return loglevel$1.exports;
4617
- }
4611
+ /** @override **/
4612
+ get isUniversal() {
4613
+ return false;
4614
+ }
4618
4615
 
4619
- var loglevelExports = requireLoglevel();
4620
- var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
4616
+ /** @override **/
4617
+ offsetName(ts, { format, locale }) {
4618
+ return parseZoneInfo(ts, format, locale);
4619
+ }
4621
4620
 
4622
- // 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
+ }
4623
4625
 
4624
- /**
4625
- * @private
4626
- */
4627
- class LuxonError extends Error {}
4626
+ /** @override **/
4627
+ offset(ts) {
4628
+ return -new Date(ts).getTimezoneOffset();
4629
+ }
4628
4630
 
4629
- /**
4630
- * @private
4631
- */
4632
- class InvalidDateTimeError extends LuxonError {
4633
- constructor(reason) {
4634
- super(`Invalid DateTime: ${reason.toMessage()}`);
4631
+ /** @override **/
4632
+ equals(otherZone) {
4633
+ return otherZone.type === "system";
4635
4634
  }
4636
- }
4637
4635
 
4638
- /**
4639
- * @private
4640
- */
4641
- class InvalidIntervalError extends LuxonError {
4642
- constructor(reason) {
4643
- super(`Invalid Interval: ${reason.toMessage()}`);
4636
+ /** @override **/
4637
+ get isValid() {
4638
+ return true;
4644
4639
  }
4645
4640
  }
4646
4641
 
4647
- /**
4648
- * @private
4649
- */
4650
- class InvalidDurationError extends LuxonError {
4651
- constructor(reason) {
4652
- 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);
4653
4658
  }
4659
+ return dtf;
4654
4660
  }
4655
4661
 
4656
- /**
4657
- * @private
4658
- */
4659
- 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
+ };
4660
4671
 
4661
- /**
4662
- * @private
4663
- */
4664
- class InvalidUnitError extends LuxonError {
4665
- constructor(unit) {
4666
- super(`Invalid unit ${unit}`);
4667
- }
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];
4668
4677
  }
4669
4678
 
4670
- /**
4671
- * @private
4672
- */
4673
- 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];
4674
4685
 
4675
- /**
4676
- * @private
4677
- */
4678
- class ZoneIsAbstractError extends LuxonError {
4679
- constructor() {
4680
- 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
+ }
4681
4691
  }
4692
+ return filled;
4682
4693
  }
4683
4694
 
4695
+ const ianaZoneCache = new Map();
4684
4696
  /**
4685
- * @private
4697
+ * A zone identified by an IANA identifier, like America/New_York
4698
+ * @implements {Zone}
4686
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
+ }
4687
4712
 
4688
- const n$1 = "numeric",
4689
- s$2 = "short",
4690
- l$1 = "long";
4691
-
4692
- const DATE_SHORT = {
4693
- year: n$1,
4694
- month: n$1,
4695
- day: n$1,
4696
- };
4697
-
4698
- const DATE_MED = {
4699
- year: n$1,
4700
- month: s$2,
4701
- day: n$1,
4702
- };
4703
-
4704
- const DATE_MED_WITH_WEEKDAY = {
4705
- year: n$1,
4706
- month: s$2,
4707
- day: n$1,
4708
- weekday: s$2,
4709
- };
4710
-
4711
- const DATE_FULL = {
4712
- year: n$1,
4713
- month: l$1,
4714
- day: n$1,
4715
- };
4716
-
4717
- const DATE_HUGE = {
4718
- year: n$1,
4719
- month: l$1,
4720
- day: n$1,
4721
- weekday: l$1,
4722
- };
4723
-
4724
- const TIME_SIMPLE = {
4725
- hour: n$1,
4726
- minute: n$1,
4727
- };
4728
-
4729
- const TIME_WITH_SECONDS = {
4730
- hour: n$1,
4731
- minute: n$1,
4732
- second: n$1,
4733
- };
4734
-
4735
- const TIME_WITH_SHORT_OFFSET = {
4736
- hour: n$1,
4737
- minute: n$1,
4738
- second: n$1,
4739
- timeZoneName: s$2,
4740
- };
4741
-
4742
- const TIME_WITH_LONG_OFFSET = {
4743
- hour: n$1,
4744
- minute: n$1,
4745
- second: n$1,
4746
- timeZoneName: l$1,
4747
- };
4748
-
4749
- const TIME_24_SIMPLE = {
4750
- hour: n$1,
4751
- minute: n$1,
4752
- hourCycle: "h23",
4753
- };
4754
-
4755
- const TIME_24_WITH_SECONDS = {
4756
- hour: n$1,
4757
- minute: n$1,
4758
- second: n$1,
4759
- hourCycle: "h23",
4760
- };
4761
-
4762
- const TIME_24_WITH_SHORT_OFFSET = {
4763
- hour: n$1,
4764
- minute: n$1,
4765
- second: n$1,
4766
- hourCycle: "h23",
4767
- timeZoneName: s$2,
4768
- };
4769
-
4770
- const TIME_24_WITH_LONG_OFFSET = {
4771
- hour: n$1,
4772
- minute: n$1,
4773
- second: n$1,
4774
- hourCycle: "h23",
4775
- timeZoneName: l$1,
4776
- };
4777
-
4778
- const DATETIME_SHORT = {
4779
- year: n$1,
4780
- month: n$1,
4781
- day: n$1,
4782
- hour: n$1,
4783
- minute: n$1,
4784
- };
4785
-
4786
- const DATETIME_SHORT_WITH_SECONDS = {
4787
- year: n$1,
4788
- month: n$1,
4789
- day: n$1,
4790
- hour: n$1,
4791
- minute: n$1,
4792
- second: n$1,
4793
- };
4794
-
4795
- const DATETIME_MED = {
4796
- year: n$1,
4797
- month: s$2,
4798
- day: n$1,
4799
- hour: n$1,
4800
- minute: n$1,
4801
- };
4802
-
4803
- const DATETIME_MED_WITH_SECONDS = {
4804
- year: n$1,
4805
- month: s$2,
4806
- day: n$1,
4807
- hour: n$1,
4808
- minute: n$1,
4809
- second: n$1,
4810
- };
4811
-
4812
- const DATETIME_MED_WITH_WEEKDAY = {
4813
- year: n$1,
4814
- month: s$2,
4815
- day: n$1,
4816
- weekday: s$2,
4817
- hour: n$1,
4818
- minute: n$1,
4819
- };
4820
-
4821
- const DATETIME_FULL = {
4822
- year: n$1,
4823
- month: l$1,
4824
- day: n$1,
4825
- hour: n$1,
4826
- minute: n$1,
4827
- timeZoneName: s$2,
4828
- };
4829
-
4830
- const DATETIME_FULL_WITH_SECONDS = {
4831
- year: n$1,
4832
- month: l$1,
4833
- day: n$1,
4834
- hour: n$1,
4835
- minute: n$1,
4836
- second: n$1,
4837
- timeZoneName: s$2,
4838
- };
4839
-
4840
- const DATETIME_HUGE = {
4841
- year: n$1,
4842
- month: l$1,
4843
- day: n$1,
4844
- weekday: l$1,
4845
- hour: n$1,
4846
- minute: n$1,
4847
- timeZoneName: l$1,
4848
- };
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
+ }
4849
4721
 
4850
- const DATETIME_HUGE_WITH_SECONDS = {
4851
- year: n$1,
4852
- month: l$1,
4853
- day: n$1,
4854
- weekday: l$1,
4855
- hour: n$1,
4856
- minute: n$1,
4857
- second: n$1,
4858
- timeZoneName: l$1,
4859
- };
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
+ }
4860
4733
 
4861
- /**
4862
- * @interface
4863
- */
4864
- class Zone {
4865
4734
  /**
4866
- * The type of zone
4867
- * @abstract
4868
- * @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}
4869
4741
  */
4870
- get type() {
4871
- 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);
4872
4760
  }
4873
4761
 
4874
4762
  /**
4875
- * The name of this zone.
4876
- * @abstract
4763
+ * The type of zone. `iana` for all instances of `IANAZone`.
4764
+ * @override
4877
4765
  * @type {string}
4878
4766
  */
4879
- get name() {
4880
- throw new ZoneIsAbstractError();
4767
+ get type() {
4768
+ return "iana";
4881
4769
  }
4882
4770
 
4883
4771
  /**
4884
- * The IANA name of this zone.
4885
- * Defaults to `name` if not overwritten by a subclass.
4886
- * @abstract
4772
+ * The name of this zone (i.e. the IANA zone name).
4773
+ * @override
4887
4774
  * @type {string}
4888
4775
  */
4889
- get ianaName() {
4890
- return this.name;
4776
+ get name() {
4777
+ return this.zoneName;
4891
4778
  }
4892
4779
 
4893
4780
  /**
4894
- * Returns whether the offset is known to be fixed for the whole year.
4895
- * @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
4896
4784
  * @type {boolean}
4897
4785
  */
4898
4786
  get isUniversal() {
4899
- throw new ZoneIsAbstractError();
4787
+ return false;
4900
4788
  }
4901
4789
 
4902
4790
  /**
4903
4791
  * Returns the offset's common name (such as EST) at the specified timestamp
4904
- * @abstract
4792
+ * @override
4905
4793
  * @param {number} ts - Epoch milliseconds for which to get the name
4906
4794
  * @param {Object} opts - Options to affect the format
4907
4795
  * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
4908
4796
  * @param {string} opts.locale - What locale to return the offset name in.
4909
4797
  * @return {string}
4910
4798
  */
4911
- offsetName(ts, opts) {
4912
- throw new ZoneIsAbstractError();
4799
+ offsetName(ts, { format, locale }) {
4800
+ return parseZoneInfo(ts, format, locale, this.name);
4913
4801
  }
4914
4802
 
4915
4803
  /**
4916
4804
  * Returns the offset's value as a string
4917
- * @abstract
4805
+ * @override
4918
4806
  * @param {number} ts - Epoch milliseconds for which to get the offset
4919
4807
  * @param {string} format - What style of offset to return.
4920
4808
  * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
4921
4809
  * @return {string}
4922
4810
  */
4923
4811
  formatOffset(ts, format) {
4924
- throw new ZoneIsAbstractError();
4812
+ return formatOffset(this.offset(ts), format);
4925
4813
  }
4926
4814
 
4927
4815
  /**
4928
4816
  * Return the offset in minutes for this zone at the specified timestamp.
4929
- * @abstract
4817
+ * @override
4930
4818
  * @param {number} ts - Epoch milliseconds for which to compute the offset
4931
4819
  * @return {number}
4932
4820
  */
4933
4821
  offset(ts) {
4934
- 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);
4935
4853
  }
4936
4854
 
4937
4855
  /**
4938
4856
  * Return whether this Zone is equal to another zone
4939
- * @abstract
4857
+ * @override
4940
4858
  * @param {Zone} otherZone - the zone to compare
4941
4859
  * @return {boolean}
4942
4860
  */
4943
4861
  equals(otherZone) {
4944
- throw new ZoneIsAbstractError();
4862
+ return otherZone.type === "iana" && otherZone.name === this.name;
4945
4863
  }
4946
4864
 
4947
4865
  /**
4948
4866
  * Return whether this Zone is valid.
4949
- * @abstract
4867
+ * @override
4950
4868
  * @type {boolean}
4951
4869
  */
4952
4870
  get isValid() {
4953
- throw new ZoneIsAbstractError();
4871
+ return this.valid;
4954
4872
  }
4955
4873
  }
4956
4874
 
4957
- let singleton$1 = null;
4875
+ // todo - remap caching
4958
4876
 
4959
- /**
4960
- * Represents the local zone for this JavaScript environment.
4961
- * @implements {Zone}
4962
- */
4963
- class SystemZone extends Zone {
4964
- /**
4965
- * Get a singleton instance of the local zone
4966
- * @return {SystemZone}
4967
- */
4968
- static get instance() {
4969
- if (singleton$1 === null) {
4970
- singleton$1 = new SystemZone();
4971
- }
4972
- 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;
4973
4884
  }
4885
+ return dtf;
4886
+ }
4974
4887
 
4975
- /** @override **/
4976
- get type() {
4977
- 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);
4978
4895
  }
4896
+ return dtf;
4897
+ }
4979
4898
 
4980
- /** @override **/
4981
- get name() {
4982
- 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);
4983
4906
  }
4907
+ return inf;
4908
+ }
4984
4909
 
4985
- /** @override **/
4986
- get isUniversal() {
4987
- 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);
4988
4918
  }
4919
+ return inf;
4920
+ }
4989
4921
 
4990
- /** @override **/
4991
- offsetName(ts, { format, locale }) {
4992
- 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;
4993
4929
  }
4930
+ }
4994
4931
 
4995
- /** @override **/
4996
- formatOffset(ts, format) {
4997
- 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);
4998
4938
  }
4939
+ return opts;
4940
+ }
4999
4941
 
5000
- /** @override **/
5001
- offset(ts) {
5002
- 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);
5003
4954
  }
4955
+ return data;
4956
+ }
5004
4957
 
5005
- /** @override **/
5006
- equals(otherZone) {
5007
- return otherZone.type === "system";
5008
- }
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:
5009
4962
 
5010
- /** @override **/
5011
- get isValid() {
5012
- return true;
5013
- }
5014
- }
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
5015
4966
 
5016
- const dtfCache = new Map();
5017
- function makeDTF(zoneName) {
5018
- let dtf = dtfCache.get(zoneName);
5019
- if (dtf === undefined) {
5020
- dtf = new Intl.DateTimeFormat("en-US", {
5021
- hour12: false,
5022
- timeZone: zoneName,
5023
- year: "numeric",
5024
- month: "2-digit",
5025
- day: "2-digit",
5026
- hour: "2-digit",
5027
- minute: "2-digit",
5028
- second: "2-digit",
5029
- era: "short",
5030
- });
5031
- 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);
5032
4973
  }
5033
- return dtf;
5034
- }
5035
4974
 
5036
- const typeToPos = {
5037
- year: 0,
5038
- month: 1,
5039
- day: 2,
5040
- era: 3,
5041
- hour: 4,
5042
- minute: 5,
5043
- second: 6,
5044
- };
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
+ }
5045
4989
 
5046
- function hackyOffset(dtf, date) {
5047
- const formatted = dtf.format(date).replace(/\u200E/g, ""),
5048
- parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted),
5049
- [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed;
5050
- return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
4990
+ const { numberingSystem, calendar } = options;
4991
+ return [selectedStr, numberingSystem, calendar];
4992
+ }
5051
4993
  }
5052
4994
 
5053
- function partsOffset(dtf, date) {
5054
- const formatted = dtf.formatToParts(date);
5055
- const filled = [];
5056
- for (let i = 0; i < formatted.length; i++) {
5057
- const { type, value } = formatted[i];
5058
- const pos = typeToPos[type];
4995
+ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
4996
+ if (outputCalendar || numberingSystem) {
4997
+ if (!localeStr.includes("-u-")) {
4998
+ localeStr += "-u";
4999
+ }
5059
5000
 
5060
- if (type === "era") {
5061
- filled[pos] = value;
5062
- } else if (!isUndefined(pos)) {
5063
- filled[pos] = parseInt(value, 10);
5001
+ if (outputCalendar) {
5002
+ localeStr += `-ca-${outputCalendar}`;
5064
5003
  }
5065
- }
5066
- return filled;
5067
- }
5068
5004
 
5069
- const ianaZoneCache = new Map();
5070
- /**
5071
- * A zone identified by an IANA identifier, like America/New_York
5072
- * @implements {Zone}
5073
- */
5074
- class IANAZone extends Zone {
5075
- /**
5076
- * @param {string} name - Zone name
5077
- * @return {IANAZone}
5078
- */
5079
- static create(name) {
5080
- let zone = ianaZoneCache.get(name);
5081
- if (zone === undefined) {
5082
- ianaZoneCache.set(name, (zone = new IANAZone(name)));
5005
+ if (numberingSystem) {
5006
+ localeStr += `-nu-${numberingSystem}`;
5083
5007
  }
5084
- return zone;
5085
- }
5086
-
5087
- /**
5088
- * Reset local caches. Should only be necessary in testing scenarios.
5089
- * @return {void}
5090
- */
5091
- static resetCache() {
5092
- ianaZoneCache.clear();
5093
- dtfCache.clear();
5094
- }
5095
-
5096
- /**
5097
- * 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.
5098
- * @param {string} s - The string to check validity on
5099
- * @example IANAZone.isValidSpecifier("America/New_York") //=> true
5100
- * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
5101
- * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
5102
- * @return {boolean}
5103
- */
5104
- static isValidSpecifier(s) {
5105
- return this.isValidZone(s);
5008
+ return localeStr;
5009
+ } else {
5010
+ return localeStr;
5106
5011
  }
5012
+ }
5107
5013
 
5108
- /**
5109
- * Returns whether the provided string identifies a real zone
5110
- * @param {string} zone - The string to check
5111
- * @example IANAZone.isValidZone("America/New_York") //=> true
5112
- * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
5113
- * @example IANAZone.isValidZone("Sport~~blorp") //=> false
5114
- * @return {boolean}
5115
- */
5116
- static isValidZone(zone) {
5117
- if (!zone) {
5118
- return false;
5119
- }
5120
- try {
5121
- new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
5122
- return true;
5123
- } catch (e) {
5124
- return false;
5125
- }
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));
5126
5019
  }
5020
+ return ms;
5021
+ }
5127
5022
 
5128
- constructor(name) {
5129
- super();
5130
- /** @private **/
5131
- this.zoneName = name;
5132
- /** @private **/
5133
- this.valid = IANAZone.isValidZone(name);
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));
5134
5028
  }
5029
+ return ms;
5030
+ }
5135
5031
 
5136
- /**
5137
- * The type of zone. `iana` for all instances of `IANAZone`.
5138
- * @override
5139
- * @type {string}
5140
- */
5141
- get type() {
5142
- return "iana";
5143
- }
5032
+ function listStuff(loc, length, englishFn, intlFn) {
5033
+ const mode = loc.listingMode();
5144
5034
 
5145
- /**
5146
- * The name of this zone (i.e. the IANA zone name).
5147
- * @override
5148
- * @type {string}
5149
- */
5150
- get name() {
5151
- return this.zoneName;
5035
+ if (mode === "error") {
5036
+ return null;
5037
+ } else if (mode === "en") {
5038
+ return englishFn(length);
5039
+ } else {
5040
+ return intlFn(length);
5152
5041
  }
5042
+ }
5153
5043
 
5154
- /**
5155
- * Returns whether the offset is known to be fixed for the whole year:
5156
- * Always returns false for all IANA zones.
5157
- * @override
5158
- * @type {boolean}
5159
- */
5160
- get isUniversal() {
5044
+ function supportsFastNumbers(loc) {
5045
+ if (loc.numberingSystem && loc.numberingSystem !== "latn") {
5161
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
+ );
5162
5054
  }
5055
+ }
5163
5056
 
5164
- /**
5165
- * Returns the offset's common name (such as EST) at the specified timestamp
5166
- * @override
5167
- * @param {number} ts - Epoch milliseconds for which to get the name
5168
- * @param {Object} opts - Options to affect the format
5169
- * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
5170
- * @param {string} opts.locale - What locale to return the offset name in.
5171
- * @return {string}
5172
- */
5173
- offsetName(ts, { format, locale }) {
5174
- return parseZoneInfo(ts, format, locale, this.name);
5175
- }
5176
-
5177
- /**
5178
- * Returns the offset's value as a string
5179
- * @override
5180
- * @param {number} ts - Epoch milliseconds for which to get the offset
5181
- * @param {string} format - What style of offset to return.
5182
- * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
5183
- * @return {string}
5184
- */
5185
- formatOffset(ts, format) {
5186
- return formatOffset(this.offset(ts), format);
5187
- }
5057
+ /**
5058
+ * @private
5059
+ */
5188
5060
 
5189
- /**
5190
- * Return the offset in minutes for this zone at the specified timestamp.
5191
- * @override
5192
- * @param {number} ts - Epoch milliseconds for which to compute the offset
5193
- * @return {number}
5194
- */
5195
- offset(ts) {
5196
- if (!this.valid) return NaN;
5197
- const date = new Date(ts);
5061
+ class PolyNumberFormatter {
5062
+ constructor(intl, forceSimple, opts) {
5063
+ this.padTo = opts.padTo || 0;
5064
+ this.floor = opts.floor || false;
5198
5065
 
5199
- if (isNaN(date)) return NaN;
5066
+ const { padTo, floor, ...otherOpts } = opts;
5200
5067
 
5201
- const dtf = makeDTF(this.name);
5202
- let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts
5203
- ? partsOffset(dtf, date)
5204
- : hackyOffset(dtf, date);
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
+ }
5073
+ }
5205
5074
 
5206
- if (adOrBc === "BC") {
5207
- year = -Math.abs(year) + 1;
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);
5208
5083
  }
5084
+ }
5085
+ }
5209
5086
 
5210
- // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
5211
- const adjustedHour = hour === 24 ? 0 : hour;
5087
+ /**
5088
+ * @private
5089
+ */
5212
5090
 
5213
- const asUTC = objToLocalTS({
5214
- year,
5215
- month,
5216
- day,
5217
- hour: adjustedHour,
5218
- minute,
5219
- second,
5220
- millisecond: 0,
5221
- });
5091
+ class PolyDateFormatter {
5092
+ constructor(dt, intl, opts) {
5093
+ this.opts = opts;
5094
+ this.originalZone = undefined;
5222
5095
 
5223
- let asTS = +date;
5224
- const over = asTS % 1000;
5225
- asTS -= over >= 0 ? over : 1000 + over;
5226
- return (asUTC - asTS) / (60 * 1000);
5227
- }
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;
5130
+ }
5228
5131
 
5229
- /**
5230
- * Return whether this Zone is equal to another zone
5231
- * @override
5232
- * @param {Zone} otherZone - the zone to compare
5233
- * @return {boolean}
5234
- */
5235
- equals(otherZone) {
5236
- 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);
5237
5135
  }
5238
5136
 
5239
- /**
5240
- * Return whether this Zone is valid.
5241
- * @override
5242
- * @type {boolean}
5243
- */
5244
- get isValid() {
5245
- 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());
5246
5146
  }
5247
- }
5248
-
5249
- // todo - remap caching
5250
5147
 
5251
- let intlLFCache = {};
5252
- function getCachedLF(locString, opts = {}) {
5253
- const key = JSON.stringify([locString, opts]);
5254
- let dtf = intlLFCache[key];
5255
- if (!dtf) {
5256
- dtf = new Intl.ListFormat(locString, opts);
5257
- intlLFCache[key] = dtf;
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;
5258
5167
  }
5259
- return dtf;
5260
- }
5261
5168
 
5262
- const intlDTCache = new Map();
5263
- function getCachedDTF(locString, opts = {}) {
5264
- const key = JSON.stringify([locString, opts]);
5265
- let dtf = intlDTCache.get(key);
5266
- if (dtf === undefined) {
5267
- dtf = new Intl.DateTimeFormat(locString, opts);
5268
- intlDTCache.set(key, dtf);
5169
+ resolvedOptions() {
5170
+ return this.dtf.resolvedOptions();
5269
5171
  }
5270
- return dtf;
5271
5172
  }
5272
5173
 
5273
- const intlNumCache = new Map();
5274
- function getCachedINF(locString, opts = {}) {
5275
- const key = JSON.stringify([locString, opts]);
5276
- let inf = intlNumCache.get(key);
5277
- if (inf === undefined) {
5278
- inf = new Intl.NumberFormat(locString, opts);
5279
- intlNumCache.set(key, inf);
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
+ }
5280
5183
  }
5281
- return inf;
5282
- }
5283
5184
 
5284
- const intlRelCache = new Map();
5285
- function getCachedRTF(locString, opts = {}) {
5286
- const { base, ...cacheKeyOpts } = opts; // exclude `base` from the options
5287
- const key = JSON.stringify([locString, cacheKeyOpts]);
5288
- let inf = intlRelCache.get(key);
5289
- if (inf === undefined) {
5290
- inf = new Intl.RelativeTimeFormat(locString, opts);
5291
- intlRelCache.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
+ }
5292
5191
  }
5293
- return inf;
5294
- }
5295
5192
 
5296
- let sysLocaleCache = null;
5297
- function systemLocale() {
5298
- if (sysLocaleCache) {
5299
- return sysLocaleCache;
5300
- } else {
5301
- sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
5302
- return sysLocaleCache;
5193
+ formatToParts(count, unit) {
5194
+ if (this.rtf) {
5195
+ return this.rtf.formatToParts(count, unit);
5196
+ } else {
5197
+ return [];
5198
+ }
5303
5199
  }
5304
5200
  }
5305
5201
 
5306
- const intlResolvedOptionsCache = new Map();
5307
- function getCachedIntResolvedOptions(locString) {
5308
- let opts = intlResolvedOptionsCache.get(locString);
5309
- if (opts === undefined) {
5310
- opts = new Intl.DateTimeFormat(locString).resolvedOptions();
5311
- intlResolvedOptionsCache.set(locString, opts);
5312
- }
5313
- return opts;
5314
- }
5202
+ const fallbackWeekSettings = {
5203
+ firstDay: 1,
5204
+ minimalDays: 4,
5205
+ weekend: [6, 7],
5206
+ };
5315
5207
 
5316
- const weekInfoCache = new Map();
5317
- function getCachedWeekInfo(locString) {
5318
- let data = weekInfoCache.get(locString);
5319
- if (!data) {
5320
- const locale = new Intl.Locale(locString);
5321
- // browsers currently implement this as a property, but spec says it should be a getter function
5322
- data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
5323
- // minimalDays was removed from WeekInfo: https://github.com/tc39/proposal-intl-locale-info/issues/86
5324
- if (!("minimalDays" in data)) {
5325
- data = { ...fallbackWeekSettings, ...data };
5326
- }
5327
- weekInfoCache.set(locString, data);
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
+ );
5328
5220
  }
5329
- return data;
5330
- }
5331
5221
 
5332
- function parseLocaleString(localeStr) {
5333
- // I really want to avoid writing a BCP 47 parser
5334
- // see, e.g. https://github.com/wooorm/bcp-47
5335
- // Instead, we'll do this:
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);
5230
+ }
5336
5231
 
5337
- // a) if the string has no -u extensions, just leave it alone
5338
- // b) if it does, use Intl to resolve everything
5339
- // c) if Intl fails, try again without the -u
5232
+ static resetCache() {
5233
+ sysLocaleCache = null;
5234
+ intlDTCache.clear();
5235
+ intlNumCache.clear();
5236
+ intlRelCache.clear();
5237
+ intlResolvedOptionsCache.clear();
5238
+ weekInfoCache.clear();
5239
+ }
5340
5240
 
5341
- // private subtags and unicode subtags have ordering requirements,
5342
- // and we're not properly parsing this, so just strip out the
5343
- // private ones if they exist.
5344
- const xIndex = localeStr.indexOf("-x-");
5345
- if (xIndex !== -1) {
5346
- localeStr = localeStr.substring(0, xIndex);
5241
+ static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
5242
+ return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
5347
5243
  }
5348
5244
 
5349
- const uIndex = localeStr.indexOf("-u-");
5350
- if (uIndex === -1) {
5351
- return [localeStr];
5352
- } else {
5353
- let options;
5354
- let selectedStr;
5355
- try {
5356
- options = getCachedDTF(localeStr).resolvedOptions();
5357
- selectedStr = localeStr;
5358
- } catch (e) {
5359
- const smaller = localeStr.substring(0, uIndex);
5360
- options = getCachedDTF(smaller).resolvedOptions();
5361
- selectedStr = smaller;
5362
- }
5245
+ constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
5246
+ const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
5363
5247
 
5364
- const { numberingSystem, calendar } = options;
5365
- return [selectedStr, numberingSystem, calendar];
5366
- }
5367
- }
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);
5368
5253
 
5369
- function intlConfigString(localeStr, numberingSystem, outputCalendar) {
5370
- if (outputCalendar || numberingSystem) {
5371
- if (!localeStr.includes("-u-")) {
5372
- localeStr += "-u";
5373
- }
5254
+ this.weekdaysCache = { format: {}, standalone: {} };
5255
+ this.monthsCache = { format: {}, standalone: {} };
5256
+ this.meridiemCache = null;
5257
+ this.eraCache = {};
5374
5258
 
5375
- if (outputCalendar) {
5376
- localeStr += `-ca-${outputCalendar}`;
5377
- }
5259
+ this.specifiedLocale = specifiedLocale;
5260
+ this.fastNumbersCached = null;
5261
+ }
5378
5262
 
5379
- if (numberingSystem) {
5380
- localeStr += `-nu-${numberingSystem}`;
5263
+ get fastNumbers() {
5264
+ if (this.fastNumbersCached == null) {
5265
+ this.fastNumbersCached = supportsFastNumbers(this);
5381
5266
  }
5382
- return localeStr;
5383
- } else {
5384
- return localeStr;
5267
+
5268
+ return this.fastNumbersCached;
5385
5269
  }
5386
- }
5387
5270
 
5388
- function mapMonths(f) {
5389
- const ms = [];
5390
- for (let i = 1; i <= 12; i++) {
5391
- const dt = DateTime.utc(2009, i, 1);
5392
- 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";
5393
5277
  }
5394
- return ms;
5395
- }
5396
5278
 
5397
- function mapWeekdays(f) {
5398
- const ms = [];
5399
- for (let i = 1; i <= 7; i++) {
5400
- const dt = DateTime.utc(2016, 11, 13 + i);
5401
- 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
+ }
5402
5291
  }
5403
- return ms;
5404
- }
5405
5292
 
5406
- function listStuff(loc, length, englishFn, intlFn) {
5407
- const mode = loc.listingMode();
5293
+ redefaultToEN(alts = {}) {
5294
+ return this.clone({ ...alts, defaultToEN: true });
5295
+ }
5408
5296
 
5409
- if (mode === "error") {
5410
- return null;
5411
- } else if (mode === "en") {
5412
- return englishFn(length);
5413
- } else {
5414
- return intlFn(length);
5415
- }
5416
- }
5417
-
5418
- function supportsFastNumbers(loc) {
5419
- if (loc.numberingSystem && loc.numberingSystem !== "latn") {
5420
- return false;
5421
- } else {
5422
- return (
5423
- loc.numberingSystem === "latn" ||
5424
- !loc.locale ||
5425
- loc.locale.startsWith("en") ||
5426
- getCachedIntResolvedOptions(loc.locale).numberingSystem === "latn"
5427
- );
5428
- }
5429
- }
5430
-
5431
- /**
5432
- * @private
5433
- */
5434
-
5435
- class PolyNumberFormatter {
5436
- constructor(intl, forceSimple, opts) {
5437
- this.padTo = opts.padTo || 0;
5438
- this.floor = opts.floor || false;
5439
-
5440
- const { padTo, floor, ...otherOpts } = opts;
5441
-
5442
- if (!forceSimple || Object.keys(otherOpts).length > 0) {
5443
- const intlOpts = { useGrouping: false, ...opts };
5444
- if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
5445
- this.inf = getCachedINF(intl, intlOpts);
5446
- }
5447
- }
5448
-
5449
- format(i) {
5450
- if (this.inf) {
5451
- const fixed = this.floor ? Math.floor(i) : i;
5452
- return this.inf.format(fixed);
5453
- } else {
5454
- // to match the browser's numberformatter defaults
5455
- const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
5456
- return padStart(fixed, this.padTo);
5457
- }
5458
- }
5459
- }
5460
-
5461
- /**
5462
- * @private
5463
- */
5464
-
5465
- class PolyDateFormatter {
5466
- constructor(dt, intl, opts) {
5467
- this.opts = opts;
5468
- this.originalZone = undefined;
5469
-
5470
- let z = undefined;
5471
- if (this.opts.timeZone) {
5472
- // Don't apply any workarounds if a timeZone is explicitly provided in opts
5473
- this.dt = dt;
5474
- } else if (dt.zone.type === "fixed") {
5475
- // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
5476
- // That is why fixed-offset TZ is set to that unless it is:
5477
- // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
5478
- // 2. Unsupported by the browser:
5479
- // - some do not support Etc/
5480
- // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
5481
- const gmtOffset = -1 * (dt.offset / 60);
5482
- const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
5483
- if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
5484
- z = offsetZ;
5485
- this.dt = dt;
5486
- } else {
5487
- // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
5488
- // we manually apply the offset and substitute the zone as needed.
5489
- z = "UTC";
5490
- this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
5491
- this.originalZone = dt.zone;
5492
- }
5493
- } else if (dt.zone.type === "system") {
5494
- this.dt = dt;
5495
- } else if (dt.zone.type === "iana") {
5496
- this.dt = dt;
5497
- z = dt.zone.name;
5498
- } else {
5499
- // Custom zones can have any offset / offsetName so we just manually
5500
- // apply the offset and substitute the zone as needed.
5501
- z = "UTC";
5502
- this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
5503
- this.originalZone = dt.zone;
5504
- }
5505
-
5506
- const intlOpts = { ...this.opts };
5507
- intlOpts.timeZone = intlOpts.timeZone || z;
5508
- this.dtf = getCachedDTF(intl, intlOpts);
5509
- }
5510
-
5511
- format() {
5512
- if (this.originalZone) {
5513
- // If we have to substitute in the actual zone name, we have to use
5514
- // formatToParts so that the timezone can be replaced.
5515
- return this.formatToParts()
5516
- .map(({ value }) => value)
5517
- .join("");
5518
- }
5519
- return this.dtf.format(this.dt.toJSDate());
5520
- }
5521
-
5522
- formatToParts() {
5523
- const parts = this.dtf.formatToParts(this.dt.toJSDate());
5524
- if (this.originalZone) {
5525
- return parts.map((part) => {
5526
- if (part.type === "timeZoneName") {
5527
- const offsetName = this.originalZone.offsetName(this.dt.ts, {
5528
- locale: this.dt.locale,
5529
- format: this.opts.timeZoneName,
5530
- });
5531
- return {
5532
- ...part,
5533
- value: offsetName,
5534
- };
5535
- } else {
5536
- return part;
5537
- }
5538
- });
5539
- }
5540
- return parts;
5541
- }
5542
-
5543
- resolvedOptions() {
5544
- return this.dtf.resolvedOptions();
5545
- }
5546
- }
5547
-
5548
- /**
5549
- * @private
5550
- */
5551
- class PolyRelFormatter {
5552
- constructor(intl, isEnglish, opts) {
5553
- this.opts = { style: "long", ...opts };
5554
- if (!isEnglish && hasRelative()) {
5555
- this.rtf = getCachedRTF(intl, opts);
5556
- }
5557
- }
5558
-
5559
- format(count, unit) {
5560
- if (this.rtf) {
5561
- return this.rtf.format(count, unit);
5562
- } else {
5563
- return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
5564
- }
5565
- }
5566
-
5567
- formatToParts(count, unit) {
5568
- if (this.rtf) {
5569
- return this.rtf.formatToParts(count, unit);
5570
- } else {
5571
- return [];
5572
- }
5573
- }
5574
- }
5575
-
5576
- const fallbackWeekSettings = {
5577
- firstDay: 1,
5578
- minimalDays: 4,
5579
- weekend: [6, 7],
5580
- };
5581
-
5582
- /**
5583
- * @private
5584
- */
5585
- class Locale {
5586
- static fromOpts(opts) {
5587
- return Locale.create(
5588
- opts.locale,
5589
- opts.numberingSystem,
5590
- opts.outputCalendar,
5591
- opts.weekSettings,
5592
- opts.defaultToEN
5593
- );
5594
- }
5595
-
5596
- static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
5597
- const specifiedLocale = locale || Settings.defaultLocale;
5598
- // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
5599
- const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
5600
- const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
5601
- const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
5602
- const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
5603
- return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
5604
- }
5605
-
5606
- static resetCache() {
5607
- sysLocaleCache = null;
5608
- intlDTCache.clear();
5609
- intlNumCache.clear();
5610
- intlRelCache.clear();
5611
- intlResolvedOptionsCache.clear();
5612
- weekInfoCache.clear();
5613
- }
5614
-
5615
- static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
5616
- return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
5617
- }
5618
-
5619
- constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
5620
- const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
5621
-
5622
- this.locale = parsedLocale;
5623
- this.numberingSystem = numbering || parsedNumberingSystem || null;
5624
- this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
5625
- this.weekSettings = weekSettings;
5626
- this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
5627
-
5628
- this.weekdaysCache = { format: {}, standalone: {} };
5629
- this.monthsCache = { format: {}, standalone: {} };
5630
- this.meridiemCache = null;
5631
- this.eraCache = {};
5632
-
5633
- this.specifiedLocale = specifiedLocale;
5634
- this.fastNumbersCached = null;
5635
- }
5636
-
5637
- get fastNumbers() {
5638
- if (this.fastNumbersCached == null) {
5639
- this.fastNumbersCached = supportsFastNumbers(this);
5640
- }
5641
-
5642
- return this.fastNumbersCached;
5643
- }
5644
-
5645
- listingMode() {
5646
- const isActuallyEn = this.isEnglish();
5647
- const hasNoWeirdness =
5648
- (this.numberingSystem === null || this.numberingSystem === "latn") &&
5649
- (this.outputCalendar === null || this.outputCalendar === "gregory");
5650
- return isActuallyEn && hasNoWeirdness ? "en" : "intl";
5651
- }
5652
-
5653
- clone(alts) {
5654
- if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
5655
- return this;
5656
- } else {
5657
- return Locale.create(
5658
- alts.locale || this.specifiedLocale,
5659
- alts.numberingSystem || this.numberingSystem,
5660
- alts.outputCalendar || this.outputCalendar,
5661
- validateWeekSettings(alts.weekSettings) || this.weekSettings,
5662
- alts.defaultToEN || false
5663
- );
5664
- }
5665
- }
5666
-
5667
- redefaultToEN(alts = {}) {
5668
- return this.clone({ ...alts, defaultToEN: true });
5669
- }
5670
-
5671
- redefaultToSystem(alts = {}) {
5672
- return this.clone({ ...alts, defaultToEN: false });
5297
+ redefaultToSystem(alts = {}) {
5298
+ return this.clone({ ...alts, defaultToEN: false });
5673
5299
  }
5674
5300
 
5675
5301
  months(length, format = false) {
@@ -12570,182 +12196,566 @@ class DateTime {
12570
12196
  return DATE_MED;
12571
12197
  }
12572
12198
 
12573
- /**
12574
- * {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983'
12575
- * @type {Object}
12576
- */
12577
- static get DATE_MED_WITH_WEEKDAY() {
12578
- return DATE_MED_WITH_WEEKDAY;
12579
- }
12199
+ /**
12200
+ * {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983'
12201
+ * @type {Object}
12202
+ */
12203
+ static get DATE_MED_WITH_WEEKDAY() {
12204
+ return DATE_MED_WITH_WEEKDAY;
12205
+ }
12206
+
12207
+ /**
12208
+ * {@link DateTime#toLocaleString} format like 'October 14, 1983'
12209
+ * @type {Object}
12210
+ */
12211
+ static get DATE_FULL() {
12212
+ return DATE_FULL;
12213
+ }
12214
+
12215
+ /**
12216
+ * {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983'
12217
+ * @type {Object}
12218
+ */
12219
+ static get DATE_HUGE() {
12220
+ return DATE_HUGE;
12221
+ }
12222
+
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;
12580
12635
 
12581
- /**
12582
- * {@link DateTime#toLocaleString} format like 'October 14, 1983'
12583
- * @type {Object}
12584
- */
12585
- static get DATE_FULL() {
12586
- return DATE_FULL;
12587
- }
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
+ };
12588
12645
 
12589
- /**
12590
- * {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983'
12591
- * @type {Object}
12592
- */
12593
- static get DATE_HUGE() {
12594
- return DATE_HUGE;
12595
- }
12646
+ self.setLevel = function (level, persist) {
12647
+ userLevel = normalizeLevel(level);
12648
+ if (persist !== false) { // defaults to true
12649
+ persistLevelIfPossible(userLevel);
12650
+ }
12596
12651
 
12597
- /**
12598
- * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
12599
- * @type {Object}
12600
- */
12601
- static get TIME_SIMPLE() {
12602
- return TIME_SIMPLE;
12603
- }
12652
+ // NOTE: in v2, this should call rebuild(), which updates children.
12653
+ return replaceLoggingMethods.call(self);
12654
+ };
12604
12655
 
12605
- /**
12606
- * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
12607
- * @type {Object}
12608
- */
12609
- static get TIME_WITH_SECONDS() {
12610
- return TIME_WITH_SECONDS;
12611
- }
12656
+ self.setDefaultLevel = function (level) {
12657
+ defaultLevel = normalizeLevel(level);
12658
+ if (!getPersistedLevel()) {
12659
+ self.setLevel(level, false);
12660
+ }
12661
+ };
12612
12662
 
12613
- /**
12614
- * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
12615
- * @type {Object}
12616
- */
12617
- static get TIME_WITH_SHORT_OFFSET() {
12618
- return TIME_WITH_SHORT_OFFSET;
12619
- }
12663
+ self.resetLevel = function () {
12664
+ userLevel = null;
12665
+ clearPersistedLevel();
12666
+ replaceLoggingMethods.call(self);
12667
+ };
12620
12668
 
12621
- /**
12622
- * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12623
- * @type {Object}
12624
- */
12625
- static get TIME_WITH_LONG_OFFSET() {
12626
- return TIME_WITH_LONG_OFFSET;
12627
- }
12669
+ self.enableAll = function(persist) {
12670
+ self.setLevel(self.levels.TRACE, persist);
12671
+ };
12628
12672
 
12629
- /**
12630
- * {@link DateTime#toLocaleString} format like '09:30', always 24-hour.
12631
- * @type {Object}
12632
- */
12633
- static get TIME_24_SIMPLE() {
12634
- return TIME_24_SIMPLE;
12635
- }
12673
+ self.disableAll = function(persist) {
12674
+ self.setLevel(self.levels.SILENT, persist);
12675
+ };
12636
12676
 
12637
- /**
12638
- * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
12639
- * @type {Object}
12640
- */
12641
- static get TIME_24_WITH_SECONDS() {
12642
- return TIME_24_WITH_SECONDS;
12643
- }
12677
+ self.rebuild = function () {
12678
+ if (defaultLogger !== self) {
12679
+ inheritedLevel = normalizeLevel(defaultLogger.getLevel());
12680
+ }
12681
+ replaceLoggingMethods.call(self);
12644
12682
 
12645
- /**
12646
- * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour.
12647
- * @type {Object}
12648
- */
12649
- static get TIME_24_WITH_SHORT_OFFSET() {
12650
- return TIME_24_WITH_SHORT_OFFSET;
12651
- }
12683
+ if (defaultLogger === self) {
12684
+ for (var childName in _loggersByName) {
12685
+ _loggersByName[childName].rebuild();
12686
+ }
12687
+ }
12688
+ };
12652
12689
 
12653
- /**
12654
- * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
12655
- * @type {Object}
12656
- */
12657
- static get TIME_24_WITH_LONG_OFFSET() {
12658
- return TIME_24_WITH_LONG_OFFSET;
12659
- }
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
+ }
12660
12700
 
12661
- /**
12662
- * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
12663
- * @type {Object}
12664
- */
12665
- static get DATETIME_SHORT() {
12666
- return DATETIME_SHORT;
12667
- }
12701
+ /*
12702
+ *
12703
+ * Top-level API
12704
+ *
12705
+ */
12668
12706
 
12669
- /**
12670
- * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
12671
- * @type {Object}
12672
- */
12673
- static get DATETIME_SHORT_WITH_SECONDS() {
12674
- return DATETIME_SHORT_WITH_SECONDS;
12675
- }
12707
+ defaultLogger = new Logger();
12676
12708
 
12677
- /**
12678
- * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
12679
- * @type {Object}
12680
- */
12681
- static get DATETIME_MED() {
12682
- return DATETIME_MED;
12683
- }
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
+ }
12684
12713
 
12685
- /**
12686
- * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
12687
- * @type {Object}
12688
- */
12689
- static get DATETIME_MED_WITH_SECONDS() {
12690
- return DATETIME_MED_WITH_SECONDS;
12691
- }
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
+ };
12692
12723
 
12693
- /**
12694
- * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
12695
- * @type {Object}
12696
- */
12697
- static get DATETIME_MED_WITH_WEEKDAY() {
12698
- return DATETIME_MED_WITH_WEEKDAY;
12699
- }
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
+ }
12700
12731
 
12701
- /**
12702
- * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
12703
- * @type {Object}
12704
- */
12705
- static get DATETIME_FULL() {
12706
- return DATETIME_FULL;
12707
- }
12732
+ return defaultLogger;
12733
+ };
12708
12734
 
12709
- /**
12710
- * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
12711
- * @type {Object}
12712
- */
12713
- static get DATETIME_FULL_WITH_SECONDS() {
12714
- return DATETIME_FULL_WITH_SECONDS;
12715
- }
12735
+ defaultLogger.getLoggers = function getLoggers() {
12736
+ return _loggersByName;
12737
+ };
12716
12738
 
12717
- /**
12718
- * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12719
- * @type {Object}
12720
- */
12721
- static get DATETIME_HUGE() {
12722
- return DATETIME_HUGE;
12723
- }
12739
+ // ES6 default export, for compatibility
12740
+ defaultLogger['default'] = defaultLogger;
12724
12741
 
12725
- /**
12726
- * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
12727
- * @type {Object}
12728
- */
12729
- static get DATETIME_HUGE_WITH_SECONDS() {
12730
- return DATETIME_HUGE_WITH_SECONDS;
12731
- }
12742
+ return defaultLogger;
12743
+ }));
12744
+ } (loglevel$1));
12745
+ return loglevel$1.exports;
12732
12746
  }
12733
12747
 
12748
+ var loglevelExports = requireLoglevel();
12749
+ var log = /*@__PURE__*/getDefaultExportFromCjs(loglevelExports);
12750
+
12751
+ const parserLog = log.getLogger('minotor:gtfs');
12752
+ parserLog.setLevel('warn', false);
12734
12753
  /**
12735
- * @private
12754
+ * Set logging for all GTFS parser instances in this module.
12755
+ * Defaults to warn.
12736
12756
  */
12737
- function friendlyDateTime(dateTimeish) {
12738
- if (DateTime.isDateTime(dateTimeish)) {
12739
- return dateTimeish;
12740
- } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
12741
- return DateTime.fromJSDate(dateTimeish);
12742
- } else if (dateTimeish && typeof dateTimeish === "object") {
12743
- return DateTime.fromObject(dateTimeish);
12744
- } else {
12745
- throw new InvalidArgumentError(
12746
- `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`
12747
- );
12748
- }
12757
+ function setParserLogLevel(level) {
12758
+ parserLog.setLevel(level, false);
12749
12759
  }
12750
12760
 
12751
12761
  /**
@@ -20650,7 +20660,7 @@ const parseFrequencies = (stream, activeTripIds) => __awaiter(void 0, void 0, vo
20650
20660
  continue;
20651
20661
  }
20652
20662
  if (line.exact_times !== '1') {
20653
- 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.`);
20654
20664
  }
20655
20665
  const window = {
20656
20666
  startTime: toTime(line.start_time),
@@ -20724,7 +20734,7 @@ const parseRoutes = (routesStream_1, ...args_1) => __awaiter(void 0, [routesStre
20724
20734
  const line = rawLine;
20725
20735
  const routeType = profile.routeTypeParser(line.route_type);
20726
20736
  if (routeType === undefined) {
20727
- 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}.`);
20728
20738
  continue;
20729
20739
  }
20730
20740
  routes.set(line.route_id, {
@@ -20754,7 +20764,7 @@ const indexRoutes = (gtfsRoutesMap, serviceRoutesMap) => {
20754
20764
  for (const [gtfsRouteId, serviceRouteId] of serviceRoutesMap) {
20755
20765
  const route = gtfsRoutesMap.get(gtfsRouteId);
20756
20766
  if (route === undefined) {
20757
- log.warn(`Route ${gtfsRouteId} not found.`);
20767
+ parserLog.warn(`Route ${gtfsRouteId} not found.`);
20758
20768
  continue;
20759
20769
  }
20760
20770
  serviceRoutes[serviceRouteId] = {
@@ -20901,7 +20911,7 @@ const parseStops = (stopsStream) => __awaiter(void 0, void 0, void 0, function*
20901
20911
  if (stop.parentSourceId) {
20902
20912
  const parentStop = parsedStops.get(stop.parentSourceId);
20903
20913
  if (!parentStop) {
20904
- log.warn(`Cannot find parent stop ${stop.parentSourceId} of ${sourceStopId}`);
20914
+ parserLog.warn(`Cannot find parent stop ${stop.parentSourceId} of ${sourceStopId}`);
20905
20915
  continue;
20906
20916
  }
20907
20917
  stop.parent = parentStop.id;
@@ -20934,7 +20944,7 @@ const processInSeatTransfer = (transferEntry, fromStop, toStop, tripContinuation
20934
20944
  transferEntry.from_trip_id === '' ||
20935
20945
  transferEntry.to_trip_id === undefined ||
20936
20946
  transferEntry.to_trip_id === '') {
20937
- 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.`);
20938
20948
  return;
20939
20949
  }
20940
20950
  const tripContinuationEntry = {
@@ -20970,7 +20980,7 @@ const processGuaranteedTripTransfer = (transferEntry, fromStop, toStop, guarante
20970
20980
  const processGuaranteedStopTransfer = (transferEntry, fromStop, toStop, transfers) => {
20971
20981
  // Reject transfers that specify route IDs - these are not supported for stop-to-stop transfers
20972
20982
  if (transferEntry.from_route_id || transferEntry.to_route_id) {
20973
- 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}.`);
20974
20984
  return;
20975
20985
  }
20976
20986
  const transfer = Object.assign({ destination: toStop, type: TransferTypes.GUARANTEED }, (transferEntry.min_transfer_time !== undefined && {
@@ -20985,11 +20995,11 @@ const processGuaranteedStopTransfer = (transferEntry, fromStop, toStop, transfer
20985
20995
  */
20986
20996
  const processStopToStopTransfer = (transferEntry, fromStop, toStop, transfers) => {
20987
20997
  if (transferEntry.from_trip_id || transferEntry.to_trip_id) {
20988
- 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}.`);
20989
20999
  return;
20990
21000
  }
20991
21001
  if (transferEntry.from_route_id || transferEntry.to_route_id) {
20992
- 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}.`);
20993
21003
  return;
20994
21004
  }
20995
21005
  if (transferEntry.transfer_type === 2 &&
@@ -21037,13 +21047,13 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
21037
21047
  continue;
21038
21048
  }
21039
21049
  if (!transferEntry.from_stop_id || !transferEntry.to_stop_id) {
21040
- log.warn(`Missing transfer origin or destination stop.`);
21050
+ parserLog.warn(`Missing transfer origin or destination stop.`);
21041
21051
  continue;
21042
21052
  }
21043
21053
  const fromStop = stopsMap.get(transferEntry.from_stop_id);
21044
21054
  const toStop = stopsMap.get(transferEntry.to_stop_id);
21045
21055
  if (!fromStop || !toStop) {
21046
- 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}`);
21047
21057
  continue;
21048
21058
  }
21049
21059
  switch (transferEntry.transfer_type) {
@@ -21068,7 +21078,7 @@ const parseTransfers = (transfersStream, stopsMap, activeServiceIds) => __awaite
21068
21078
  transferEntry.to_trip_id ||
21069
21079
  transferEntry.from_route_id ||
21070
21080
  transferEntry.to_route_id) {
21071
- 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}.`);
21072
21082
  break;
21073
21083
  }
21074
21084
  const forbiddenDestinations = (_d = forbiddenTransfers.get(fromStop.id)) !== null && _d !== void 0 ? _d : new Set();
@@ -21469,7 +21479,7 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21469
21479
  }
21470
21480
  const firstDeparture = departureTimes[0];
21471
21481
  if (firstDeparture === undefined) {
21472
- log.warn(`Empty trip ${currentTripId}`);
21482
+ parserLog.warn(`Empty trip ${currentTripId}`);
21473
21483
  stops = [];
21474
21484
  arrivalTimes = [];
21475
21485
  departureTimes = [];
@@ -21552,11 +21562,11 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21552
21562
  const rawLine = _c;
21553
21563
  const line = rawLine;
21554
21564
  if (line.trip_id === currentTripId && line.stop_sequence <= previousSeq) {
21555
- 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}.`);
21556
21566
  continue;
21557
21567
  }
21558
21568
  if (!line.arrival_time && !line.departure_time) {
21559
- 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}.`);
21560
21570
  continue;
21561
21571
  }
21562
21572
  if (line.pickup_type === '1' && line.drop_off_type === '1') {
@@ -21571,14 +21581,14 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
21571
21581
  currentTripId = line.trip_id;
21572
21582
  const stopData = stopsMap.get(line.stop_id);
21573
21583
  if (!stopData) {
21574
- log.warn(`Unknown stop ID: ${line.stop_id}`);
21584
+ parserLog.warn(`Unknown stop ID: ${line.stop_id}`);
21575
21585
  continue;
21576
21586
  }
21577
21587
  stops.push(stopData.id);
21578
21588
  const departure = (_d = line.departure_time) !== null && _d !== void 0 ? _d : line.arrival_time;
21579
21589
  const arrival = (_e = line.arrival_time) !== null && _e !== void 0 ? _e : line.departure_time;
21580
21590
  if (!arrival || !departure) {
21581
- 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}`);
21582
21592
  continue;
21583
21593
  }
21584
21594
  arrivalTimes.push(toTime(arrival));
@@ -21651,52 +21661,51 @@ class GtfsParser {
21651
21661
  */
21652
21662
  parseTimetable(date) {
21653
21663
  return __awaiter(this, void 0, void 0, function* () {
21654
- log.setLevel('INFO');
21655
21664
  const zip = new StreamZip.async({ file: this.path });
21656
21665
  const entries = yield zip.entries();
21657
21666
  const datetime = DateTime.fromJSDate(date);
21658
21667
  const activeServiceIds = new Set();
21659
21668
  const activeStopIds = new Set();
21660
- log.info(`Parsing ${STOPS_FILE}`);
21669
+ parserLog.info(`Parsing ${STOPS_FILE}`);
21661
21670
  const stopsStart = performance.now();
21662
21671
  const stopsStream = yield zip.stream(STOPS_FILE);
21663
21672
  const parsedStops = yield parseStops(stopsStream);
21664
21673
  const stopsEnd = performance.now();
21665
- log.info(`${parsedStops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21674
+ parserLog.info(`${parsedStops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21666
21675
  if (entries[CALENDAR_FILE]) {
21667
- log.info(`Parsing ${CALENDAR_FILE}`);
21676
+ parserLog.info(`Parsing ${CALENDAR_FILE}`);
21668
21677
  const calendarStart = performance.now();
21669
21678
  const calendarStream = yield zip.stream(CALENDAR_FILE);
21670
21679
  yield parseCalendar(calendarStream, activeServiceIds, datetime);
21671
21680
  const calendarEnd = performance.now();
21672
- log.info(`${activeServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
21681
+ parserLog.info(`${activeServiceIds.size} valid services. (${(calendarEnd - calendarStart).toFixed(2)}ms)`);
21673
21682
  }
21674
21683
  if (entries[CALENDAR_DATES_FILE]) {
21675
- log.info(`Parsing ${CALENDAR_DATES_FILE}`);
21684
+ parserLog.info(`Parsing ${CALENDAR_DATES_FILE}`);
21676
21685
  const calendarDatesStart = performance.now();
21677
21686
  const calendarDatesStream = yield zip.stream(CALENDAR_DATES_FILE);
21678
21687
  yield parseCalendarDates(calendarDatesStream, activeServiceIds, datetime);
21679
21688
  const calendarDatesEnd = performance.now();
21680
- log.info(`${activeServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
21689
+ parserLog.info(`${activeServiceIds.size} valid services. (${(calendarDatesEnd - calendarDatesStart).toFixed(2)}ms)`);
21681
21690
  }
21682
- log.info(`Parsing ${ROUTES_FILE}`);
21691
+ parserLog.info(`Parsing ${ROUTES_FILE}`);
21683
21692
  const routesStart = performance.now();
21684
21693
  const routesStream = yield zip.stream(ROUTES_FILE);
21685
21694
  const validGtfsRoutes = yield parseRoutes(routesStream, this.profile);
21686
21695
  const routesEnd = performance.now();
21687
- log.info(`${validGtfsRoutes.size} valid GTFS routes. (${(routesEnd - routesStart).toFixed(2)}ms)`);
21688
- log.info(`Parsing ${TRIPS_FILE}`);
21696
+ parserLog.info(`${validGtfsRoutes.size} valid GTFS routes. (${(routesEnd - routesStart).toFixed(2)}ms)`);
21697
+ parserLog.info(`Parsing ${TRIPS_FILE}`);
21689
21698
  const tripsStart = performance.now();
21690
21699
  const tripsStream = yield zip.stream(TRIPS_FILE);
21691
21700
  const trips = yield parseTrips(tripsStream, activeServiceIds, validGtfsRoutes);
21692
21701
  const tripsEnd = performance.now();
21693
- log.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21702
+ parserLog.info(`${trips.size} valid trips. (${(tripsEnd - tripsStart).toFixed(2)}ms)`);
21694
21703
  let transfers = new Map();
21695
21704
  let forbiddenTransfers = new Map();
21696
21705
  let tripContinuationsList = [];
21697
21706
  let guaranteedTripTransfersList = [];
21698
21707
  if (entries[TRANSFERS_FILE]) {
21699
- log.info(`Parsing ${TRANSFERS_FILE}`);
21708
+ parserLog.info(`Parsing ${TRANSFERS_FILE}`);
21700
21709
  const transfersStart = performance.now();
21701
21710
  const transfersStream = yield zip.stream(TRANSFERS_FILE);
21702
21711
  const { transfers: parsedTransfers, forbiddenTransfers: parsedForbiddenTransfers, tripContinuations: parsedTripContinuations, guaranteedTripTransfers: parsedGuaranteedTripTransfers, } = yield parseTransfers(transfersStream, parsedStops, activeServiceIds);
@@ -21705,32 +21714,32 @@ class GtfsParser {
21705
21714
  tripContinuationsList = parsedTripContinuations;
21706
21715
  guaranteedTripTransfersList = parsedGuaranteedTripTransfers;
21707
21716
  const transfersEnd = performance.now();
21708
- 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)`);
21709
21718
  }
21710
21719
  let frequenciesMap;
21711
21720
  if (entries[FREQUENCIES_FILE]) {
21712
- log.info(`Parsing ${FREQUENCIES_FILE}`);
21721
+ parserLog.info(`Parsing ${FREQUENCIES_FILE}`);
21713
21722
  const frequenciesStart = performance.now();
21714
21723
  const frequenciesStream = yield zip.stream(FREQUENCIES_FILE);
21715
21724
  frequenciesMap = yield parseFrequencies(frequenciesStream, new Set(trips.keys()));
21716
21725
  const frequenciesEnd = performance.now();
21717
- 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)`);
21718
21727
  }
21719
- log.info(`Parsing ${STOP_TIMES_FILE}`);
21728
+ parserLog.info(`Parsing ${STOP_TIMES_FILE}`);
21720
21729
  const stopTimesStart = performance.now();
21721
21730
  const stopTimesStream = yield zip.stream(STOP_TIMES_FILE);
21722
21731
  const { routes, serviceRoutesMap, tripsMapping } = yield parseStopTimes(stopTimesStream, parsedStops, trips, activeStopIds, frequenciesMap);
21723
21732
  const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
21724
21733
  const stopTimesEnd = performance.now();
21725
- 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)`);
21726
21735
  if (this.profile.deriveSiblingTransfers !== false) {
21727
21736
  const siblingTransfersStart = performance.now();
21728
21737
  const siblingTransfersAdded = addMissingSiblingTransfers(parsedStops, activeStopIds, transfers, forbiddenTransfers);
21729
21738
  const siblingTransfersEnd = performance.now();
21730
- log.info(`${siblingTransfersAdded} sibling transfers added. (${(siblingTransfersEnd - siblingTransfersStart).toFixed(2)}ms)`);
21739
+ parserLog.info(`${siblingTransfersAdded} sibling transfers added. (${(siblingTransfersEnd - siblingTransfersStart).toFixed(2)}ms)`);
21731
21740
  }
21732
21741
  if (this.transferGenerator) {
21733
- log.info('Generating virtual transfers');
21742
+ parserLog.info('Generating virtual transfers');
21734
21743
  const virtualTransfersStart = performance.now();
21735
21744
  // Only route-served stops with coordinates are worth connecting: a
21736
21745
  // transfer to a stop no route calls at is a dead end for the router.
@@ -21741,28 +21750,28 @@ class GtfsParser {
21741
21750
  const generatedTransfers = yield this.transferGenerator.generate(originStops, stopsIndex);
21742
21751
  const addedTransfers = addGeneratedTransfers(generatedTransfers, activeStopIds, transfers, forbiddenTransfers);
21743
21752
  const virtualTransfersEnd = performance.now();
21744
- log.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21753
+ parserLog.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
21745
21754
  }
21746
- log.info('Building stops adjacency structure');
21755
+ parserLog.info('Building stops adjacency structure');
21747
21756
  const stopsAdjacencyStart = performance.now();
21748
21757
  const stopsAdjacency = buildStopsAdjacencyStructure(serviceRoutes, routes, transfers, parsedStops.size, activeStopIds);
21749
21758
  const stopsAdjacencyEnd = performance.now();
21750
- 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)`);
21751
21760
  yield zip.close();
21752
21761
  // temporary timetable for building continuations
21753
21762
  const timetable = new Timetable(stopsAdjacency, routes, serviceRoutes);
21754
- log.info('Building in-seat trip continuations');
21763
+ parserLog.info('Building in-seat trip continuations');
21755
21764
  const tripContinuationsStart = performance.now();
21756
21765
  const tripContinuations = buildTripTransfers(tripsMapping, tripContinuationsList, timetable, activeStopIds);
21757
21766
  const tripContinuationsEnd = performance.now();
21758
- log.info(`${tripContinuations.size} in-seat trip continuations origins created. (${(tripContinuationsEnd - tripContinuationsStart).toFixed(2)}ms)`);
21759
- log.info('Parsing complete.');
21760
- 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');
21761
21770
  const guaranteedTripTransfersStart = performance.now();
21762
21771
  const guaranteedTripTransfers = buildTripTransfers(tripsMapping, guaranteedTripTransfersList, timetable, activeStopIds);
21763
21772
  const guaranteedTripTransfersEnd = performance.now();
21764
- log.info(`${guaranteedTripTransfers.size} guaranteed trip transfers origins created. (${(guaranteedTripTransfersEnd - guaranteedTripTransfersStart).toFixed(2)}ms)`);
21765
- log.info('Parsing complete.');
21773
+ parserLog.info(`${guaranteedTripTransfers.size} guaranteed trip transfers origins created. (${(guaranteedTripTransfersEnd - guaranteedTripTransfersStart).toFixed(2)}ms)`);
21774
+ parserLog.info('Parsing complete.');
21766
21775
  return new Timetable(stopsAdjacency, routes, serviceRoutes, tripContinuations, guaranteedTripTransfers);
21767
21776
  });
21768
21777
  }
@@ -21775,12 +21784,12 @@ class GtfsParser {
21775
21784
  parseStops() {
21776
21785
  return __awaiter(this, void 0, void 0, function* () {
21777
21786
  const zip = new StreamZip.async({ file: this.path });
21778
- log.info(`Parsing ${STOPS_FILE}`);
21787
+ parserLog.info(`Parsing ${STOPS_FILE}`);
21779
21788
  const stopsStart = performance.now();
21780
21789
  const stopsStream = yield zip.stream(STOPS_FILE);
21781
21790
  const stops = yield parseStops(stopsStream);
21782
21791
  const stopsEnd = performance.now();
21783
- log.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21792
+ parserLog.info(`${stops.size} parsed stops. (${(stopsEnd - stopsStart).toFixed(2)}ms)`);
21784
21793
  yield zip.close();
21785
21794
  return new StopsIndex(Array.from(stops.values()));
21786
21795
  });
@@ -24973,12 +24982,7 @@ program
24973
24982
  .option('--virtual-transfers-radius <meters>', 'Generate virtual walking transfers between stops within this radius (in meters). Disabled when omitted.')
24974
24983
  .option('-v, --verbose', 'Verbose mode', false)
24975
24984
  .action((gtfsPath, options) => __awaiter(void 0, void 0, void 0, function* () {
24976
- if (options.verbose) {
24977
- log.setDefaultLevel(log.levels.INFO);
24978
- }
24979
- else {
24980
- log.setDefaultLevel(log.levels.ERROR);
24981
- }
24985
+ setParserLogLevel(options.verbose ? 'info' : 'error');
24982
24986
  const radiusMeters = options.virtualTransfersRadius !== undefined
24983
24987
  ? parseInt(options.virtualTransfersRadius, 10)
24984
24988
  : undefined;
@@ -25001,12 +25005,7 @@ program
25001
25005
  .option('-p, --profileName <name>', 'Profile name for GTFS config', 'CH')
25002
25006
  .option('-v, --verbose', 'Verbose mode', false)
25003
25007
  .action((gtfsPath, options) => __awaiter(void 0, void 0, void 0, function* () {
25004
- if (options.verbose) {
25005
- log.setDefaultLevel(log.levels.INFO);
25006
- }
25007
- else {
25008
- log.setDefaultLevel(log.levels.ERROR);
25009
- }
25008
+ setParserLogLevel(options.verbose ? 'info' : 'error');
25010
25009
  const parser = new GtfsParser(gtfsPath, profiles[options.profileName]);
25011
25010
  const stopsIndex = yield parser.parseStops();
25012
25011
  fs$1.writeFileSync(options.stopsOutputPath, stopsIndex.serialize());