@nmshd/consumption 3.6.2 → 3.6.4

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.
@@ -17,10 +17,10 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
17
17
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
18
18
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
19
19
  exports.buildInformation = {
20
- version: "3.6.2",
21
- build: "116",
22
- date: "2023-11-09T16:33:07+00:00",
23
- commit: "0b2e044d30a6200cf5f7b144ef6e290bbd142c6d",
20
+ version: "3.6.4",
21
+ build: "118",
22
+ date: "2023-11-15T07:25:15+00:00",
23
+ commit: "cb9f401e1770fbb33b804826b93939826d831738",
24
24
  dependencies: {"@js-soft/docdb-querytranslator":"^1.1.1","@nmshd/iql":"^0.0.4","ts-simple-nameof":"^1.3.1"},
25
25
  libraries: {
26
26
  transport: transport_1.buildInformation,
@@ -1519,6 +1519,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1519
1519
  exports.AttributeSuccessorParams = void 0;
1520
1520
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
1521
1521
  const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
1522
+ const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
1523
+ const LocalAttributeShareInfo_1 = __webpack_require__(/*! ./LocalAttributeShareInfo */ "./dist/modules/attributes/local/LocalAttributeShareInfo.js");
1522
1524
  let AttributeSuccessorParams = class AttributeSuccessorParams extends ts_serval_1.Serializable {
1523
1525
  static from(value) {
1524
1526
  return this.fromAny(value);
@@ -1528,7 +1530,7 @@ exports.AttributeSuccessorParams = AttributeSuccessorParams;
1528
1530
  __decorate([
1529
1531
  (0, ts_serval_1.validate)({ nullable: true }),
1530
1532
  (0, ts_serval_1.serialize)(),
1531
- __metadata("design:type", Object)
1533
+ __metadata("design:type", transport_1.CoreId)
1532
1534
  ], AttributeSuccessorParams.prototype, "id", void 0);
1533
1535
  __decorate([
1534
1536
  (0, ts_serval_1.validate)(),
@@ -1538,27 +1540,27 @@ __decorate([
1538
1540
  __decorate([
1539
1541
  (0, ts_serval_1.validate)({ nullable: true }),
1540
1542
  (0, ts_serval_1.serialize)(),
1541
- __metadata("design:type", Object)
1543
+ __metadata("design:type", transport_1.CoreDate)
1542
1544
  ], AttributeSuccessorParams.prototype, "createdAt", void 0);
1543
1545
  __decorate([
1544
1546
  (0, ts_serval_1.validate)({ nullable: true }),
1545
1547
  (0, ts_serval_1.serialize)(),
1546
- __metadata("design:type", Object)
1548
+ __metadata("design:type", transport_1.CoreId)
1547
1549
  ], AttributeSuccessorParams.prototype, "succeeds", void 0);
1548
1550
  __decorate([
1549
1551
  (0, ts_serval_1.validate)({ nullable: true }),
1550
1552
  (0, ts_serval_1.serialize)(),
1551
- __metadata("design:type", Object)
1553
+ __metadata("design:type", transport_1.CoreId)
1552
1554
  ], AttributeSuccessorParams.prototype, "succeededBy", void 0);
1553
1555
  __decorate([
1554
1556
  (0, ts_serval_1.validate)({ nullable: true }),
1555
1557
  (0, ts_serval_1.serialize)(),
1556
- __metadata("design:type", Object)
1558
+ __metadata("design:type", LocalAttributeShareInfo_1.LocalAttributeShareInfo)
1557
1559
  ], AttributeSuccessorParams.prototype, "shareInfo", void 0);
1558
1560
  __decorate([
1559
1561
  (0, ts_serval_1.validate)({ nullable: true }),
1560
1562
  (0, ts_serval_1.serialize)(),
1561
- __metadata("design:type", Object)
1563
+ __metadata("design:type", transport_1.CoreId)
1562
1564
  ], AttributeSuccessorParams.prototype, "parentId", void 0);
1563
1565
  exports.AttributeSuccessorParams = AttributeSuccessorParams = __decorate([
1564
1566
  (0, ts_serval_1.type)("AttributeSuccessorParams")
@@ -27543,6 +27545,17 @@ function systemLocale() {
27543
27545
  return sysLocaleCache;
27544
27546
  }
27545
27547
  }
27548
+ let weekInfoCache = {};
27549
+ function getCachedWeekInfo(locString) {
27550
+ let data = weekInfoCache[locString];
27551
+ if (!data) {
27552
+ const locale = new Intl.Locale(locString);
27553
+ // browsers currently implement this as a property, but spec says it should be a getter function
27554
+ data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
27555
+ weekInfoCache[locString] = data;
27556
+ }
27557
+ return data;
27558
+ }
27546
27559
  function parseLocaleString(localeStr) {
27547
27560
  // I really want to avoid writing a BCP 47 parser
27548
27561
  // see, e.g. https://github.com/wooorm/bcp-47
@@ -27780,6 +27793,11 @@ class PolyRelFormatter {
27780
27793
  }
27781
27794
  }
27782
27795
  }
27796
+ const fallbackWeekSettings = {
27797
+ firstDay: 1,
27798
+ minimalDays: 4,
27799
+ weekend: [6, 7]
27800
+ };
27783
27801
 
27784
27802
  /**
27785
27803
  * @private
@@ -27787,15 +27805,16 @@ class PolyRelFormatter {
27787
27805
 
27788
27806
  class Locale {
27789
27807
  static fromOpts(opts) {
27790
- return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN);
27808
+ return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.weekSettings, opts.defaultToEN);
27791
27809
  }
27792
- static create(locale, numberingSystem, outputCalendar, defaultToEN = false) {
27810
+ static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
27793
27811
  const specifiedLocale = locale || Settings.defaultLocale;
27794
27812
  // the system locale is useful for human readable strings but annoying for parsing/formatting known formats
27795
27813
  const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
27796
27814
  const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
27797
27815
  const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
27798
- return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale);
27816
+ const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
27817
+ return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
27799
27818
  }
27800
27819
  static resetCache() {
27801
27820
  sysLocaleCache = null;
@@ -27806,15 +27825,17 @@ class Locale {
27806
27825
  static fromObject({
27807
27826
  locale,
27808
27827
  numberingSystem,
27809
- outputCalendar
27828
+ outputCalendar,
27829
+ weekSettings
27810
27830
  } = {}) {
27811
- return Locale.create(locale, numberingSystem, outputCalendar);
27831
+ return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
27812
27832
  }
27813
- constructor(locale, numbering, outputCalendar, specifiedLocale) {
27833
+ constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
27814
27834
  const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
27815
27835
  this.locale = parsedLocale;
27816
27836
  this.numberingSystem = numbering || parsedNumberingSystem || null;
27817
27837
  this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
27838
+ this.weekSettings = weekSettings;
27818
27839
  this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
27819
27840
  this.weekdaysCache = {
27820
27841
  format: {},
@@ -27844,7 +27865,7 @@ class Locale {
27844
27865
  if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
27845
27866
  return this;
27846
27867
  } else {
27847
- return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false);
27868
+ return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, validateWeekSettings(alts.weekSettings) || this.weekSettings, alts.defaultToEN || false);
27848
27869
  }
27849
27870
  }
27850
27871
  redefaultToEN(alts = {}) {
@@ -27942,6 +27963,24 @@ class Locale {
27942
27963
  isEnglish() {
27943
27964
  return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
27944
27965
  }
27966
+ getWeekSettings() {
27967
+ if (this.weekSettings) {
27968
+ return this.weekSettings;
27969
+ } else if (!hasLocaleWeekInfo()) {
27970
+ return fallbackWeekSettings;
27971
+ } else {
27972
+ return getCachedWeekInfo(this.locale);
27973
+ }
27974
+ }
27975
+ getStartOfWeek() {
27976
+ return this.getWeekSettings().firstDay;
27977
+ }
27978
+ getMinDaysInFirstWeek() {
27979
+ return this.getWeekSettings().minimalDays;
27980
+ }
27981
+ getWeekendDays() {
27982
+ return this.getWeekSettings().weekend;
27983
+ }
27945
27984
  equals(other) {
27946
27985
  return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
27947
27986
  }
@@ -28125,7 +28164,8 @@ let now = () => Date.now(),
28125
28164
  defaultNumberingSystem = null,
28126
28165
  defaultOutputCalendar = null,
28127
28166
  twoDigitCutoffYear = 60,
28128
- throwOnInvalid;
28167
+ throwOnInvalid,
28168
+ defaultWeekSettings = null;
28129
28169
 
28130
28170
  /**
28131
28171
  * Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.
@@ -28216,6 +28256,31 @@ class Settings {
28216
28256
  defaultOutputCalendar = outputCalendar;
28217
28257
  }
28218
28258
 
28259
+ /**
28260
+ * @typedef {Object} WeekSettings
28261
+ * @property {number} firstDay
28262
+ * @property {number} minimalDays
28263
+ * @property {number[]} weekend
28264
+ */
28265
+
28266
+ /**
28267
+ * @return {WeekSettings|null}
28268
+ */
28269
+ static get defaultWeekSettings() {
28270
+ return defaultWeekSettings;
28271
+ }
28272
+
28273
+ /**
28274
+ * Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
28275
+ * how many days are required in the first week of a year.
28276
+ * Does not affect existing instances.
28277
+ *
28278
+ * @param {WeekSettings|null} weekSettings
28279
+ */
28280
+ static set defaultWeekSettings(weekSettings) {
28281
+ defaultWeekSettings = validateWeekSettings(weekSettings);
28282
+ }
28283
+
28219
28284
  /**
28220
28285
  * Get the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
28221
28286
  * @type {number}
@@ -28262,6 +28327,224 @@ class Settings {
28262
28327
  }
28263
28328
  }
28264
28329
 
28330
+ class Invalid {
28331
+ constructor(reason, explanation) {
28332
+ this.reason = reason;
28333
+ this.explanation = explanation;
28334
+ }
28335
+ toMessage() {
28336
+ if (this.explanation) {
28337
+ return `${this.reason}: ${this.explanation}`;
28338
+ } else {
28339
+ return this.reason;
28340
+ }
28341
+ }
28342
+ }
28343
+
28344
+ const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
28345
+ leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
28346
+ function unitOutOfRange(unit, value) {
28347
+ return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
28348
+ }
28349
+ function dayOfWeek(year, month, day) {
28350
+ const d = new Date(Date.UTC(year, month - 1, day));
28351
+ if (year < 100 && year >= 0) {
28352
+ d.setUTCFullYear(d.getUTCFullYear() - 1900);
28353
+ }
28354
+ const js = d.getUTCDay();
28355
+ return js === 0 ? 7 : js;
28356
+ }
28357
+ function computeOrdinal(year, month, day) {
28358
+ return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
28359
+ }
28360
+ function uncomputeOrdinal(year, ordinal) {
28361
+ const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
28362
+ month0 = table.findIndex(i => i < ordinal),
28363
+ day = ordinal - table[month0];
28364
+ return {
28365
+ month: month0 + 1,
28366
+ day
28367
+ };
28368
+ }
28369
+ function isoWeekdayToLocal(isoWeekday, startOfWeek) {
28370
+ return (isoWeekday - startOfWeek + 7) % 7 + 1;
28371
+ }
28372
+
28373
+ /**
28374
+ * @private
28375
+ */
28376
+
28377
+ function gregorianToWeek(gregObj, minDaysInFirstWeek = 4, startOfWeek = 1) {
28378
+ const {
28379
+ year,
28380
+ month,
28381
+ day
28382
+ } = gregObj,
28383
+ ordinal = computeOrdinal(year, month, day),
28384
+ weekday = isoWeekdayToLocal(dayOfWeek(year, month, day), startOfWeek);
28385
+ let weekNumber = Math.floor((ordinal - weekday + 14 - minDaysInFirstWeek) / 7),
28386
+ weekYear;
28387
+ if (weekNumber < 1) {
28388
+ weekYear = year - 1;
28389
+ weekNumber = weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek);
28390
+ } else if (weekNumber > weeksInWeekYear(year, minDaysInFirstWeek, startOfWeek)) {
28391
+ weekYear = year + 1;
28392
+ weekNumber = 1;
28393
+ } else {
28394
+ weekYear = year;
28395
+ }
28396
+ return {
28397
+ weekYear,
28398
+ weekNumber,
28399
+ weekday,
28400
+ ...timeObject(gregObj)
28401
+ };
28402
+ }
28403
+ function weekToGregorian(weekData, minDaysInFirstWeek = 4, startOfWeek = 1) {
28404
+ const {
28405
+ weekYear,
28406
+ weekNumber,
28407
+ weekday
28408
+ } = weekData,
28409
+ weekdayOfJan4 = isoWeekdayToLocal(dayOfWeek(weekYear, 1, minDaysInFirstWeek), startOfWeek),
28410
+ yearInDays = daysInYear(weekYear);
28411
+ let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 7 + minDaysInFirstWeek,
28412
+ year;
28413
+ if (ordinal < 1) {
28414
+ year = weekYear - 1;
28415
+ ordinal += daysInYear(year);
28416
+ } else if (ordinal > yearInDays) {
28417
+ year = weekYear + 1;
28418
+ ordinal -= daysInYear(weekYear);
28419
+ } else {
28420
+ year = weekYear;
28421
+ }
28422
+ const {
28423
+ month,
28424
+ day
28425
+ } = uncomputeOrdinal(year, ordinal);
28426
+ return {
28427
+ year,
28428
+ month,
28429
+ day,
28430
+ ...timeObject(weekData)
28431
+ };
28432
+ }
28433
+ function gregorianToOrdinal(gregData) {
28434
+ const {
28435
+ year,
28436
+ month,
28437
+ day
28438
+ } = gregData;
28439
+ const ordinal = computeOrdinal(year, month, day);
28440
+ return {
28441
+ year,
28442
+ ordinal,
28443
+ ...timeObject(gregData)
28444
+ };
28445
+ }
28446
+ function ordinalToGregorian(ordinalData) {
28447
+ const {
28448
+ year,
28449
+ ordinal
28450
+ } = ordinalData;
28451
+ const {
28452
+ month,
28453
+ day
28454
+ } = uncomputeOrdinal(year, ordinal);
28455
+ return {
28456
+ year,
28457
+ month,
28458
+ day,
28459
+ ...timeObject(ordinalData)
28460
+ };
28461
+ }
28462
+
28463
+ /**
28464
+ * Check if local week units like localWeekday are used in obj.
28465
+ * If so, validates that they are not mixed with ISO week units and then copies them to the normal week unit properties.
28466
+ * Modifies obj in-place!
28467
+ * @param obj the object values
28468
+ */
28469
+ function usesLocalWeekValues(obj, loc) {
28470
+ const hasLocaleWeekData = !isUndefined(obj.localWeekday) || !isUndefined(obj.localWeekNumber) || !isUndefined(obj.localWeekYear);
28471
+ if (hasLocaleWeekData) {
28472
+ const hasIsoWeekData = !isUndefined(obj.weekday) || !isUndefined(obj.weekNumber) || !isUndefined(obj.weekYear);
28473
+ if (hasIsoWeekData) {
28474
+ throw new ConflictingSpecificationError("Cannot mix locale-based week fields with ISO-based week fields");
28475
+ }
28476
+ if (!isUndefined(obj.localWeekday)) obj.weekday = obj.localWeekday;
28477
+ if (!isUndefined(obj.localWeekNumber)) obj.weekNumber = obj.localWeekNumber;
28478
+ if (!isUndefined(obj.localWeekYear)) obj.weekYear = obj.localWeekYear;
28479
+ delete obj.localWeekday;
28480
+ delete obj.localWeekNumber;
28481
+ delete obj.localWeekYear;
28482
+ return {
28483
+ minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
28484
+ startOfWeek: loc.getStartOfWeek()
28485
+ };
28486
+ } else {
28487
+ return {
28488
+ minDaysInFirstWeek: 4,
28489
+ startOfWeek: 1
28490
+ };
28491
+ }
28492
+ }
28493
+ function hasInvalidWeekData(obj, minDaysInFirstWeek = 4, startOfWeek = 1) {
28494
+ const validYear = isInteger(obj.weekYear),
28495
+ validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear, minDaysInFirstWeek, startOfWeek)),
28496
+ validWeekday = integerBetween(obj.weekday, 1, 7);
28497
+ if (!validYear) {
28498
+ return unitOutOfRange("weekYear", obj.weekYear);
28499
+ } else if (!validWeek) {
28500
+ return unitOutOfRange("week", obj.weekNumber);
28501
+ } else if (!validWeekday) {
28502
+ return unitOutOfRange("weekday", obj.weekday);
28503
+ } else return false;
28504
+ }
28505
+ function hasInvalidOrdinalData(obj) {
28506
+ const validYear = isInteger(obj.year),
28507
+ validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
28508
+ if (!validYear) {
28509
+ return unitOutOfRange("year", obj.year);
28510
+ } else if (!validOrdinal) {
28511
+ return unitOutOfRange("ordinal", obj.ordinal);
28512
+ } else return false;
28513
+ }
28514
+ function hasInvalidGregorianData(obj) {
28515
+ const validYear = isInteger(obj.year),
28516
+ validMonth = integerBetween(obj.month, 1, 12),
28517
+ validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
28518
+ if (!validYear) {
28519
+ return unitOutOfRange("year", obj.year);
28520
+ } else if (!validMonth) {
28521
+ return unitOutOfRange("month", obj.month);
28522
+ } else if (!validDay) {
28523
+ return unitOutOfRange("day", obj.day);
28524
+ } else return false;
28525
+ }
28526
+ function hasInvalidTimeData(obj) {
28527
+ const {
28528
+ hour,
28529
+ minute,
28530
+ second,
28531
+ millisecond
28532
+ } = obj;
28533
+ const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
28534
+ validMinute = integerBetween(minute, 0, 59),
28535
+ validSecond = integerBetween(second, 0, 59),
28536
+ validMillisecond = integerBetween(millisecond, 0, 999);
28537
+ if (!validHour) {
28538
+ return unitOutOfRange("hour", hour);
28539
+ } else if (!validMinute) {
28540
+ return unitOutOfRange("minute", minute);
28541
+ } else if (!validSecond) {
28542
+ return unitOutOfRange("second", second);
28543
+ } else if (!validMillisecond) {
28544
+ return unitOutOfRange("millisecond", millisecond);
28545
+ } else return false;
28546
+ }
28547
+
28265
28548
  /*
28266
28549
  This is just a junk drawer, containing anything used across multiple classes.
28267
28550
  Because Luxon is small(ish), this should stay small and we won't worry about splitting
@@ -28299,6 +28582,13 @@ function hasRelative() {
28299
28582
  return false;
28300
28583
  }
28301
28584
  }
28585
+ function hasLocaleWeekInfo() {
28586
+ try {
28587
+ return typeof Intl !== "undefined" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
28588
+ } catch (e) {
28589
+ return false;
28590
+ }
28591
+ }
28302
28592
 
28303
28593
  // OBJECTS AND ARRAYS
28304
28594
 
@@ -28329,6 +28619,22 @@ function pick(obj, keys) {
28329
28619
  function hasOwnProperty(obj, prop) {
28330
28620
  return Object.prototype.hasOwnProperty.call(obj, prop);
28331
28621
  }
28622
+ function validateWeekSettings(settings) {
28623
+ if (settings == null) {
28624
+ return null;
28625
+ } else if (typeof settings !== "object") {
28626
+ throw new InvalidArgumentError("Week settings must be an object");
28627
+ } else {
28628
+ if (!integerBetween(settings.firstDay, 1, 7) || !integerBetween(settings.minimalDays, 1, 7) || !Array.isArray(settings.weekend) || settings.weekend.some(v => !integerBetween(v, 1, 7))) {
28629
+ throw new InvalidArgumentError("Invalid week settings");
28630
+ }
28631
+ return {
28632
+ firstDay: settings.firstDay,
28633
+ minimalDays: settings.minimalDays,
28634
+ weekend: Array.from(settings.weekend)
28635
+ };
28636
+ }
28637
+ }
28332
28638
 
28333
28639
  // NUMBERS AND STRINGS
28334
28640
 
@@ -28411,11 +28717,16 @@ function objToLocalTS(obj) {
28411
28717
  }
28412
28718
  return +d;
28413
28719
  }
28414
- function weeksInWeekYear(weekYear) {
28415
- const p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7,
28416
- last = weekYear - 1,
28417
- p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7;
28418
- return p1 === 4 || p2 === 3 ? 53 : 52;
28720
+
28721
+ // adapted from moment.js: https://github.com/moment/moment/blob/000ac1800e620f770f4eb31b5ae908f6167b0ab2/src/lib/units/week-calendar-utils.js
28722
+ function firstWeekOffset(year, minDaysInFirstWeek, startOfWeek) {
28723
+ const fwdlw = isoWeekdayToLocal(dayOfWeek(year, 1, minDaysInFirstWeek), startOfWeek);
28724
+ return -fwdlw + minDaysInFirstWeek - 1;
28725
+ }
28726
+ function weeksInWeekYear(weekYear, minDaysInFirstWeek = 4, startOfWeek = 1) {
28727
+ const weekOffset = firstWeekOffset(weekYear, minDaysInFirstWeek, startOfWeek);
28728
+ const weekOffsetNext = firstWeekOffset(weekYear + 1, minDaysInFirstWeek, startOfWeek);
28729
+ return (daysInYear(weekYear) - weekOffset + weekOffsetNext) / 7;
28419
28730
  }
28420
28731
  function untruncateYear(year) {
28421
28732
  if (year > 99) {
@@ -28956,6 +29267,14 @@ class Formatter {
28956
29267
  return this.num(dt.weekNumber);
28957
29268
  case "WW":
28958
29269
  return this.num(dt.weekNumber, 2);
29270
+ case "n":
29271
+ return this.num(dt.localWeekNumber);
29272
+ case "nn":
29273
+ return this.num(dt.localWeekNumber, 2);
29274
+ case "ii":
29275
+ return this.num(dt.localWeekYear.toString().slice(-2), 2);
29276
+ case "iiii":
29277
+ return this.num(dt.localWeekYear, 4);
28959
29278
  case "o":
28960
29279
  return this.num(dt.ordinal);
28961
29280
  case "ooo":
@@ -29017,20 +29336,6 @@ class Formatter {
29017
29336
  }
29018
29337
  }
29019
29338
 
29020
- class Invalid {
29021
- constructor(reason, explanation) {
29022
- this.reason = reason;
29023
- this.explanation = explanation;
29024
- }
29025
- toMessage() {
29026
- if (this.explanation) {
29027
- return `${this.reason}: ${this.explanation}`;
29028
- } else {
29029
- return this.reason;
29030
- }
29031
- }
29032
- }
29033
-
29034
29339
  /*
29035
29340
  * This file handles parsing for well-specified formats. Here's how it works:
29036
29341
  * Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match.
@@ -29707,9 +30012,10 @@ class Duration {
29707
30012
 
29708
30013
  /**
29709
30014
  * Returns a string representation of a Duration with all units included.
29710
- * To modify its behavior use the `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
29711
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
29712
- * @param opts - On option object to override the formatting. Accepts the same keys as the options parameter of the native `Int.NumberFormat` constructor, as well as `listStyle`.
30015
+ * To modify its behavior, use `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
30016
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
30017
+ * @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
30018
+ * @param {string} [opts.listStyle='narrow'] - How to format the merged list. Corresponds to the `style` property of the options parameter of the native `Intl.ListFormat` constructor.
29713
30019
  * @example
29714
30020
  * ```js
29715
30021
  * var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
@@ -29830,6 +30136,18 @@ class Duration {
29830
30136
  return this.toISO();
29831
30137
  }
29832
30138
 
30139
+ /**
30140
+ * Returns a string representation of this Duration appropriate for the REPL.
30141
+ * @return {string}
30142
+ */
30143
+ [Symbol.for("nodejs.util.inspect.custom")]() {
30144
+ if (this.isValid) {
30145
+ return `Duration { values: ${JSON.stringify(this.values)} }`;
30146
+ } else {
30147
+ return `Duration { Invalid, reason: ${this.invalidReason} }`;
30148
+ }
30149
+ }
30150
+
29833
30151
  /**
29834
30152
  * Returns an milliseconds value of this Duration.
29835
30153
  * @return {number}
@@ -29965,7 +30283,7 @@ class Duration {
29965
30283
  * Assuming the overall value of the Duration is positive, this means:
29966
30284
  * - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
29967
30285
  * - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
29968
- * the overall value would be negative, see second example)
30286
+ * the overall value would be negative, see third example)
29969
30287
  * - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
29970
30288
  *
29971
30289
  * If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
@@ -30423,12 +30741,22 @@ class Interval {
30423
30741
  * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
30424
30742
  * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
30425
30743
  * @param {string} [unit='milliseconds'] - the unit of time to count.
30744
+ * @param {Object} opts - options
30745
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; this operation will always use the locale of the start DateTime
30426
30746
  * @return {number}
30427
30747
  */
30428
- count(unit = "milliseconds") {
30748
+ count(unit = "milliseconds", opts) {
30429
30749
  if (!this.isValid) return NaN;
30430
- const start = this.start.startOf(unit),
30431
- end = this.end.startOf(unit);
30750
+ const start = this.start.startOf(unit, opts);
30751
+ let end;
30752
+ if (opts != null && opts.useLocaleWeeks) {
30753
+ end = this.end.reconfigure({
30754
+ locale: start.locale
30755
+ });
30756
+ } else {
30757
+ end = this.end;
30758
+ }
30759
+ end = end.startOf(unit, opts);
30432
30760
  return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
30433
30761
  }
30434
30762
 
@@ -30501,7 +30829,7 @@ class Interval {
30501
30829
  */
30502
30830
  splitAt(...dateTimes) {
30503
30831
  if (!this.isValid) return [];
30504
- const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort(),
30832
+ const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort((a, b) => a.toMillis() - b.toMillis()),
30505
30833
  results = [];
30506
30834
  let {
30507
30835
  s
@@ -30708,6 +31036,18 @@ class Interval {
30708
31036
  return `[${this.s.toISO()} – ${this.e.toISO()})`;
30709
31037
  }
30710
31038
 
31039
+ /**
31040
+ * Returns a string representation of this Interval appropriate for the REPL.
31041
+ * @return {string}
31042
+ */
31043
+ [Symbol.for("nodejs.util.inspect.custom")]() {
31044
+ if (this.isValid) {
31045
+ return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
31046
+ } else {
31047
+ return `Interval { Invalid, reason: ${this.invalidReason} }`;
31048
+ }
31049
+ }
31050
+
30711
31051
  /**
30712
31052
  * Returns a localized string representing this Interval. Accepts the same options as the
30713
31053
  * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
@@ -30858,6 +31198,50 @@ class Info {
30858
31198
  return normalizeZone(input, Settings.defaultZone);
30859
31199
  }
30860
31200
 
31201
+ /**
31202
+ * Get the weekday on which the week starts according to the given locale.
31203
+ * @param {Object} opts - options
31204
+ * @param {string} [opts.locale] - the locale code
31205
+ * @param {string} [opts.locObj=null] - an existing locale object to use
31206
+ * @returns {number} the start of the week, 1 for Monday through 7 for Sunday
31207
+ */
31208
+ static getStartOfWeek({
31209
+ locale = null,
31210
+ locObj = null
31211
+ } = {}) {
31212
+ return (locObj || Locale.create(locale)).getStartOfWeek();
31213
+ }
31214
+
31215
+ /**
31216
+ * Get the minimum number of days necessary in a week before it is considered part of the next year according
31217
+ * to the given locale.
31218
+ * @param {Object} opts - options
31219
+ * @param {string} [opts.locale] - the locale code
31220
+ * @param {string} [opts.locObj=null] - an existing locale object to use
31221
+ * @returns {number}
31222
+ */
31223
+ static getMinimumDaysInFirstWeek({
31224
+ locale = null,
31225
+ locObj = null
31226
+ } = {}) {
31227
+ return (locObj || Locale.create(locale)).getMinDaysInFirstWeek();
31228
+ }
31229
+
31230
+ /**
31231
+ * Get the weekdays, which are considered the weekend according to the given locale
31232
+ * @param {Object} opts - options
31233
+ * @param {string} [opts.locale] - the locale code
31234
+ * @param {string} [opts.locObj=null] - an existing locale object to use
31235
+ * @returns {number[]} an array of weekdays, 1 for Monday through 7 for Sunday
31236
+ */
31237
+ static getWeekendWeekdays({
31238
+ locale = null,
31239
+ locObj = null
31240
+ } = {}) {
31241
+ // copy the array, because we cache it internally
31242
+ return (locObj || Locale.create(locale)).getWeekendDays().slice();
31243
+ }
31244
+
30861
31245
  /**
30862
31246
  * Return an array of standalone month names.
30863
31247
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
@@ -30983,12 +31367,14 @@ class Info {
30983
31367
  * Some features of Luxon are not available in all environments. For example, on older browsers, relative time formatting support is not available. Use this function to figure out if that's the case.
30984
31368
  * Keys:
30985
31369
  * * `relative`: whether this environment supports relative time formatting
30986
- * @example Info.features() //=> { relative: false }
31370
+ * * `localeWeek`: whether this environment supports different weekdays for the start of the week based on the locale
31371
+ * @example Info.features() //=> { relative: false, localeWeek: true }
30987
31372
  * @return {Object}
30988
31373
  */
30989
31374
  static features() {
30990
31375
  return {
30991
- relative: hasRelative()
31376
+ relative: hasRelative(),
31377
+ localeWeek: hasLocaleWeekInfo()
30992
31378
  };
30993
31379
  }
30994
31380
  }
@@ -31592,176 +31978,6 @@ function formatOptsToTokens(formatOpts, locale) {
31592
31978
  return parts.map(p => tokenForPart(p, formatOpts, resolvedOpts));
31593
31979
  }
31594
31980
 
31595
- const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
31596
- leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
31597
- function unitOutOfRange(unit, value) {
31598
- return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
31599
- }
31600
- function dayOfWeek(year, month, day) {
31601
- const d = new Date(Date.UTC(year, month - 1, day));
31602
- if (year < 100 && year >= 0) {
31603
- d.setUTCFullYear(d.getUTCFullYear() - 1900);
31604
- }
31605
- const js = d.getUTCDay();
31606
- return js === 0 ? 7 : js;
31607
- }
31608
- function computeOrdinal(year, month, day) {
31609
- return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
31610
- }
31611
- function uncomputeOrdinal(year, ordinal) {
31612
- const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
31613
- month0 = table.findIndex(i => i < ordinal),
31614
- day = ordinal - table[month0];
31615
- return {
31616
- month: month0 + 1,
31617
- day
31618
- };
31619
- }
31620
-
31621
- /**
31622
- * @private
31623
- */
31624
-
31625
- function gregorianToWeek(gregObj) {
31626
- const {
31627
- year,
31628
- month,
31629
- day
31630
- } = gregObj,
31631
- ordinal = computeOrdinal(year, month, day),
31632
- weekday = dayOfWeek(year, month, day);
31633
- let weekNumber = Math.floor((ordinal - weekday + 10) / 7),
31634
- weekYear;
31635
- if (weekNumber < 1) {
31636
- weekYear = year - 1;
31637
- weekNumber = weeksInWeekYear(weekYear);
31638
- } else if (weekNumber > weeksInWeekYear(year)) {
31639
- weekYear = year + 1;
31640
- weekNumber = 1;
31641
- } else {
31642
- weekYear = year;
31643
- }
31644
- return {
31645
- weekYear,
31646
- weekNumber,
31647
- weekday,
31648
- ...timeObject(gregObj)
31649
- };
31650
- }
31651
- function weekToGregorian(weekData) {
31652
- const {
31653
- weekYear,
31654
- weekNumber,
31655
- weekday
31656
- } = weekData,
31657
- weekdayOfJan4 = dayOfWeek(weekYear, 1, 4),
31658
- yearInDays = daysInYear(weekYear);
31659
- let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 3,
31660
- year;
31661
- if (ordinal < 1) {
31662
- year = weekYear - 1;
31663
- ordinal += daysInYear(year);
31664
- } else if (ordinal > yearInDays) {
31665
- year = weekYear + 1;
31666
- ordinal -= daysInYear(weekYear);
31667
- } else {
31668
- year = weekYear;
31669
- }
31670
- const {
31671
- month,
31672
- day
31673
- } = uncomputeOrdinal(year, ordinal);
31674
- return {
31675
- year,
31676
- month,
31677
- day,
31678
- ...timeObject(weekData)
31679
- };
31680
- }
31681
- function gregorianToOrdinal(gregData) {
31682
- const {
31683
- year,
31684
- month,
31685
- day
31686
- } = gregData;
31687
- const ordinal = computeOrdinal(year, month, day);
31688
- return {
31689
- year,
31690
- ordinal,
31691
- ...timeObject(gregData)
31692
- };
31693
- }
31694
- function ordinalToGregorian(ordinalData) {
31695
- const {
31696
- year,
31697
- ordinal
31698
- } = ordinalData;
31699
- const {
31700
- month,
31701
- day
31702
- } = uncomputeOrdinal(year, ordinal);
31703
- return {
31704
- year,
31705
- month,
31706
- day,
31707
- ...timeObject(ordinalData)
31708
- };
31709
- }
31710
- function hasInvalidWeekData(obj) {
31711
- const validYear = isInteger(obj.weekYear),
31712
- validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)),
31713
- validWeekday = integerBetween(obj.weekday, 1, 7);
31714
- if (!validYear) {
31715
- return unitOutOfRange("weekYear", obj.weekYear);
31716
- } else if (!validWeek) {
31717
- return unitOutOfRange("week", obj.week);
31718
- } else if (!validWeekday) {
31719
- return unitOutOfRange("weekday", obj.weekday);
31720
- } else return false;
31721
- }
31722
- function hasInvalidOrdinalData(obj) {
31723
- const validYear = isInteger(obj.year),
31724
- validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
31725
- if (!validYear) {
31726
- return unitOutOfRange("year", obj.year);
31727
- } else if (!validOrdinal) {
31728
- return unitOutOfRange("ordinal", obj.ordinal);
31729
- } else return false;
31730
- }
31731
- function hasInvalidGregorianData(obj) {
31732
- const validYear = isInteger(obj.year),
31733
- validMonth = integerBetween(obj.month, 1, 12),
31734
- validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
31735
- if (!validYear) {
31736
- return unitOutOfRange("year", obj.year);
31737
- } else if (!validMonth) {
31738
- return unitOutOfRange("month", obj.month);
31739
- } else if (!validDay) {
31740
- return unitOutOfRange("day", obj.day);
31741
- } else return false;
31742
- }
31743
- function hasInvalidTimeData(obj) {
31744
- const {
31745
- hour,
31746
- minute,
31747
- second,
31748
- millisecond
31749
- } = obj;
31750
- const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
31751
- validMinute = integerBetween(minute, 0, 59),
31752
- validSecond = integerBetween(second, 0, 59),
31753
- validMillisecond = integerBetween(millisecond, 0, 999);
31754
- if (!validHour) {
31755
- return unitOutOfRange("hour", hour);
31756
- } else if (!validMinute) {
31757
- return unitOutOfRange("minute", minute);
31758
- } else if (!validSecond) {
31759
- return unitOutOfRange("second", second);
31760
- } else if (!validMillisecond) {
31761
- return unitOutOfRange("millisecond", millisecond);
31762
- } else return false;
31763
- }
31764
-
31765
31981
  const INVALID = "Invalid DateTime";
31766
31982
  const MAX_DATE = 8.64e15;
31767
31983
  function unsupportedZone(zone) {
@@ -31769,6 +31985,9 @@ function unsupportedZone(zone) {
31769
31985
  }
31770
31986
 
31771
31987
  // we cache week data on the DT object and this intermediates the cache
31988
+ /**
31989
+ * @param {DateTime} dt
31990
+ */
31772
31991
  function possiblyCachedWeekData(dt) {
31773
31992
  if (dt.weekData === null) {
31774
31993
  dt.weekData = gregorianToWeek(dt.c);
@@ -31776,6 +31995,16 @@ function possiblyCachedWeekData(dt) {
31776
31995
  return dt.weekData;
31777
31996
  }
31778
31997
 
31998
+ /**
31999
+ * @param {DateTime} dt
32000
+ */
32001
+ function possiblyCachedLocalWeekData(dt) {
32002
+ if (dt.localWeekData === null) {
32003
+ dt.localWeekData = gregorianToWeek(dt.c, dt.loc.getMinDaysInFirstWeek(), dt.loc.getStartOfWeek());
32004
+ }
32005
+ return dt.localWeekData;
32006
+ }
32007
+
31779
32008
  // clone really means, "make a new object with these modifications". all "setters" really use this
31780
32009
  // to create a new object while only changing some of the properties
31781
32010
  function clone(inst, alts) {
@@ -32020,6 +32249,21 @@ function normalizeUnit(unit) {
32020
32249
  if (!normalized) throw new InvalidUnitError(unit);
32021
32250
  return normalized;
32022
32251
  }
32252
+ function normalizeUnitWithLocalWeeks(unit) {
32253
+ switch (unit.toLowerCase()) {
32254
+ case "localweekday":
32255
+ case "localweekdays":
32256
+ return "localWeekday";
32257
+ case "localweeknumber":
32258
+ case "localweeknumbers":
32259
+ return "localWeekNumber";
32260
+ case "localweekyear":
32261
+ case "localweekyears":
32262
+ return "localWeekYear";
32263
+ default:
32264
+ return normalizeUnit(unit);
32265
+ }
32266
+ }
32023
32267
 
32024
32268
  // this is a dumbed down version of fromObject() that runs about 60% faster
32025
32269
  // but doesn't do any validation, makes a bunch of assumptions about what units
@@ -32154,6 +32398,10 @@ class DateTime {
32154
32398
  * @access private
32155
32399
  */
32156
32400
  this.weekData = null;
32401
+ /**
32402
+ * @access private
32403
+ */
32404
+ this.localWeekData = null;
32157
32405
  /**
32158
32406
  * @access private
32159
32407
  */
@@ -32335,13 +32583,16 @@ class DateTime {
32335
32583
  * @param {number} obj.weekYear - an ISO week year
32336
32584
  * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
32337
32585
  * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
32586
+ * @param {number} obj.localWeekYear - a week year, according to the locale
32587
+ * @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
32588
+ * @param {number} obj.localWeekday - a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale
32338
32589
  * @param {number} obj.hour - hour of the day, 0-23
32339
32590
  * @param {number} obj.minute - minute of the hour, 0-59
32340
32591
  * @param {number} obj.second - second of the minute, 0-59
32341
32592
  * @param {number} obj.millisecond - millisecond of the second, 0-999
32342
32593
  * @param {Object} opts - options for creating this DateTime
32343
32594
  * @param {string|Zone} [opts.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
32344
- * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
32595
+ * @param {string} [opts.locale='system\'s locale'] - a locale to set on the resulting DateTime instance
32345
32596
  * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
32346
32597
  * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
32347
32598
  * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
@@ -32351,6 +32602,7 @@ class DateTime {
32351
32602
  * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
32352
32603
  * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
32353
32604
  * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
32605
+ * @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
32354
32606
  * @return {DateTime}
32355
32607
  */
32356
32608
  static fromObject(obj, opts = {}) {
@@ -32359,15 +32611,19 @@ class DateTime {
32359
32611
  if (!zoneToUse.isValid) {
32360
32612
  return DateTime.invalid(unsupportedZone(zoneToUse));
32361
32613
  }
32614
+ const loc = Locale.fromObject(opts);
32615
+ const normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
32616
+ const {
32617
+ minDaysInFirstWeek,
32618
+ startOfWeek
32619
+ } = usesLocalWeekValues(normalized, loc);
32362
32620
  const tsNow = Settings.now(),
32363
32621
  offsetProvis = !isUndefined(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow),
32364
- normalized = normalizeObject(obj, normalizeUnit),
32365
32622
  containsOrdinal = !isUndefined(normalized.ordinal),
32366
32623
  containsGregorYear = !isUndefined(normalized.year),
32367
32624
  containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
32368
32625
  containsGregor = containsGregorYear || containsGregorMD,
32369
- definiteWeekDef = normalized.weekYear || normalized.weekNumber,
32370
- loc = Locale.fromObject(opts);
32626
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
32371
32627
 
32372
32628
  // cases:
32373
32629
  // just a weekday -> this week's instance of that weekday, no worries
@@ -32390,7 +32646,7 @@ class DateTime {
32390
32646
  if (useWeekData) {
32391
32647
  units = orderedWeekUnits;
32392
32648
  defaultValues = defaultWeekUnitValues;
32393
- objNow = gregorianToWeek(objNow);
32649
+ objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
32394
32650
  } else if (containsOrdinal) {
32395
32651
  units = orderedOrdinalUnits;
32396
32652
  defaultValues = defaultOrdinalUnitValues;
@@ -32414,14 +32670,14 @@ class DateTime {
32414
32670
  }
32415
32671
 
32416
32672
  // make sure the values we have are in range
32417
- const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
32673
+ const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
32418
32674
  invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
32419
32675
  if (invalid) {
32420
32676
  return DateTime.invalid(invalid);
32421
32677
  }
32422
32678
 
32423
32679
  // compute the actual time
32424
- const gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
32680
+ const gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
32425
32681
  [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
32426
32682
  inst = new DateTime({
32427
32683
  ts: tsFinal,
@@ -32800,6 +33056,43 @@ class DateTime {
32800
33056
  return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
32801
33057
  }
32802
33058
 
33059
+ /**
33060
+ * Returns true if this date is on a weekend according to the locale, false otherwise
33061
+ * @returns {boolean}
33062
+ */
33063
+ get isWeekend() {
33064
+ return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
33065
+ }
33066
+
33067
+ /**
33068
+ * Get the day of the week according to the locale.
33069
+ * 1 is the first day of the week and 7 is the last day of the week.
33070
+ * If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
33071
+ * @returns {number}
33072
+ */
33073
+ get localWeekday() {
33074
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
33075
+ }
33076
+
33077
+ /**
33078
+ * Get the week number of the week year according to the locale. Different locales assign week numbers differently,
33079
+ * because the week can start on different days of the week (see localWeekday) and because a different number of days
33080
+ * is required for a week to count as the first week of a year.
33081
+ * @returns {number}
33082
+ */
33083
+ get localWeekNumber() {
33084
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
33085
+ }
33086
+
33087
+ /**
33088
+ * Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
33089
+ * differently, see localWeekNumber.
33090
+ * @returns {number}
33091
+ */
33092
+ get localWeekYear() {
33093
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : NaN;
33094
+ }
33095
+
32803
33096
  /**
32804
33097
  * Get the ordinal (meaning the day of the year)
32805
33098
  * @example DateTime.local(2017, 5, 25).ordinal //=> 145
@@ -33000,6 +33293,16 @@ class DateTime {
33000
33293
  return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
33001
33294
  }
33002
33295
 
33296
+ /**
33297
+ * Returns the number of weeks in this DateTime's local week year
33298
+ * @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
33299
+ * @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
33300
+ * @type {number}
33301
+ */
33302
+ get weeksInLocalWeekYear() {
33303
+ return this.isValid ? weeksInWeekYear(this.localWeekYear, this.loc.getMinDaysInFirstWeek(), this.loc.getStartOfWeek()) : NaN;
33304
+ }
33305
+
33003
33306
  /**
33004
33307
  * Returns the resolved Intl options for this DateTime.
33005
33308
  * This is useful in understanding the behavior of formatting methods
@@ -33111,6 +33414,9 @@ class DateTime {
33111
33414
  /**
33112
33415
  * "Set" the values of specified units. Returns a newly-constructed DateTime.
33113
33416
  * You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}.
33417
+ *
33418
+ * This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
33419
+ * They cannot be mixed with ISO-week units like `weekday`.
33114
33420
  * @param {Object} values - a mapping of units to numbers
33115
33421
  * @example dt.set({ year: 2017 })
33116
33422
  * @example dt.set({ hour: 8, minute: 30 })
@@ -33120,8 +33426,12 @@ class DateTime {
33120
33426
  */
33121
33427
  set(values) {
33122
33428
  if (!this.isValid) return this;
33123
- const normalized = normalizeObject(values, normalizeUnit),
33124
- settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
33429
+ const normalized = normalizeObject(values, normalizeUnitWithLocalWeeks);
33430
+ const {
33431
+ minDaysInFirstWeek,
33432
+ startOfWeek
33433
+ } = usesLocalWeekValues(normalized, this.loc);
33434
+ const settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
33125
33435
  containsOrdinal = !isUndefined(normalized.ordinal),
33126
33436
  containsGregorYear = !isUndefined(normalized.year),
33127
33437
  containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
@@ -33136,9 +33446,9 @@ class DateTime {
33136
33446
  let mixed;
33137
33447
  if (settingWeekStuff) {
33138
33448
  mixed = weekToGregorian({
33139
- ...gregorianToWeek(this.c),
33449
+ ...gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek),
33140
33450
  ...normalized
33141
- });
33451
+ }, minDaysInFirstWeek, startOfWeek);
33142
33452
  } else if (!isUndefined(normalized.ordinal)) {
33143
33453
  mixed = ordinalToGregorian({
33144
33454
  ...gregorianToOrdinal(this.c),
@@ -33197,6 +33507,8 @@ class DateTime {
33197
33507
  /**
33198
33508
  * "Set" this DateTime to the beginning of a unit of time.
33199
33509
  * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
33510
+ * @param {Object} opts - options
33511
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
33200
33512
  * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
33201
33513
  * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
33202
33514
  * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
@@ -33204,7 +33516,9 @@ class DateTime {
33204
33516
  * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
33205
33517
  * @return {DateTime}
33206
33518
  */
33207
- startOf(unit) {
33519
+ startOf(unit, {
33520
+ useLocaleWeeks = false
33521
+ } = {}) {
33208
33522
  if (!this.isValid) return this;
33209
33523
  const o = {},
33210
33524
  normalizedUnit = Duration.normalizeUnit(unit);
@@ -33233,7 +33547,18 @@ class DateTime {
33233
33547
  }
33234
33548
 
33235
33549
  if (normalizedUnit === "weeks") {
33236
- o.weekday = 1;
33550
+ if (useLocaleWeeks) {
33551
+ const startOfWeek = this.loc.getStartOfWeek();
33552
+ const {
33553
+ weekday
33554
+ } = this;
33555
+ if (weekday < startOfWeek) {
33556
+ o.weekNumber = this.weekNumber - 1;
33557
+ }
33558
+ o.weekday = startOfWeek;
33559
+ } else {
33560
+ o.weekday = 1;
33561
+ }
33237
33562
  }
33238
33563
  if (normalizedUnit === "quarters") {
33239
33564
  const q = Math.ceil(this.month / 3);
@@ -33245,6 +33570,8 @@ class DateTime {
33245
33570
  /**
33246
33571
  * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
33247
33572
  * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
33573
+ * @param {Object} opts - options
33574
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
33248
33575
  * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
33249
33576
  * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
33250
33577
  * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
@@ -33252,10 +33579,10 @@ class DateTime {
33252
33579
  * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
33253
33580
  * @return {DateTime}
33254
33581
  */
33255
- endOf(unit) {
33582
+ endOf(unit, opts) {
33256
33583
  return this.isValid ? this.plus({
33257
33584
  [unit]: 1
33258
- }).startOf(unit).minus(1) : this;
33585
+ }).startOf(unit, opts).minus(1) : this;
33259
33586
  }
33260
33587
 
33261
33588
  // OUTPUT
@@ -33495,6 +33822,18 @@ class DateTime {
33495
33822
  return this.isValid ? this.toISO() : INVALID;
33496
33823
  }
33497
33824
 
33825
+ /**
33826
+ * Returns a string representation of this DateTime appropriate for the REPL.
33827
+ * @return {string}
33828
+ */
33829
+ [Symbol.for("nodejs.util.inspect.custom")]() {
33830
+ if (this.isValid) {
33831
+ return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`;
33832
+ } else {
33833
+ return `DateTime { Invalid, reason: ${this.invalidReason} }`;
33834
+ }
33835
+ }
33836
+
33498
33837
  /**
33499
33838
  * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
33500
33839
  * @return {number}
@@ -33632,16 +33971,18 @@ class DateTime {
33632
33971
  * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link DateTime#setZone} to convert one of the dates if needed.
33633
33972
  * @param {DateTime} otherDateTime - the other DateTime
33634
33973
  * @param {string} unit - the unit of time to check sameness on
33974
+ * @param {Object} opts - options
33975
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; only the locale of this DateTime is used
33635
33976
  * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
33636
33977
  * @return {boolean}
33637
33978
  */
33638
- hasSame(otherDateTime, unit) {
33979
+ hasSame(otherDateTime, unit, opts) {
33639
33980
  if (!this.isValid) return false;
33640
33981
  const inputMs = otherDateTime.valueOf();
33641
33982
  const adjustedToZone = this.setZone(otherDateTime.zone, {
33642
33983
  keepLocalTime: true
33643
33984
  });
33644
- return adjustedToZone.startOf(unit) <= inputMs && inputMs <= adjustedToZone.endOf(unit);
33985
+ return adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts);
33645
33986
  }
33646
33987
 
33647
33988
  /**
@@ -33965,7 +34306,7 @@ function friendlyDateTime(dateTimeish) {
33965
34306
  }
33966
34307
  }
33967
34308
 
33968
- const VERSION = "3.4.3";
34309
+ const VERSION = "3.4.4";
33969
34310
 
33970
34311
  exports.DateTime = DateTime;
33971
34312
  exports.Duration = Duration;