@nmshd/runtime 2.9.0 → 2.10.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.
@@ -555,11 +555,11 @@ const content_1 = __webpack_require__(/*! @nmshd/content */ "@nmshd/content");
555
555
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
556
556
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
557
557
  exports.buildInformation = {
558
- version: "2.9.0",
559
- build: "173",
560
- date: "2023-10-31T12:24:51+00:00",
561
- commit: "015233cc97f24e4f5769718b4bb2b8d89548e0a6",
562
- dependencies: {"@js-soft/docdb-querytranslator":"1.1.1","@js-soft/logging-abstractions":"1.0.0","@js-soft/ts-serval":"2.0.9","@js-soft/ts-utils":"^2.3.1","@nmshd/consumption":"3.4.3","@nmshd/content":"2.7.4","@nmshd/crypto":"2.0.4","@nmshd/transport":"2.1.2","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.3","qrcode":"1.5.3","reflect-metadata":"0.1.13","ts-simple-nameof":"1.3.1","typescript-ioc":"3.2.2"},
558
+ version: "2.10.0",
559
+ build: "175",
560
+ date: "2023-11-20T15:34:30+00:00",
561
+ commit: "b24d6bb0b3751226ba30efc81dad0e9adab6e97f",
562
+ dependencies: {"@js-soft/docdb-querytranslator":"1.1.2","@js-soft/logging-abstractions":"1.0.1","@js-soft/ts-serval":"2.0.10","@js-soft/ts-utils":"^2.3.3","@nmshd/consumption":"3.4.3","@nmshd/content":"2.7.4","@nmshd/crypto":"2.0.5","@nmshd/transport":"2.1.4","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.4","qrcode":"1.5.3","reflect-metadata":"0.1.13","ts-simple-nameof":"1.3.1","typescript-ioc":"3.2.2"},
563
563
  libraries: {
564
564
  serval: ts_serval_1.buildInformation,
565
565
  consumption: consumption_1.buildInformation,
@@ -1087,6 +1087,26 @@ let DataViewExpander = class DataViewExpander {
1087
1087
  isDecidable,
1088
1088
  response: responseItemDVO
1089
1089
  };
1090
+ case "FreeTextRequestItem":
1091
+ const freeTextRequestItem = requestItem;
1092
+ if (isDecidable) {
1093
+ return {
1094
+ ...freeTextRequestItem,
1095
+ type: "DecidableFreeTextRequestItemDVO",
1096
+ id: "",
1097
+ name: requestItem.title ? requestItem.title : "i18n://dvo.requestItem.DecidableFreeTextRequestItem.name",
1098
+ isDecidable,
1099
+ response: responseItemDVO
1100
+ };
1101
+ }
1102
+ return {
1103
+ ...freeTextRequestItem,
1104
+ type: "FreeTextRequestItemDVO",
1105
+ id: "",
1106
+ name: requestItem.title ? requestItem.title : "i18n://dvo.requestItem.FreeTextRequestItem.name",
1107
+ isDecidable,
1108
+ response: responseItemDVO
1109
+ };
1090
1110
  case "RegisterAttributeListenerRequestItem":
1091
1111
  const registerAttributeListenerRequestItem = requestItem;
1092
1112
  const queryDVO = (await this.expandAttributeQuery(registerAttributeListenerRequestItem.query));
@@ -6331,7 +6351,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
6331
6351
  };
6332
6352
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6333
6353
  exports.QRCode = void 0;
6334
- const QRCodeLibrary = __importStar(__webpack_require__(/*! qrcode */ "./node_modules/qrcode/lib/browser.js"));
6354
+ const qrcodeLibrary = __importStar(__webpack_require__(/*! qrcode */ "./node_modules/qrcode/lib/browser.js"));
6335
6355
  class QRCode {
6336
6356
  constructor(base64) {
6337
6357
  this.base64 = base64;
@@ -6340,7 +6360,7 @@ class QRCode {
6340
6360
  return this.base64;
6341
6361
  }
6342
6362
  static async from(content, prefix) {
6343
- const dataUrl = await QRCodeLibrary.toDataURL(`nmshd://${prefix}#${content}`);
6363
+ const dataUrl = await qrcodeLibrary.toDataURL(`nmshd://${prefix}#${content}`);
6344
6364
  const base64 = dataUrl.split(",")[1];
6345
6365
  return new QRCode(base64);
6346
6366
  }
@@ -30071,6 +30091,13 @@ exports.RegisterPushNotificationTokenRequest = {
30071
30091
  },
30072
30092
  "appId": {
30073
30093
  "type": "string"
30094
+ },
30095
+ "environment": {
30096
+ "type": "string",
30097
+ "enum": [
30098
+ "Development",
30099
+ "Production"
30100
+ ]
30074
30101
  }
30075
30102
  },
30076
30103
  "required": [
@@ -36397,7 +36424,8 @@ let RegisterPushNotificationTokenUseCase = class RegisterPushNotificationTokenUs
36397
36424
  await this.accountController.registerPushNotificationToken({
36398
36425
  handle: request.handle,
36399
36426
  platform: request.platform,
36400
- appId: request.appId
36427
+ appId: request.appId,
36428
+ environment: request.environment
36401
36429
  });
36402
36430
  return ts_utils_1.Result.ok(undefined);
36403
36431
  }
@@ -71274,6 +71302,17 @@ function systemLocale() {
71274
71302
  return sysLocaleCache;
71275
71303
  }
71276
71304
  }
71305
+ let weekInfoCache = {};
71306
+ function getCachedWeekInfo(locString) {
71307
+ let data = weekInfoCache[locString];
71308
+ if (!data) {
71309
+ const locale = new Intl.Locale(locString);
71310
+ // browsers currently implement this as a property, but spec says it should be a getter function
71311
+ data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
71312
+ weekInfoCache[locString] = data;
71313
+ }
71314
+ return data;
71315
+ }
71277
71316
  function parseLocaleString(localeStr) {
71278
71317
  // I really want to avoid writing a BCP 47 parser
71279
71318
  // see, e.g. https://github.com/wooorm/bcp-47
@@ -71511,6 +71550,11 @@ class PolyRelFormatter {
71511
71550
  }
71512
71551
  }
71513
71552
  }
71553
+ const fallbackWeekSettings = {
71554
+ firstDay: 1,
71555
+ minimalDays: 4,
71556
+ weekend: [6, 7]
71557
+ };
71514
71558
 
