@nmshd/runtime 2.5.5 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -548,11 +548,11 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
548
548
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
549
549
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
550
550
  exports.buildInformation = {
551
- version: "2.5.5",
552
- build: "160",
553
- date: "2023-08-02T15:11:53+00:00",
554
- commit: "abc570f47c30c4f6bba2e25c7e8ce8cd1fe3e34e",
555
- dependencies: {"@js-soft/docdb-querytranslator":"1.1.0","@js-soft/logging-abstractions":"1.0.0","@js-soft/ts-serval":"2.0.9","@js-soft/ts-utils":"^2.3.1","@nmshd/consumption":"3.2.2","@nmshd/content":"2.3.6","@nmshd/crypto":"2.0.4","@nmshd/transport":"2.0.5","ajv":"^8.12.0","ajv-errors":"^3.0.0","ajv-formats":"^2.1.1","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^3.3.0","qrcode":"1.5.3","reflect-metadata":"0.1.13","ts-simple-nameof":"1.3.1","typescript-ioc":"3.2.2"},
551
+ version: "2.6.0",
552
+ build: "161",
553
+ date: "2023-08-14T11:46:35+00:00",
554
+ commit: "3bc0a7d1b8c05d5706f9b4cac0b63d689287a732",
555
+ dependencies: {"@js-soft/docdb-querytranslator":"1.1.0","@js-soft/logging-abstractions":"1.0.0","@js-soft/ts-serval":"2.0.9","@js-soft/ts-utils":"^2.3.1","@nmshd/consumption":"3.2.2","@nmshd/content":"2.3.6","@nmshd/crypto":"2.0.4","@nmshd/transport":"2.0.5","ajv":"^8.12.0","ajv-errors":"^3.0.0","ajv-formats":"^2.1.1","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^3.4.0","qrcode":"1.5.3","reflect-metadata":"0.1.13","ts-simple-nameof":"1.3.1","typescript-ioc":"3.2.2"},
556
556
  libraries: {
557
557
  serval: ts_serval_1.buildInformation,
558
558
  consumption: consumption_1.buildInformation,
@@ -32824,7 +32824,7 @@ let GetDeviceInfoUseCase = exports.GetDeviceInfoUseCase = class GetDeviceInfoUse
32824
32824
  }
32825
32825
  executeInternal() {
32826
32826
  const device = this.deviceController.device;
32827
- return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device));
32827
+ return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device, true));
32828
32828
  }
32829
32829
  };
32830
32830
  exports.GetDeviceInfoUseCase = GetDeviceInfoUseCase = __decorate([
@@ -33578,7 +33578,7 @@ let CreateDeviceUseCase = exports.CreateDeviceUseCase = class CreateDeviceUseCas
33578
33578
  async executeInternal(request) {
33579
33579
  const device = await this.devicesController.sendDevice(request);
33580
33580
  await this.accountController.syncDatawallet();
33581
- return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device));
33581
+ return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device, false));
33582
33582
  }
33583
33583
  };