71515
71559
  /**
71516
71560
  * @private
@@ -71518,15 +71562,16 @@ class PolyRelFormatter {
71518
71562
 
71519
71563
  class Locale {
71520
71564
  static fromOpts(opts) {
71521
- return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN);
71565
+ return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.weekSettings, opts.defaultToEN);
71522
71566
  }
71523
- static create(locale, numberingSystem, outputCalendar, defaultToEN = false) {
71567
+ static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
71524
71568
  const specifiedLocale = locale || Settings.defaultLocale;
71525
71569
  // the system locale is useful for human readable strings but annoying for parsing/formatting known formats
71526
71570
  const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
71527
71571
  const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
71528
71572
  const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
71529
- return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale);
71573
+ const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
71574
+ return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
71530
71575
  }
71531
71576
  static resetCache() {
71532
71577
  sysLocaleCache = null;
@@ -71537,15 +71582,17 @@ class Locale {
71537
71582
  static fromObject({
71538
71583
  locale,
71539
71584
  numberingSystem,
71540
- outputCalendar
71585
+ outputCalendar,
71586
+ weekSettings
71541
71587
  } = {}) {
71542
- return Locale.create(locale, numberingSystem, outputCalendar);
71588
+ return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
71543
71589
  }
71544
- constructor(locale, numbering, outputCalendar, specifiedLocale) {
71590
+ constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
71545
71591
  const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
71546
71592
  this.locale = parsedLocale;
71547
71593
  this.numberingSystem = numbering || parsedNumberingSystem || null;
71548
71594
  this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
71595
+ this.weekSettings = weekSettings;
71549
71596
  this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
71550
71597
  this.weekdaysCache = {
71551
71598
  format: {},
@@ -71575,7 +71622,7 @@ class Locale {
71575
71622
  if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
71576
71623
  return this;
71577
71624
  } else {
71578
- return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false);
71625
+ return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, validateWeekSettings(alts.weekSettings) || this.weekSettings, alts.defaultToEN || false);
71579
71626
  }
71580
71627
  }
71581
71628
  redefaultToEN(alts = {}) {
@@ -71673,6 +71720,24 @@ class Locale {
71673
71720
  isEnglish() {
71674
71721
  return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
71675
71722
  }
71723
+ getWeekSettings() {
71724
+ if (this.weekSettings) {
71725
+ return this.weekSettings;
71726
+ } else if (!hasLocaleWeekInfo()) {
71727
+ return fallbackWeekSettings;
71728
+ } else {
71729
+ return getCachedWeekInfo(this.locale);
71730
+ }
71731
+ }
71732
+ getStartOfWeek() {
71733
+ return this.getWeekSettings().firstDay;
71734
+ }
71735
+ getMinDaysInFirstWeek() {
71736
+ return this.getWeekSettings().minimalDays;
71737
+ }
71738
+ getWeekendDays() {
71739
+ return this.getWeekSettings().weekend;
71740
+ }
71676
71741
  equals(other) {
71677
71742
  return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
71678
71743
  }
@@ -71856,7 +71921,8 @@ let now = () => Date.now(),
71856
71921
  defaultNumberingSystem = null,
71857
71922
  defaultOutputCalendar = null,
71858
71923
  twoDigitCutoffYear = 60,
71859
- throwOnInvalid;
71924
+ throwOnInvalid,
71925
+ defaultWeekSettings = null;
71860
71926
 
71861
71927
  /**
71862
71928
  * 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.
@@ -71947,6 +72013,31 @@ class Settings {
71947
72013
  defaultOutputCalendar = outputCalendar;
71948
72014
  }
71949
72015
 
72016
+ /**
72017
+ * @typedef {Object} WeekSettings
72018
+ * @property {number} firstDay
72019
+ * @property {number} minimalDays
72020
+ * @property {number[]} weekend
72021
+ */
72022
+
72023
+ /**
72024
+ * @return {WeekSettings|null}
72025
+ */
72026
+ static get defaultWeekSettings() {
72027
+ return defaultWeekSettings;
72028
+ }
72029
+
72030
+ /**
72031
+ * Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
72032
+ * how many days are required in the first week of a year.
72033
+ * Does not affect existing instances.
72034
+ *
72035
+ * @param {WeekSettings|null} weekSettings
72036
+ */
72037
+ static set defaultWeekSettings(weekSettings) {
72038
+ defaultWeekSettings = validateWeekSettings(weekSettings);
72039
+ }
72040
+
71950
72041
  /**
71951
72042
  * Get the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
71952
72043
  * @type {number}
@@ -71993,6 +72084,224 @@ class Settings {
71993
72084
  }
71994
72085
  }
71995
72086
 
72087
+ class Invalid {
72088
+ constructor(reason, explanation) {
72089
+ this.reason = reason;
72090
+ this.explanation = explanation;
72091
+ }
72092
+ toMessage() {
72093
+ if (this.explanation) {
72094
+ return `${this.reason}: ${this.explanation}`;
72095
+ } else {
72096
+ return this.reason;
72097
+ }
72098
+ }
72099
+ }
72100
+
72101
+ const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
72102
+ leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
72103
+ function unitOutOfRange(unit, value) {
72104
+ return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
72105
+ }
72106
+ function dayOfWeek(year, month, day) {
72107
+ const d = new Date(Date.UTC(year, month - 1, day));
72108
+ if (year < 100 && year >= 0) {
72109
+ d.setUTCFullYear(d.getUTCFullYear() - 1900);
72110
+ }
72111
+ const js = d.getUTCDay();
72112
+ return js === 0 ? 7 : js;
72113
+ }
72114
+ function computeOrdinal(year, month, day) {
72115
+ return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
72116
+ }
72117
+ function uncomputeOrdinal(year, ordinal) {
72118
+ const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
72119
+ month0 = table.findIndex(i => i < ordinal),
72120
+ day = ordinal - table[month0];
72121
+ return {
72122
+ month: month0 + 1,
72123
+ day
72124
+ };
72125
+ }
72126
+ function isoWeekdayToLocal(isoWeekday, startOfWeek) {
72127
+ return (isoWeekday - startOfWeek + 7) % 7 + 1;
72128
+ }
72129
+
72130
+ /**
72131
+ * @private
72132
+ */
72133
+
72134
+ function gregorianToWeek(gregObj, minDaysInFirstWeek = 4, startOfWeek = 1) {
72135
+ const {
72136
+ year,
72137
+ month,
72138
+ day
72139
+ } = gregObj,
72140
+ ordinal = computeOrdinal(year, month, day),
72141
+ weekday = isoWeekdayToLocal(dayOfWeek(year, month, day), startOfWeek);
72142
+ let weekNumber = Math.floor((ordinal - weekday + 14 - minDaysInFirstWeek) / 7),
72143
+ weekYear;
72144
+ if (weekNumber < 1) {
72145
+ weekYear = year - 1;
72146
+ weekNumber = weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek);
72147
+ } else if (weekNumber > weeksInWeekYear(year, minDaysInFirstWeek, startOfWeek)) {
72148
+ weekYear = year + 1;
72149
+ weekNumber = 1;
72150
+ } else {
72151
+ weekYear = year;
72152
+ }
72153
+ return {
72154
+ weekYear,
72155
+ weekNumber,
72156
+ weekday,
72157
+ ...timeObject(gregObj)
72158
+ };
72159
+ }
72160
+ function weekToGregorian(weekData, minDaysInFirstWeek = 4, startOfWeek = 1) {
72161
+ const {
72162
+ weekYear,
72163
+ weekNumber,
72164
+ weekday
72165
+ } = weekData,
72166
+ weekdayOfJan4 = isoWeekdayToLocal(dayOfWeek(weekYear, 1, minDaysInFirstWeek), startOfWeek),
72167
+ yearInDays = daysInYear(weekYear);
72168
+ let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 7 + minDaysInFirstWeek,
72169
+ year;
72170
+ if (ordinal < 1) {
72171
+ year = weekYear - 1;
72172
+ ordinal += daysInYear(year);
72173
+ } else if (ordinal > yearInDays) {
72174
+ year = weekYear + 1;
72175
+ ordinal -= daysInYear(weekYear);
72176
+ } else {
72177
+ year = weekYear;
72178
+ }
72179
+ const {
72180
+ month,
72181
+ day
72182
+ } = uncomputeOrdinal(year, ordinal);
72183
+ return {
72184
+ year,
72185
+ month,
72186
+ day,
72187
+ ...timeObject(weekData)
72188
+ };
72189
+ }
72190
+ function gregorianToOrdinal(gregData) {
72191
+ const {
72192
+ year,
72193
+ month,
72194
+ day
72195
+ } = gregData;
72196
+ const ordinal = computeOrdinal(year, month, day);
72197
+ return {
72198
+ year,
72199
+ ordinal,
72200
+ ...timeObject(gregData)
72201
+ };
72202
+ }
72203
+ function ordinalToGregorian(ordinalData) {
72204
+ const {
72205
+ year,
72206
+ ordinal
72207
+ } = ordinalData;
72208
+ const {
72209
+ month,
72210
+ day
72211
+ } = uncomputeOrdinal(year, ordinal);
72212
+ return {
72213
+ year,
72214
+ month,
72215
+ day,
72216
+ ...timeObject(ordinalData)
72217
+ };
72218
+ }
72219
+
72220
+ /**
72221
+ * Check if local week units like localWeekday are used in obj.
72222
+ * If so, validates that they are not mixed with ISO week units and then copies them to the normal week unit properties.
72223
+ * Modifies obj in-place!
72224
+ * @param obj the object values
72225
+ */
72226
+ function usesLocalWeekValues(obj, loc) {
72227
+ const hasLocaleWeekData = !isUndefined(obj.localWeekday) || !isUndefined(obj.localWeekNumber) || !isUndefined(obj.localWeekYear);
72228
+ if (hasLocaleWeekData) {
72229
+ const hasIsoWeekData = !isUndefined(obj.weekday) || !isUndefined(obj.weekNumber) || !isUndefined(obj.weekYear);
72230
+ if (hasIsoWeekData) {
72231
+ throw new ConflictingSpecificationError("Cannot mix locale-based week fields with ISO-based week fields");
72232
+ }
72233
+ if (!isUndefined(obj.localWeekday)) obj.weekday = obj.localWeekday;
72234
+ if (!isUndefined(obj.localWeekNumber)) obj.weekNumber = obj.localWeekNumber;
72235
+ if (!isUndefined(obj.localWeekYear)) obj.weekYear = obj.localWeekYear;
72236
+ delete obj.localWeekday;
72237
+ delete obj.localWeekNumber;
72238
+ delete obj.localWeekYear;
72239
+ return {
72240
+ minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
72241
+ startOfWeek: loc.getStartOfWeek()
72242
+ };
72243
+ } else {
72244
+ return {
72245
+ minDaysInFirstWeek: 4,
72246
+ startOfWeek: 1
72247
+ };
72248
+ }
72249
+ }
72250
+ function hasInvalidWeekData(obj, minDaysInFirstWeek = 4, startOfWeek = 1) {
72251
+ const validYear = isInteger(obj.weekYear),
72252
+ validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear, minDaysInFirstWeek, startOfWeek)),
72253
+ validWeekday = integerBetween(obj.weekday, 1, 7);
72254
+ if (!validYear) {
72255
+ return unitOutOfRange("weekYear", obj.weekYear);
72256
+ } else if (!validWeek) {
72257
+ return unitOutOfRange("week", obj.weekNumber);
72258
+ } else if (!validWeekday) {
72259
+ return unitOutOfRange("weekday", obj.weekday);
72260
+ } else return false;
72261
+ }
72262
+ function hasInvalidOrdinalData(obj) {
72263
+ const validYear = isInteger(obj.year),
72264
+ validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
72265
+ if (!validYear) {
72266
+ return unitOutOfRange("year", obj.year);
72267
+ } else if (!validOrdinal) {
72268
+ return unitOutOfRange("ordinal", obj.ordinal);
72269
+ } else return false;
72270
+ }
72271
+ function hasInvalidGregorianData(obj) {
72272
+ const validYear = isInteger(obj.year),
72273
+ validMonth = integerBetween(obj.month, 1, 12),
72274
+ validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
72275
+ if (!validYear) {
72276
+ return unitOutOfRange("year", obj.year);
72277
+ } else if (!validMonth) {
72278
+ return unitOutOfRange("month", obj.month);
72279
+ } else if (!validDay) {
72280
+ return unitOutOfRange("day", obj.day);
72281
+ } else return false;
72282
+ }
72283
+ function hasInvalidTimeData(obj) {
72284
+ const {
72285
+ hour,
72286
+ minute,
72287
+ second,
72288
+ millisecond
72289
+ } = obj;
72290
+ const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
72291
+ validMinute = integerBetween(minute, 0, 59),
72292
+ validSecond = integerBetween(second, 0, 59),
72293
+ validMillisecond = integerBetween(millisecond, 0, 999);
72294
+ if (!validHour) {
72295
+ return unitOutOfRange("hour", hour);
72296
+ } else if (!validMinute) {
72297
+ return unitOutOfRange("minute", minute);
72298
+ } else if (!validSecond) {
72299
+ return unitOutOfRange("second", second);
72300
+ } else if (!validMillisecond) {
72301
+ return unitOutOfRange("millisecond", millisecond);
72302
+ } else return false;
72303
+ }
72304
+
71996
72305
  /*
71997
72306
  This is just a junk drawer, containing anything used across multiple classes.
71998
72307
  Because Luxon is small(ish), this should stay small and we won't worry about splitting
@@ -72030,6 +72339,13 @@ function hasRelative() {
72030
72339
  return false;
72031
72340
  }
72032
72341
  }
72342
+ function hasLocaleWeekInfo() {
72343
+ try {
72344
+ return typeof Intl !== "undefined" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
72345
+ } catch (e) {
72346
+ return false;
72347
+ }
72348
+ }
72033
72349
 
72034
72350
  // OBJECTS AND ARRAYS
72035
72351
 
@@ -72060,6 +72376,22 @@ function pick(obj, keys) {
72060
72376
  function hasOwnProperty(obj, prop) {
72061
72377
  return Object.prototype.hasOwnProperty.call(obj, prop);
72062
72378
  }
72379
+ function validateWeekSettings(settings) {
72380
+ if (settings == null) {
72381
+ return null;
72382
+ } else if (typeof settings !== "object") {
72383
+ throw new InvalidArgumentError("Week settings must be an object");
72384
+ } else {
72385
+ if (!integerBetween(settings.firstDay, 1, 7) || !integerBetween(settings.minimalDays, 1, 7) || !Array.isArray(settings.weekend) || settings.weekend.some(v => !integerBetween(v, 1, 7))) {
72386
+ throw new InvalidArgumentError("Invalid week settings");
72387
+ }
72388
+ return {
72389
+ firstDay: settings.firstDay,
72390
+ minimalDays: settings.minimalDays,
72391
+ weekend: Array.from(settings.weekend)
72392
+ };
72393
+ }
72394
+ }
72063
72395
 
72064
72396
  // NUMBERS AND STRINGS
72065
72397
 
@@ -72142,11 +72474,16 @@ function objToLocalTS(obj) {
72142
72474
  }
72143
72475
  return +d;
72144
72476
  }
72145
- function weeksInWeekYear(weekYear) {
72146
- const p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7,
72147
- last = weekYear - 1,
72148
- p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7;
72149
- return p1 === 4 || p2 === 3 ? 53 : 52;
72477
+
72478
+ // adapted from moment.js: https://github.com/moment/moment/blob/000ac1800e620f770f4eb31b5ae908f6167b0ab2/src/lib/units/week-calendar-utils.js
72479
+ function firstWeekOffset(year, minDaysInFirstWeek, startOfWeek) {
72480
+ const fwdlw = isoWeekdayToLocal(dayOfWeek(year, 1, minDaysInFirstWeek), startOfWeek);
72481
+ return -fwdlw + minDaysInFirstWeek - 1;
72482
+ }
72483
+ function weeksInWeekYear(weekYear, minDaysInFirstWeek = 4, startOfWeek = 1) {
72484
+ const weekOffset = firstWeekOffset(weekYear, minDaysInFirstWeek, startOfWeek);
72485
+ const weekOffsetNext = firstWeekOffset(weekYear + 1, minDaysInFirstWeek, startOfWeek);
72486
+ return (daysInYear(weekYear) - weekOffset + weekOffsetNext) / 7;
72150
72487
  }
72151
72488
  function untruncateYear(year) {
72152
72489
  if (year > 99) {
@@ -72687,6 +73024,14 @@ class Formatter {
72687
73024
  return this.num(dt.weekNumber);
72688
73025
  case "WW":
72689
73026
  return this.num(dt.weekNumber, 2);
73027
+ case "n":
73028
+ return this.num(dt.localWeekNumber);
73029
+ case "nn":
73030
+ return this.num(dt.localWeekNumber, 2);
73031
+ case "ii":
73032
+ return this.num(dt.localWeekYear.toString().slice(-2), 2);
73033
+ case "iiii":
73034
+ return this.num(dt.localWeekYear, 4);
72690
73035
  case "o":
72691
73036
  return this.num(dt.ordinal);
72692
73037
  case "ooo":
@@ -72748,20 +73093,6 @@ class Formatter {
72748
73093
  }
72749
73094
  }
72750
73095
 
72751
- class Invalid {
72752
- constructor(reason, explanation) {
72753
- this.reason = reason;
72754
- this.explanation = explanation;
72755
- }
72756
- toMessage() {
72757
- if (this.explanation) {
72758
- return `${this.reason}: ${this.explanation}`;
72759
- } else {
72760
- return this.reason;
72761
- }
72762
- }
72763
- }
72764
-
72765
73096
  /*
72766
73097
  * This file handles parsing for well-specified formats. Here's how it works:
72767
73098
  * Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match.
@@ -73438,9 +73769,10 @@ class Duration {
73438
73769
 
73439
73770
  /**
73440
73771
  * Returns a string representation of a Duration with all units included.
73441
- * To modify its behavior use the `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
73442
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
73443
- * @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`.
73772
+ * To modify its behavior, use `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
73773
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
73774
+ * @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
73775
+ * @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.
73444
73776
  * @example
73445
73777
  * ```js
73446
73778
  * var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
@@ -73561,6 +73893,18 @@ class Duration {
73561
73893
  return this.toISO();
73562
73894
  }
73563
73895
 
73896
+ /**
73897
+ * Returns a string representation of this Duration appropriate for the REPL.
73898
+ * @return {string}
73899
+ */
73900
+ [Symbol.for("nodejs.util.inspect.custom")]() {
73901
+ if (this.isValid) {
73902
+ return `Duration { values: ${JSON.stringify(this.values)} }`;
73903
+ } else {
73904
+ return `Duration { Invalid, reason: ${this.invalidReason} }`;
73905
+ }
73906
+ }
73907
+
73564
73908
  /**
73565
73909
  * Returns an milliseconds value of this Duration.
73566
73910
  * @return {number}
@@ -73696,7 +74040,7 @@ class Duration {
73696
74040
  * Assuming the overall value of the Duration is positive, this means:
73697
74041
  * - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
73698
74042
  * - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
73699
- * the overall value would be negative, see second example)
74043
+ * the overall value would be negative, see third example)
73700
74044
  * - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
73701
74045
  *
73702
74046
  * If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
@@ -74154,12 +74498,22 @@ class Interval {
74154
74498
  * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
74155
74499
  * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
74156
74500
  * @param {string} [unit='milliseconds'] - the unit of time to count.
74501
+ * @param {Object} opts - options
74502
+ * @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
74157
74503
  * @return {number}
74158
74504
  */