33584
33584
  exports.CreateDeviceUseCase = CreateDeviceUseCase = __decorate([
@@ -33735,7 +33735,7 @@ exports.DeviceMapper = void 0;
33735
33735
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
33736
33736
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
33737
33737
  class DeviceMapper {
33738
- static toDeviceDTO(device) {
33738
+ static toDeviceDTO(device, isCurrentDevice) {
33739
33739
  return {
33740
33740
  id: device.id.toString(),
33741
33741
  createdAt: device.createdAt.toString(),
@@ -33747,7 +33747,8 @@ class DeviceMapper {
33747
33747
  description: device.description,
33748
33748
  lastLoginAt: device.lastLoginAt?.toString(),
33749
33749
  operatingSystem: device.operatingSystem,
33750
- publicKey: device.publicKey?.toBase64(false)
33750
+ publicKey: device.publicKey?.toBase64(false),
33751
+ isCurrentDevice: isCurrentDevice
33751
33752
  };
33752
33753
  }
33753
33754
  static toDeviceOnboardingInfoDTO(deviceSharedSecret) {
@@ -33834,22 +33835,27 @@ Validator = __decorate([
33834
33835
  __metadata("design:paramtypes", [common_1.SchemaRepository])
33835
33836
  ], Validator);
33836
33837
  let GetDeviceUseCase = exports.GetDeviceUseCase = class GetDeviceUseCase extends common_1.UseCase {
33837
- constructor(devicesController, validator) {
33838
+ constructor(devicesController, deviceController, validator) {
33838
33839
  super(validator);
33839
33840
  this.devicesController = devicesController;
33841
+ this.deviceController = deviceController;
33840
33842
  }
33841
33843
  async executeInternal(request) {
33842
33844
  const device = await this.devicesController.get(transport_1.CoreId.from(request.id));
33843
33845
  if (!device) {
33844
33846
  return ts_utils_1.Result.fail(common_1.RuntimeErrors.general.recordNotFound(transport_1.Device));
33845
33847
  }
33846
- return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device));
33848
+ const currentDevice = this.deviceController.device;
33849
+ const isCurrentDevice = device.id.equals(currentDevice.id);
33850
+ return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device, isCurrentDevice));
33847
33851
  }
33848
33852
  };
33849
33853
  exports.GetDeviceUseCase = GetDeviceUseCase = __decorate([
33850
33854
  __param(0, typescript_ioc_1.Inject),
33851
33855
  __param(1, typescript_ioc_1.Inject),
33856
+ __param(2, typescript_ioc_1.Inject),
33852
33857
  __metadata("design:paramtypes", [transport_1.DevicesController,
33858
+ transport_1.DeviceController,
33853
33859
  Validator])
33854
33860
  ], GetDeviceUseCase);
33855
33861
  //# sourceMappingURL=GetDevice.js.map
@@ -33940,19 +33946,23 @@ const typescript_ioc_1 = __webpack_require__(/*! typescript-ioc */ "./node_modul
33940
33946
  const common_1 = __webpack_require__(/*! ../../common */ "./dist/useCases/common/index.js");
33941
33947
  const DeviceMapper_1 = __webpack_require__(/*! ./DeviceMapper */ "./dist/useCases/transport/devices/DeviceMapper.js");
33942
33948
  let GetDevicesUseCase = exports.GetDevicesUseCase = class GetDevicesUseCase extends common_1.UseCase {
33943
- constructor(devicesController) {
33949
+ constructor(devicesController, deviceController) {
33944
33950
  super();
33945
33951
  this.devicesController = devicesController;
33952
+ this.deviceController = deviceController;
33946
33953
  }
33947
33954
  async executeInternal() {
33948
33955
  const devices = await this.devicesController.list();
33949
- const deviceDTOs = devices.map((device) => DeviceMapper_1.DeviceMapper.toDeviceDTO(device));
33956
+ const currentDevice = this.deviceController.device;
33957
+ const deviceDTOs = devices.map((device) => DeviceMapper_1.DeviceMapper.toDeviceDTO(device, device.id.equals(currentDevice.id)));
33950
33958
  return ts_utils_1.Result.ok(deviceDTOs);
33951
33959
  }
33952
33960
  };
33953
33961
  exports.GetDevicesUseCase = GetDevicesUseCase = __decorate([
33954
33962
  __param(0, typescript_ioc_1.Inject),
33955
- __metadata("design:paramtypes", [transport_1.DevicesController])
33963
+ __param(1, typescript_ioc_1.Inject),
33964
+ __metadata("design:paramtypes", [transport_1.DevicesController,
33965
+ transport_1.DeviceController])
33956
33966
  ], GetDevicesUseCase);
33957
33967
  //# sourceMappingURL=GetDevices.js.map
33958
33968
 
@@ -33995,31 +34005,36 @@ Validator = __decorate([
33995
34005
  __metadata("design:paramtypes", [common_1.SchemaRepository])
33996
34006
  ], Validator);
33997
34007
  let UpdateDeviceUseCase = exports.UpdateDeviceUseCase = class UpdateDeviceUseCase extends common_1.UseCase {
33998
- constructor(devicesController, accountController, validator) {
34008
+ constructor(devicesController, accountController, deviceController, validator) {
33999
34009
  super(validator);
34000
34010
  this.devicesController = devicesController;
34001
34011
  this.accountController = accountController;
34012
+ this.deviceController = deviceController;
34002
34013
  }
34003
34014
  async executeInternal(request) {
34004
34015
  const device = await this.devicesController.get(transport_1.CoreId.from(request.id));
34005
34016
  if (!device) {
34006
34017
  return ts_utils_1.Result.fail(common_1.RuntimeErrors.general.recordNotFound(transport_1.Device));
34007
34018
  }
34008
- if (request.name) {
34019
+ if (typeof request.name !== "undefined") {
34009
34020
  device.name = request.name;
34010
34021
  }
34011
34022
  device.description = request.description;
34012
34023
  await this.devicesController.update(device);
34013
34024
  await this.accountController.syncDatawallet();
34014
- return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device));
34025
+ const currentDevice = this.deviceController.device;
34026
+ const isCurrentDevice = device.id.equals(currentDevice.id);
34027
+ return ts_utils_1.Result.ok(DeviceMapper_1.DeviceMapper.toDeviceDTO(device, isCurrentDevice));
34015
34028
  }
34016
34029
  };
34017
34030
  exports.UpdateDeviceUseCase = UpdateDeviceUseCase = __decorate([
34018
34031
  __param(0, typescript_ioc_1.Inject),
34019
34032
  __param(1, typescript_ioc_1.Inject),
34020
34033
  __param(2, typescript_ioc_1.Inject),
34034
+ __param(3, typescript_ioc_1.Inject),
34021
34035
  __metadata("design:paramtypes", [transport_1.DevicesController,
34022
34036
  transport_1.AccountController,
34037
+ transport_1.DeviceController,
34023
34038
  Validator])
34024
34039
  ], UpdateDeviceUseCase);
34025
34040
  //# sourceMappingURL=UpdateDevice.js.map
@@ -67946,7 +67961,7 @@ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
67946
67961
  function mapMonths(f) {
67947
67962
  const ms = [];
67948
67963
  for (let i = 1; i <= 12; i++) {
67949
- const dt = DateTime.utc(2016, i, 1);
67964
+ const dt = DateTime.utc(2009, i, 1);
67950
67965
  ms.push(f(dt));
67951
67966
  }
67952
67967
  return ms;
@@ -67959,8 +67974,8 @@ function mapWeekdays(f) {
67959
67974
  }
67960
67975
  return ms;
67961
67976
  }
67962
- function listStuff(loc, length, defaultOK, englishFn, intlFn) {
67963
- const mode = loc.listingMode(defaultOK);
67977
+ function listStuff(loc, length, englishFn, intlFn) {
67978
+ const mode = loc.listingMode();
67964
67979
  if (mode === "error") {
67965
67980
  return null;
67966
67981
  } else if (mode === "en") {
@@ -68206,8 +68221,8 @@ class Locale {
68206
68221
  defaultToEN: false
68207
68222
  });
68208
68223
  }
68209
- months(length, format = false, defaultOK = true) {
68210
- return listStuff(this, length, defaultOK, months, () => {
68224
+ months(length, format = false) {
68225
+ return listStuff(this, length, months, () => {
68211
68226
  const intl = format ? {
68212
68227
  month: length,
68213
68228
  day: "numeric"
@@ -68221,8 +68236,8 @@ class Locale {
68221
68236
  return this.monthsCache[formatStr][length];
68222
68237
  });
68223
68238
  }
68224
- weekdays(length, format = false, defaultOK = true) {
68225
- return listStuff(this, length, defaultOK, weekdays, () => {
68239
+ weekdays(length, format = false) {
68240
+ return listStuff(this, length, weekdays, () => {
68226
68241
  const intl = format ? {
68227
68242
  weekday: length,
68228
68243
  year: "numeric",
@@ -68238,8 +68253,8 @@ class Locale {
68238
68253
  return this.weekdaysCache[formatStr][length];
68239
68254
  });
68240
68255
  }
68241
- meridiems(defaultOK = true) {
68242
- return listStuff(this, undefined, defaultOK, () => meridiems, () => {
68256
+ meridiems() {
68257
+ return listStuff(this, undefined, () => meridiems, () => {
68243
68258
  // In theory there could be aribitrary day periods. We're gonna assume there are exactly two
68244
68259
  // for AM and PM. This is probably wrong, but it's makes parsing way easier.
68245
68260
  if (!this.meridiemCache) {
@@ -68252,8 +68267,8 @@ class Locale {
68252
68267
  return this.meridiemCache;
68253
68268
  });
68254
68269
  }
68255
- eras(length, defaultOK = true) {
68256
- return listStuff(this, length, defaultOK, eras, () => {
68270
+ eras(length) {
68271
+ return listStuff(this, length, eras, () => {
68257
68272
  const intl = {
68258
68273
  era: length
68259
68274
  };
@@ -68457,7 +68472,7 @@ function normalizeZone(input, defaultZone) {
68457
68472
  if (lowered === "default") return defaultZone;else if (lowered === "local" || lowered === "system") return SystemZone.instance;else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input);
68458
68473
  } else if (isNumber(input)) {
68459
68474
  return FixedOffsetZone.instance(input);
68460
- } else if (typeof input === "object" && input.offset && typeof input.offset === "number") {
68475
+ } else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") {
68461
68476
  // This is dumb, but the instanceof check above doesn't seem to really work
68462
68477
  // so we're duck checking it
68463
68478
  return input;
@@ -68574,10 +68589,10 @@ class Settings {
68574
68589
  /**
68575
68590
  * Set the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
68576
68591
  * @type {number}
68577
- * @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpretted as current century
68592
+ * @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpreted as current century
68578
68593
  * @example Settings.twoDigitCutoffYear = 50 // '49' -> 1949; '50' -> 2050
68579
- * @example Settings.twoDigitCutoffYear = 1950 // interpretted as 50
68580
- * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpretted as 50
68594
+ * @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50
68595
+ * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50
68581
68596
  */
68582
68597
  static set twoDigitCutoffYear(cutoffYear) {
68583
68598
  twoDigitCutoffYear = cutoffYear % 100;
@@ -68744,7 +68759,7 @@ function daysInMonth(year, month) {
68744
68759
  }
68745
68760
  }
68746
68761
 
68747
- // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
68762
+ // convert a calendar object to a local timestamp (epoch, but with the offset baked in)
68748
68763
  function objToLocalTS(obj) {
68749
68764
  let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond);
68750
68765
 
@@ -69046,33 +69061,24 @@ class Formatter {
69046
69061
  });
69047
69062
  return df.format();
69048
69063
  }
69049
- formatDateTime(dt, opts = {}) {
69050
- const df = this.loc.dtFormatter(dt, {
69064
+ dtFormatter(dt, opts = {}) {
69065
+ return this.loc.dtFormatter(dt, {
69051
69066
  ...this.opts,
69052
69067
  ...opts
69053
69068
  });
69054
- return df.format();
69055
69069
  }
69056
- formatDateTimeParts(dt, opts = {}) {
69057
- const df = this.loc.dtFormatter(dt, {
69058
- ...this.opts,
69059
- ...opts
69060
- });
69061
- return df.formatToParts();
69070
+ formatDateTime(dt, opts) {
69071
+ return this.dtFormatter(dt, opts).format();
69062
69072
  }
69063
- formatInterval(interval, opts = {}) {
69064
- const df = this.loc.dtFormatter(interval.start, {
69065
- ...this.opts,
69066
- ...opts
69067
- });
69073
+ formatDateTimeParts(dt, opts) {
69074
+ return this.dtFormatter(dt, opts).formatToParts();
69075
+ }
69076
+ formatInterval(interval, opts) {
69077
+ const df = this.dtFormatter(interval.start, opts);
69068
69078
  return df.dtf.formatRange(interval.start.toJSDate(), interval.end.toJSDate());
69069
69079
  }
69070
- resolvedOptions(dt, opts = {}) {
69071
- const df = this.loc.dtFormatter(dt, {
69072
- ...this.opts,
69073
- ...opts
69074
- });
69075
- return df.resolvedOptions();
69080
+ resolvedOptions(dt, opts) {
69081
+ return this.dtFormatter(dt, opts).resolvedOptions();
69076
69082
  }
69077
69083
  num(n, p = 0) {
69078
69084
  // we get some perf out of doing this here, annoyingly
@@ -69126,7 +69132,7 @@ class Formatter {
69126
69132
  era: length
69127
69133
  }, "era"),
69128
69134
  tokenToString = token => {
69129
- // Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles
69135
+ // Where possible: https://cldr.unicode.org/translation/date-time/date-time-symbols
69130
69136
  switch (token) {
69131
69137
  // ms
69132
69138
  case "S":
@@ -69715,19 +69721,19 @@ function clone$1(dur, alts, clear = false) {
69715
69721
  };
69716
69722
  return new Duration(conf);
69717
69723
  }
69718
- function antiTrunc(n) {
69719
- return n < 0 ? Math.floor(n) : Math.ceil(n);
69724
+
69725
+ // this is needed since in some test cases it would return 0.9999999999999999 instead of 1
69726
+ function removePrecisionIssue(a) {
69727
+ return Math.trunc(a * 1e3) / 1e3;
69720
69728
  }
69721
69729
 
69722
69730
  // NB: mutates parameters
69723
69731
  function convert(matrix, fromMap, fromUnit, toMap, toUnit) {
69724
69732
  const conv = matrix[toUnit][fromUnit],
69725
69733
  raw = fromMap[fromUnit] / conv,
69726
- sameSign = Math.sign(raw) === Math.sign(toMap[toUnit]),
69727
- // ok, so this is wild, but see the matrix in the tests
69728
- added = !sameSign && toMap[toUnit] !== 0 && Math.abs(raw) <= 1 ? antiTrunc(raw) : Math.trunc(raw);
69729
- toMap[toUnit] += added;
69730
- fromMap[fromUnit] -= added * conv;
69734
+ added = Math.floor(raw);
69735
+ toMap[toUnit] = removePrecisionIssue(toMap[toUnit] + added);
69736
+ fromMap[fromUnit] = removePrecisionIssue(fromMap[fromUnit] - added * conv);
69731
69737
  }
69732
69738
 
69733
69739
  // NB: mutates parameters
@@ -70126,21 +70132,13 @@ class Duration {
70126
70132
  suppressSeconds: false,
70127
70133
  includePrefix: false,
70128
70134
  format: "extended",
70129
- ...opts
70135
+ ...opts,
70136
+ includeOffset: false
70130
70137
  };
70131
- const value = this.shiftTo("hours", "minutes", "seconds", "milliseconds");
70132
- let fmt = opts.format === "basic" ? "hhmm" : "hh:mm";
70133
- if (!opts.suppressSeconds || value.seconds !== 0 || value.milliseconds !== 0) {
70134
- fmt += opts.format === "basic" ? "ss" : ":ss";
70135
- if (!opts.suppressMilliseconds || value.milliseconds !== 0) {
70136
- fmt += ".SSS";
70137
- }
70138
- }
70139
- let str = value.toFormat(fmt);
70140
- if (opts.includePrefix) {
70141
- str = "T" + str;
70142
- }
70143
- return str;
70138
+ const dateTime = DateTime.fromMillis(millis, {
70139
+ zone: "UTC"
70140
+ });
70141
+ return dateTime.toISOTime(opts);
70144
70142
  }
70145
70143
 
70146
70144
  /**
@@ -70164,7 +70162,15 @@ class Duration {
70164
70162
  * @return {number}
70165
70163
  */
70166
70164
  toMillis() {
70167
- return this.as("milliseconds");
70165
+ var _this$values$millisec;
70166
+ let sum = (_this$values$millisec = this.values.milliseconds) != null ? _this$values$millisec : 0;
70167
+ for (let unit of reverseUnits.slice(1)) {
70168
+ var _this$values;
70169
+ if ((_this$values = this.values) != null && _this$values[unit]) {
70170
+ sum += this.values[unit] * this.matrix[unit]["milliseconds"];
70171
+ }
70172
+ }
70173
+ return sum;
70168
70174
  }
70169
70175
 
70170
70176
  /**
@@ -70297,10 +70303,13 @@ class Duration {
70297
70303
  normalize() {
70298
70304
  if (!this.isValid) return this;
70299
70305
  const vals = this.toObject();
70300
- normalizeValues(this.matrix, vals);
70301
- return clone$1(this, {
70302
- values: vals
70303
- }, true);
70306
+ if (this.valueOf() >= 0) {
70307
+ normalizeValues(this.matrix, vals);
70308
+ return clone$1(this, {
70309
+ values: vals
70310
+ }, true);
70311
+ }
70312
+ return this.negate().normalize().negate();
70304
70313
  }
70305
70314
 
70306
70315
  /**
@@ -71329,14 +71338,35 @@ function highOrderDiffs(cursor, later, units) {
71329
71338
  const results = {};
71330
71339
  const earlier = cursor;
71331
71340
  let lowestOrder, highWater;
71341
+
71342
+ /* This loop tries to diff using larger units first.
71343
+ If we overshoot, we backtrack and try the next smaller unit.
71344
+ "cursor" starts out at the earlier timestamp and moves closer and closer to "later"
71345
+ as we use smaller and smaller units.
71346
+ highWater keeps track of where we would be if we added one more of the smallest unit,
71347
+ this is used later to potentially convert any difference smaller than the smallest higher order unit
71348
+ into a fraction of that smallest higher order unit
71349
+ */
71332
71350
  for (const [unit, differ] of differs) {
71333
71351
  if (units.indexOf(unit) >= 0) {
71334
71352
  lowestOrder = unit;
71335
71353
  results[unit] = differ(cursor, later);
71336
71354
  highWater = earlier.plus(results);
71337
71355
  if (highWater > later) {
71356
+ // we overshot the end point, backtrack cursor by 1
71338
71357
  results[unit]--;
71339
71358
  cursor = earlier.plus(results);
71359
+
71360
+ // if we are still overshooting now, we need to backtrack again
71361
+ // this happens in certain situations when diffing times in different zones,
71362
+ // because this calculation ignores time zones
71363
+ if (cursor > later) {
71364
+ // keep the "overshot by 1" around as highWater
71365
+ highWater = cursor;
71366
+ // backtrack cursor by 1
71367
+ results[unit]--;
71368
+ cursor = earlier.plus(results);
71369
+ }
71340
71370
  } else {
71341
71371
  cursor = highWater;
71342
71372
  }
@@ -71485,6 +71515,11 @@ function simple(regex) {
71485
71515
  function escapeToken(value) {
71486
71516
  return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
71487
71517
  }
71518
+
71519
+ /**
71520
+ * @param token
71521
+ * @param {Locale} loc
71522
+ */
71488
71523
  function unitForToken(token, loc) {
71489
71524
  const one = digitRegex(loc),
71490
71525
  two = digitRegex(loc, "{2}"),
@@ -71509,9 +71544,9 @@ function unitForToken(token, loc) {
71509
71544
  switch (t.val) {
71510
71545
  // era
71511
71546
  case "G":
71512
- return oneOf(loc.eras("short", false), 0);
71547
+ return oneOf(loc.eras("short"), 0);
71513
71548
  case "GG":
71514
- return oneOf(loc.eras("long", false), 0);
71549
+ return oneOf(loc.eras("long"), 0);
71515
71550
  // years
71516
71551
  case "y":
71517
71552
  return intUnit(oneToSix);
@@ -71529,17 +71564,17 @@ function unitForToken(token, loc) {
71529
71564
  case "MM":
71530
71565
  return intUnit(two);
71531
71566
  case "MMM":
71532
- return oneOf(loc.months("short", true, false), 1);
71567
+ return oneOf(loc.months("short", true), 1);
71533
71568
  case "MMMM":
71534
- return oneOf(loc.months("long", true, false), 1);
71569
+ return oneOf(loc.months("long", true), 1);
71535
71570
  case "L":
71536
71571
  return intUnit(oneOrTwo);
71537
71572
  case "LL":
71538
71573
  return intUnit(two);
71539
71574
  case "LLL":
71540
- return oneOf(loc.months("short", false, false), 1);
71575
+ return oneOf(loc.months("short", false), 1);
71541
71576
  case "LLLL":
71542
- return oneOf(loc.months("long", false, false), 1);
71577
+ return oneOf(loc.months("long", false), 1);
71543
71578
  // dates
71544
71579
  case "d":
71545
71580
  return intUnit(oneOrTwo);
@@ -71599,13 +71634,13 @@ function unitForToken(token, loc) {
71599
71634
  case "c":
71600
71635
  return intUnit(one);
71601
71636
  case "EEE":
71602
- return oneOf(loc.weekdays("short", false, false), 1);
71637
+ return oneOf(loc.weekdays("short", false), 1);
71603
71638
  case "EEEE":
71604
- return oneOf(loc.weekdays("long", false, false), 1);
71639
+ return oneOf(loc.weekdays("long", false), 1);
71605
71640
  case "ccc":
71606
- return oneOf(loc.weekdays("short", true, false), 1);
71641
+ return oneOf(loc.weekdays("short", true), 1);
71607
71642
  case "cccc":
71608
- return oneOf(loc.weekdays("long", true, false), 1);
71643
+ return oneOf(loc.weekdays("long", true), 1);
71609
71644
  // offset/zone
71610
71645
  case "Z":
71611
71646
  case "ZZ":
@@ -71651,10 +71686,14 @@ const partTypeStyleToTokenVal = {
71651
71686
  },
71652
71687
  dayperiod: "a",
71653
71688
  dayPeriod: "a",
71654
- hour: {
71689
+ hour12: {
71655
71690
  numeric: "h",
71656
71691
  "2-digit": "hh"
71657
71692
  },
71693
+ hour24: {
71694
+ numeric: "H",
71695
+ "2-digit": "HH"
71696
+ },
71658
71697
  minute: {
71659
71698
  numeric: "m",
71660
71699
  "2-digit": "mm"
@@ -71668,7 +71707,7 @@ const partTypeStyleToTokenVal = {
71668
71707
  short: "ZZZ"
71669
71708
  }
71670
71709
  };
71671
- function tokenForPart(part, formatOpts) {
71710
+ function tokenForPart(part, formatOpts, resolvedOpts) {
71672
71711
  const {
71673
71712
  type,
71674
71713
  value
@@ -71681,7 +71720,27 @@ function tokenForPart(part, formatOpts) {
71681
71720
  };
71682
71721
  }
71683
71722
  const style = formatOpts[type];
71684
- let val = partTypeStyleToTokenVal[type];
71723
+
71724
+ // The user might have explicitly specified hour12 or hourCycle
71725
+ // if so, respect their decision
71726
+ // if not, refer back to the resolvedOpts, which are based on the locale
71727
+ let actualType = type;
71728
+ if (type === "hour") {
71729
+ if (formatOpts.hour12 != null) {
71730
+ actualType = formatOpts.hour12 ? "hour12" : "hour24";
71731
+ } else if (formatOpts.hourCycle != null) {
71732
+ if (formatOpts.hourCycle === "h11" || formatOpts.hourCycle === "h12") {
71733
+ actualType = "hour12";
71734
+ } else {
71735
+ actualType = "hour24";
71736
+ }
71737
+ } else {
71738
+ // tokens only differentiate between 24 hours or not,
71739
+ // so we do not need to check hourCycle here, which is less supported anyways
71740
+ actualType = resolvedOpts.hour12 ? "hour12" : "hour24";
71741
+ }
71742
+ }
71743
+ let val = partTypeStyleToTokenVal[actualType];
71685
71744
  if (typeof val === "object") {
71686
71745
  val = val[style];
71687
71746
  }
@@ -71857,8 +71916,10 @@ function formatOptsToTokens(formatOpts, locale) {
71857
71916
  return null;
71858
71917
  }
71859
71918
  const formatter = Formatter.create(locale, formatOpts);
71860
- const parts = formatter.formatDateTimeParts(getDummyDateTime());
71861
- return parts.map(p => tokenForPart(p, formatOpts));
71919
+ const df = formatter.dtFormatter(getDummyDateTime());
71920
+ const parts = df.formatToParts();
71921
+ const resolvedOpts = df.resolvedOptions();
71922
+ return parts.map(p => tokenForPart(p, formatOpts, resolvedOpts));
71862
71923
  }
71863
71924
 
71864
71925
  const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
@@ -72194,13 +72255,13 @@ function toISOTime(o, extended, suppressSeconds, suppressMilliseconds, includeOf
72194
72255
  if (extended) {
72195
72256
  c += ":";
72196
72257
  c += padStart(o.c.minute);
72197
- if (o.c.second !== 0 || !suppressSeconds) {
72258
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
72198
72259
  c += ":";
72199
72260
  }
72200
72261
  } else {
72201
72262
  c += padStart(o.c.minute);
72202
72263
  }
72203
- if (o.c.second !== 0 || !suppressSeconds) {
72264
+ if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
72204
72265
  c += padStart(o.c.second);
72205
72266
  if (o.c.millisecond !== 0 || !suppressMilliseconds) {
72206
72267
  c += ".";
@@ -72834,7 +72895,7 @@ class DateTime {
72834
72895
 
72835
72896
  /**
72836
72897
  * Create an invalid DateTime.
72837
- * @param {DateTime} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
72898
+ * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent.
72838
72899
  * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
72839
72900
  * @return {DateTime}
72840
72901
  */
@@ -73193,6 +73254,41 @@ class DateTime {
73193
73254
  }
73194
73255
  }
73195
73256
 
73257
+ /**
73258
+ * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC
73259
+ * in this DateTime's zone. During DST changes local time can be ambiguous, for example
73260
+ * `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`.
73261
+ * This method will return both possible DateTimes if this DateTime's local time is ambiguous.
73262
+ * @returns {DateTime[]}
73263
+ */
73264
+ getPossibleOffsets() {
73265
+ if (!this.isValid || this.isOffsetFixed) {
73266
+ return [this];
73267
+ }
73268
+ const dayMs = 86400000;
73269
+ const minuteMs = 60000;
73270
+ const localTS = objToLocalTS(this.c);
73271
+ const oEarlier = this.zone.offset(localTS - dayMs);
73272
+ const oLater = this.zone.offset(localTS + dayMs);
73273
+ const o1 = this.zone.offset(localTS - oEarlier * minuteMs);
73274
+ const o2 = this.zone.offset(localTS - oLater * minuteMs);
73275
+ if (o1 === o2) {
73276
+ return [this];
73277
+ }
73278
+ const ts1 = localTS - o1 * minuteMs;
73279
+ const ts2 = localTS - o2 * minuteMs;
73280
+ const c1 = tsToObj(ts1, o1);
73281
+ const c2 = tsToObj(ts2, o2);
73282
+ if (c1.hour === c2.hour && c1.minute === c2.minute && c1.second === c2.second && c1.millisecond === c2.millisecond) {
73283
+ return [clone(this, {
73284
+ ts: ts1
73285
+ }), clone(this, {
73286
+ ts: ts2
73287
+ })];
73288
+ }
73289
+ return [this];
73290
+ }
73291
+
73196
73292
  /**
73197
73293
  * Returns true if this DateTime is in a leap year, false otherwise
73198
73294
  * @example DateTime.local(2016).isInLeapYear //=> true
@@ -74199,7 +74295,7 @@ function friendlyDateTime(dateTimeish) {
74199
74295
  }
74200
74296
  }
74201
74297
 
74202
- const VERSION = "3.3.0";
74298
+ const VERSION = "3.4.0";
74203
74299
 
74204
74300
  exports.DateTime = DateTime;
74205
74301
  exports.Duration = Duration;