74159
- count(unit = "milliseconds") {
74505
+ count(unit = "milliseconds", opts) {
74160
74506
  if (!this.isValid) return NaN;
74161
- const start = this.start.startOf(unit),
74162
- end = this.end.startOf(unit);
74507
+ const start = this.start.startOf(unit, opts);
74508
+ let end;
74509
+ if (opts != null && opts.useLocaleWeeks) {
74510
+ end = this.end.reconfigure({
74511
+ locale: start.locale
74512
+ });
74513
+ } else {
74514
+ end = this.end;
74515
+ }
74516
+ end = end.startOf(unit, opts);
74163
74517
  return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
74164
74518
  }
74165
74519
 
@@ -74232,7 +74586,7 @@ class Interval {
74232
74586
  */
74233
74587
  splitAt(...dateTimes) {
74234
74588
  if (!this.isValid) return [];
74235
- const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort(),
74589
+ const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort((a, b) => a.toMillis() - b.toMillis()),
74236
74590
  results = [];
74237
74591
  let {
74238
74592
  s
@@ -74439,6 +74793,18 @@ class Interval {
74439
74793
  return `[${this.s.toISO()} – ${this.e.toISO()})`;
74440
74794
  }
74441
74795
 
74796
+ /**
74797
+ * Returns a string representation of this Interval appropriate for the REPL.
74798
+ * @return {string}
74799
+ */
74800
+ [Symbol.for("nodejs.util.inspect.custom")]() {
74801
+ if (this.isValid) {
74802
+ return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
74803
+ } else {
74804
+ return `Interval { Invalid, reason: ${this.invalidReason} }`;
74805
+ }
74806
+ }
74807
+
74442
74808
  /**
74443
74809
  * Returns a localized string representing this Interval. Accepts the same options as the
74444
74810
  * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
@@ -74589,6 +74955,50 @@ class Info {
74589
74955
  return normalizeZone(input, Settings.defaultZone);
74590
74956
  }
74591
74957
 
74958
+ /**
74959
+ * Get the weekday on which the week starts according to the given locale.
74960
+ * @param {Object} opts - options
74961
+ * @param {string} [opts.locale] - the locale code
74962
+ * @param {string} [opts.locObj=null] - an existing locale object to use
74963
+ * @returns {number} the start of the week, 1 for Monday through 7 for Sunday
74964
+ */
74965
+ static getStartOfWeek({
74966
+ locale = null,
74967
+ locObj = null
74968
+ } = {}) {
74969
+ return (locObj || Locale.create(locale)).getStartOfWeek();
74970
+ }
74971
+
74972
+ /**
74973
+ * Get the minimum number of days necessary in a week before it is considered part of the next year according
74974
+ * to the given locale.
74975
+ * @param {Object} opts - options
74976
+ * @param {string} [opts.locale] - the locale code
74977
+ * @param {string} [opts.locObj=null] - an existing locale object to use
74978
+ * @returns {number}
74979
+ */
74980
+ static getMinimumDaysInFirstWeek({
74981
+ locale = null,
74982
+ locObj = null
74983
+ } = {}) {
74984
+ return (locObj || Locale.create(locale)).getMinDaysInFirstWeek();
74985
+ }
74986
+
74987
+ /**
74988
+ * Get the weekdays, which are considered the weekend according to the given locale
74989
+ * @param {Object} opts - options
74990
+ * @param {string} [opts.locale] - the locale code
74991
+ * @param {string} [opts.locObj=null] - an existing locale object to use
74992
+ * @returns {number[]} an array of weekdays, 1 for Monday through 7 for Sunday
74993
+ */
74994
+ static getWeekendWeekdays({
74995
+ locale = null,
74996
+ locObj = null
74997
+ } = {}) {
74998
+ // copy the array, because we cache it internally
74999
+ return (locObj || Locale.create(locale)).getWeekendDays().slice();
75000
+ }
75001
+
74592
75002
  /**
74593
75003
  * Return an array of standalone month names.
74594
75004
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
@@ -74714,12 +75124,14 @@ class Info {
74714
75124
  * 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.
74715
75125
  * Keys:
74716
75126
  * * `relative`: whether this environment supports relative time formatting
74717
- * @example Info.features() //=> { relative: false }
75127
+ * * `localeWeek`: whether this environment supports different weekdays for the start of the week based on the locale
75128
+ * @example Info.features() //=> { relative: false, localeWeek: true }
74718
75129
  * @return {Object}
74719
75130
  */
74720
75131
  static features() {
74721
75132
  return {
74722
- relative: hasRelative()
75133
+ relative: hasRelative(),
75134
+ localeWeek: hasLocaleWeekInfo()
74723
75135
  };
74724
75136
  }
74725
75137
  }
@@ -75323,176 +75735,6 @@ function formatOptsToTokens(formatOpts, locale) {
75323
75735
  return parts.map(p => tokenForPart(p, formatOpts, resolvedOpts));
75324
75736
  }
75325
75737
 
75326
- const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
75327
- leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
75328
- function unitOutOfRange(unit, value) {
75329
- return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
75330
- }
75331
- function dayOfWeek(year, month, day) {
75332
- const d = new Date(Date.UTC(year, month - 1, day));
75333
- if (year < 100 && year >= 0) {
75334
- d.setUTCFullYear(d.getUTCFullYear() - 1900);
75335
- }
75336
- const js = d.getUTCDay();
75337
- return js === 0 ? 7 : js;
75338
- }
75339
- function computeOrdinal(year, month, day) {
75340
- return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
75341
- }
75342
- function uncomputeOrdinal(year, ordinal) {
75343
- const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
75344
- month0 = table.findIndex(i => i < ordinal),
75345
- day = ordinal - table[month0];
75346
- return {
75347
- month: month0 + 1,
75348
- day
75349
- };
75350
- }
75351
-
75352
- /**
75353
- * @private
75354
- */
75355
-
75356
- function gregorianToWeek(gregObj) {
75357
- const {
75358
- year,
75359
- month,
75360
- day
75361
- } = gregObj,
75362
- ordinal = computeOrdinal(year, month, day),
75363
- weekday = dayOfWeek(year, month, day);
75364
- let weekNumber = Math.floor((ordinal - weekday + 10) / 7),
75365
- weekYear;
75366
- if (weekNumber < 1) {
75367
- weekYear = year - 1;
75368
- weekNumber = weeksInWeekYear(weekYear);
75369
- } else if (weekNumber > weeksInWeekYear(year)) {
75370
- weekYear = year + 1;
75371
- weekNumber = 1;
75372
- } else {
75373
- weekYear = year;
75374
- }
75375
- return {
75376
- weekYear,
75377
- weekNumber,
75378
- weekday,
75379
- ...timeObject(gregObj)
75380
- };
75381
- }
75382
- function weekToGregorian(weekData) {
75383
- const {
75384
- weekYear,
75385
- weekNumber,
75386
- weekday
75387
- } = weekData,
75388
- weekdayOfJan4 = dayOfWeek(weekYear, 1, 4),
75389
- yearInDays = daysInYear(weekYear);
75390
- let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 3,
75391
- year;
75392
- if (ordinal < 1) {
75393
- year = weekYear - 1;
75394
- ordinal += daysInYear(year);
75395
- } else if (ordinal > yearInDays) {
75396
- year = weekYear + 1;
75397
- ordinal -= daysInYear(weekYear);
75398
- } else {
75399
- year = weekYear;
75400
- }
75401
- const {
75402
- month,
75403
- day
75404
- } = uncomputeOrdinal(year, ordinal);
75405
- return {
75406
- year,
75407
- month,
75408
- day,
75409
- ...timeObject(weekData)
75410
- };
75411
- }
75412
- function gregorianToOrdinal(gregData) {
75413
- const {
75414
- year,
75415
- month,
75416
- day
75417
- } = gregData;
75418
- const ordinal = computeOrdinal(year, month, day);
75419
- return {
75420
- year,
75421
- ordinal,
75422
- ...timeObject(gregData)
75423
- };
75424
- }
75425
- function ordinalToGregorian(ordinalData) {
75426
- const {
75427
- year,
75428
- ordinal
75429
- } = ordinalData;
75430
- const {
75431
- month,
75432
- day
75433
- } = uncomputeOrdinal(year, ordinal);
75434
- return {
75435
- year,
75436
- month,
75437
- day,
75438
- ...timeObject(ordinalData)
75439
- };
75440
- }
75441
- function hasInvalidWeekData(obj) {
75442
- const validYear = isInteger(obj.weekYear),
75443
- validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)),
75444
- validWeekday = integerBetween(obj.weekday, 1, 7);
75445
- if (!validYear) {
75446
- return unitOutOfRange("weekYear", obj.weekYear);
75447
- } else if (!validWeek) {
75448
- return unitOutOfRange("week", obj.week);
75449
- } else if (!validWeekday) {
75450
- return unitOutOfRange("weekday", obj.weekday);
75451
- } else return false;
75452
- }
75453
- function hasInvalidOrdinalData(obj) {
75454
- const validYear = isInteger(obj.year),
75455
- validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
75456
- if (!validYear) {
75457
- return unitOutOfRange("year", obj.year);
75458
- } else if (!validOrdinal) {
75459
- return unitOutOfRange("ordinal", obj.ordinal);
75460
- } else return false;
75461
- }
75462
- function hasInvalidGregorianData(obj) {
75463
- const validYear = isInteger(obj.year),
75464
- validMonth = integerBetween(obj.month, 1, 12),
75465
- validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
75466
- if (!validYear) {
75467
- return unitOutOfRange("year", obj.year);
75468
- } else if (!validMonth) {
75469
- return unitOutOfRange("month", obj.month);
75470
- } else if (!validDay) {
75471
- return unitOutOfRange("day", obj.day);
75472
- } else return false;
75473
- }
75474
- function hasInvalidTimeData(obj) {
75475
- const {
75476
- hour,
75477
- minute,
75478
- second,
75479
- millisecond
75480
- } = obj;
75481
- const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
75482
- validMinute = integerBetween(minute, 0, 59),
75483
- validSecond = integerBetween(second, 0, 59),
75484
- validMillisecond = integerBetween(millisecond, 0, 999);
75485
- if (!validHour) {
75486
- return unitOutOfRange("hour", hour);
75487
- } else if (!validMinute) {
75488
- return unitOutOfRange("minute", minute);
75489
- } else if (!validSecond) {
75490
- return unitOutOfRange("second", second);
75491
- } else if (!validMillisecond) {
75492
- return unitOutOfRange("millisecond", millisecond);
75493
- } else return false;
75494
- }
75495
-
75496
75738
  const INVALID = "Invalid DateTime";
75497
75739
  const MAX_DATE = 8.64e15;
75498
75740
  function unsupportedZone(zone) {
@@ -75500,6 +75742,9 @@ function unsupportedZone(zone) {
75500
75742
  }
75501
75743
 
75502
75744
  // we cache week data on the DT object and this intermediates the cache
75745
+ /**
75746
+ * @param {DateTime} dt
75747
+ */
75503
75748
  function possiblyCachedWeekData(dt) {
75504
75749
  if (dt.weekData === null) {
75505
75750
  dt.weekData = gregorianToWeek(dt.c);
@@ -75507,6 +75752,16 @@ function possiblyCachedWeekData(dt) {
75507
75752
  return dt.weekData;
75508
75753
  }
75509
75754
 
75755
+ /**
75756
+ * @param {DateTime} dt
75757
+ */
75758
+ function possiblyCachedLocalWeekData(dt) {
75759
+ if (dt.localWeekData === null) {
75760
+ dt.localWeekData = gregorianToWeek(dt.c, dt.loc.getMinDaysInFirstWeek(), dt.loc.getStartOfWeek());
75761
+ }
75762
+ return dt.localWeekData;
75763
+ }
75764
+
75510
75765
  // clone really means, "make a new object with these modifications". all "setters" really use this
75511
75766
  // to create a new object while only changing some of the properties
75512
75767
  function clone(inst, alts) {
@@ -75751,6 +76006,21 @@ function normalizeUnit(unit) {
75751
76006
  if (!normalized) throw new InvalidUnitError(unit);
75752
76007
  return normalized;
75753
76008
  }
76009
+ function normalizeUnitWithLocalWeeks(unit) {
76010
+ switch (unit.toLowerCase()) {
76011
+ case "localweekday":
76012
+ case "localweekdays":
76013
+ return "localWeekday";
76014
+ case "localweeknumber":
76015
+ case "localweeknumbers":
76016
+ return "localWeekNumber";
76017
+ case "localweekyear":
76018
+ case "localweekyears":
76019
+ return "localWeekYear";
76020
+ default:
76021
+ return normalizeUnit(unit);
76022
+ }
76023
+ }
75754
76024
 
75755
76025
  // this is a dumbed down version of fromObject() that runs about 60% faster
75756
76026
  // but doesn't do any validation, makes a bunch of assumptions about what units
@@ -75885,6 +76155,10 @@ class DateTime {
75885
76155
  * @access private
75886
76156
  */
75887
76157
  this.weekData = null;
76158
+ /**
76159
+ * @access private
76160
+ */
76161
+ this.localWeekData = null;
75888
76162
  /**
75889
76163
  * @access private
75890
76164
  */
@@ -76066,13 +76340,16 @@ class DateTime {
76066
76340
  * @param {number} obj.weekYear - an ISO week year
76067
76341
  * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
76068
76342
  * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
76343
+ * @param {number} obj.localWeekYear - a week year, according to the locale
76344
+ * @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
76345
+ * @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
76069
76346
  * @param {number} obj.hour - hour of the day, 0-23
76070
76347
  * @param {number} obj.minute - minute of the hour, 0-59
76071
76348
  * @param {number} obj.second - second of the minute, 0-59
76072
76349
  * @param {number} obj.millisecond - millisecond of the second, 0-999
76073
76350
  * @param {Object} opts - options for creating this DateTime
76074
76351
  * @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()
76075
- * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
76352
+ * @param {string} [opts.locale='system\'s locale'] - a locale to set on the resulting DateTime instance
76076
76353
  * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
76077
76354
  * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
76078
76355
  * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
@@ -76082,6 +76359,7 @@ class DateTime {
76082
76359
  * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
76083
76360
  * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
76084
76361
  * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
76362
+ * @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
76085
76363
  * @return {DateTime}
76086
76364
  */
76087
76365
  static fromObject(obj, opts = {}) {
@@ -76090,15 +76368,19 @@ class DateTime {
76090
76368
  if (!zoneToUse.isValid) {
76091
76369
  return DateTime.invalid(unsupportedZone(zoneToUse));
76092
76370
  }
76371
+ const loc = Locale.fromObject(opts);
76372
+ const normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
76373
+ const {
76374
+ minDaysInFirstWeek,
76375
+ startOfWeek
76376
+ } = usesLocalWeekValues(normalized, loc);
76093
76377
  const tsNow = Settings.now(),
76094
76378
  offsetProvis = !isUndefined(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow),
76095
- normalized = normalizeObject(obj, normalizeUnit),
76096
76379
  containsOrdinal = !isUndefined(normalized.ordinal),
76097
76380
  containsGregorYear = !isUndefined(normalized.year),
76098
76381
  containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
76099
76382
  containsGregor = containsGregorYear || containsGregorMD,
76100
- definiteWeekDef = normalized.weekYear || normalized.weekNumber,
76101
- loc = Locale.fromObject(opts);
76383
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
76102
76384
 
76103
76385
  // cases:
76104
76386
  // just a weekday -> this week's instance of that weekday, no worries
@@ -76121,7 +76403,7 @@ class DateTime {
76121
76403
  if (useWeekData) {
76122
76404
  units = orderedWeekUnits;
76123
76405
  defaultValues = defaultWeekUnitValues;
76124
- objNow = gregorianToWeek(objNow);
76406
+ objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
76125
76407
  } else if (containsOrdinal) {
76126
76408
  units = orderedOrdinalUnits;
76127
76409
  defaultValues = defaultOrdinalUnitValues;
@@ -76145,14 +76427,14 @@ class DateTime {
76145
76427
  }
76146
76428
 
76147
76429
  // make sure the values we have are in range
76148
- const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
76430
+ const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
76149
76431
  invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
76150
76432
  if (invalid) {
76151
76433
  return DateTime.invalid(invalid);
76152
76434
  }
76153
76435
 
76154
76436
  // compute the actual time
76155
- const gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
76437
+ const gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
76156
76438
  [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
76157
76439
  inst = new DateTime({
76158
76440
  ts: tsFinal,
@@ -76531,6 +76813,43 @@ class DateTime {
76531
76813
  return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
76532
76814
  }
76533
76815
 
76816
+ /**
76817
+ * Returns true if this date is on a weekend according to the locale, false otherwise
76818
+ * @returns {boolean}
76819
+ */
76820
+ get isWeekend() {
76821
+ return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
76822
+ }
76823
+
76824
+ /**
76825
+ * Get the day of the week according to the locale.
76826
+ * 1 is the first day of the week and 7 is the last day of the week.
76827
+ * If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
76828
+ * @returns {number}
76829
+ */
76830
+ get localWeekday() {
76831
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
76832
+ }
76833
+
76834
+ /**
76835
+ * Get the week number of the week year according to the locale. Different locales assign week numbers differently,
76836
+ * because the week can start on different days of the week (see localWeekday) and because a different number of days
76837
+ * is required for a week to count as the first week of a year.
76838
+ * @returns {number}
76839
+ */
76840
+ get localWeekNumber() {
76841
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
76842
+ }
76843
+
76844
+ /**
76845
+ * Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
76846
+ * differently, see localWeekNumber.
76847
+ * @returns {number}
76848
+ */
76849
+ get localWeekYear() {
76850
+ return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : NaN;
76851
+ }
76852
+
76534
76853
  /**
76535
76854
  * Get the ordinal (meaning the day of the year)
76536
76855
  * @example DateTime.local(2017, 5, 25).ordinal //=> 145
@@ -76731,6 +77050,16 @@ class DateTime {
76731
77050
  return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
76732
77051
  }
76733
77052
 
77053
+ /**
77054
+ * Returns the number of weeks in this DateTime's local week year
77055
+ * @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
77056
+ * @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
77057
+ * @type {number}
77058
+ */
77059
+ get weeksInLocalWeekYear() {
77060
+ return this.isValid ? weeksInWeekYear(this.localWeekYear, this.loc.getMinDaysInFirstWeek(), this.loc.getStartOfWeek()) : NaN;
77061
+ }
77062
+
76734
77063
  /**
76735
77064
  * Returns the resolved Intl options for this DateTime.
76736
77065
  * This is useful in understanding the behavior of formatting methods
@@ -76842,6 +77171,9 @@ class DateTime {
76842
77171
  /**
76843
77172
  * "Set" the values of specified units. Returns a newly-constructed DateTime.
76844
77173
  * You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}.
77174
+ *
77175
+ * This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
77176
+ * They cannot be mixed with ISO-week units like `weekday`.
76845
77177
  * @param {Object} values - a mapping of units to numbers
76846
77178
  * @example dt.set({ year: 2017 })
76847
77179
  * @example dt.set({ hour: 8, minute: 30 })
@@ -76851,8 +77183,12 @@ class DateTime {
76851
77183
  */
76852
77184
  set(values) {
76853
77185
  if (!this.isValid) return this;
76854
- const normalized = normalizeObject(values, normalizeUnit),
76855
- settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
77186
+ const normalized = normalizeObject(values, normalizeUnitWithLocalWeeks);
77187
+ const {
77188
+ minDaysInFirstWeek,
77189
+ startOfWeek
77190
+ } = usesLocalWeekValues(normalized, this.loc);
77191
+ const settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
76856
77192
  containsOrdinal = !isUndefined(normalized.ordinal),
76857
77193
  containsGregorYear = !isUndefined(normalized.year),
76858
77194
  containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
@@ -76867,9 +77203,9 @@ class DateTime {
76867
77203
  let mixed;
76868
77204
  if (settingWeekStuff) {
76869
77205
  mixed = weekToGregorian({
76870
- ...gregorianToWeek(this.c),
77206
+ ...gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek),
76871
77207
  ...normalized
76872
- });
77208
+ }, minDaysInFirstWeek, startOfWeek);
76873
77209
  } else if (!isUndefined(normalized.ordinal)) {
76874
77210
  mixed = ordinalToGregorian({
76875
77211
  ...gregorianToOrdinal(this.c),
@@ -76928,6 +77264,8 @@ class DateTime {
76928
77264
  /**
76929
77265
  * "Set" this DateTime to the beginning of a unit of time.
76930
77266
  * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
77267
+ * @param {Object} opts - options
77268
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
76931
77269
  * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
76932
77270
  * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
76933
77271
  * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
@@ -76935,7 +77273,9 @@ class DateTime {
76935
77273
  * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
76936
77274
  * @return {DateTime}
76937
77275
  */
76938
- startOf(unit) {
77276
+ startOf(unit, {
77277
+ useLocaleWeeks = false
77278
+ } = {}) {
76939
77279
  if (!this.isValid) return this;
76940
77280
  const o = {},
76941
77281
  normalizedUnit = Duration.normalizeUnit(unit);
@@ -76964,7 +77304,18 @@ class DateTime {
76964
77304
  }
76965
77305
 
76966
77306
  if (normalizedUnit === "weeks") {
76967
- o.weekday = 1;
77307
+ if (useLocaleWeeks) {
77308
+ const startOfWeek = this.loc.getStartOfWeek();
77309
+ const {
77310
+ weekday
77311
+ } = this;
77312
+ if (weekday < startOfWeek) {
77313
+ o.weekNumber = this.weekNumber - 1;
77314
+ }
77315
+ o.weekday = startOfWeek;
77316
+ } else {
77317
+ o.weekday = 1;
77318
+ }
76968
77319
  }
76969
77320
  if (normalizedUnit === "quarters") {
76970
77321
  const q = Math.ceil(this.month / 3);
@@ -76976,6 +77327,8 @@ class DateTime {
76976
77327
  /**
76977
77328
  * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
76978
77329
  * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
77330
+ * @param {Object} opts - options
77331
+ * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
76979
77332
  * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
76980
77333
  * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
76981
77334
  * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
@@ -76983,10 +77336,10 @@ class DateTime {
76983
77336
  * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
76984
77337
  * @return {DateTime}
76985
77338
  */
76986
- endOf(unit) {
77339
+ endOf(unit, opts) {
76987
77340
  return this.isValid ? this.plus({
76988
77341
  [unit]: 1
76989
- }).startOf(unit).minus(1) : this;
77342
+ }).startOf(unit, opts).minus(1) : this;
76990
77343
  }
76991
77344
 
76992
77345
  // OUTPUT
@@ -77226,6 +77579,18 @@ class DateTime {
77226
77579
  return this.isValid ? this.toISO() : INVALID;
77227
77580
  }
77228
77581
 
77582
+ /**
77583
+ * Returns a string representation of this DateTime appropriate for the REPL.
77584
+ * @return {string}
77585
+ */
77586
+ [Symbol.for("nodejs.util.inspect.custom")]() {
77587
+ if (this.isValid) {
77588
+ return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`;
77589
+ } else {
77590
+ return `DateTime { Invalid, reason: ${this.invalidReason} }`;
77591
+ }
77592
+ }
77593
+
77229
77594
  /**
77230
77595
  * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
77231
77596
  * @return {number}
@@ -77363,16 +77728,18 @@ class DateTime {
77363
77728
  * 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.
77364
77729
  * @param {DateTime} otherDateTime - the other DateTime
77365
77730
  * @param {string} unit - the unit of time to check sameness on
77731
+ * @param {Object} opts - options
77732
+ * @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
77366
77733
  * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
77367
77734
  * @return {boolean}
77368
77735
  */
77369
- hasSame(otherDateTime, unit) {
77736
+ hasSame(otherDateTime, unit, opts) {
77370
77737
  if (!this.isValid) return false;
77371
77738
  const inputMs = otherDateTime.valueOf();
77372
77739
  const adjustedToZone = this.setZone(otherDateTime.zone, {
77373
77740
  keepLocalTime: true
77374
77741
  });
77375
- return adjustedToZone.startOf(unit) <= inputMs && inputMs <= adjustedToZone.endOf(unit);
77742
+ return adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts);
77376
77743
  }
77377
77744
 
77378
77745
  /**
@@ -77696,7 +78063,7 @@ function friendlyDateTime(dateTimeish) {
77696
78063
  }
77697
78064
  }
77698
78065
 
77699
- const VERSION = "3.4.3";
78066
+ const VERSION = "3.4.4";
77700
78067
 
77701
78068
  exports.DateTime = DateTime;
77702
78069
  exports.Duration = Duration;