@nmshd/content 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attributes/AttributeValueTypes.d.ts +10 -10
- package/dist/attributes/AttributeValueTypes.js +2 -2
- package/dist/attributes/AttributeValueTypes.js.map +1 -1
- package/dist/attributes/IQLQuery.js +2 -2
- package/dist/attributes/IdentityAttribute.js.map +1 -1
- package/dist/attributes/IdentityAttributeQuery.js.map +1 -1
- package/dist/attributes/ThirdPartyRelationshipAttributeQuery.js.map +1 -1
- package/dist/attributes/hints/ValueHintsValue.js.map +1 -1
- package/dist/attributes/types/address/DeliveryBoxAddress.js.map +1 -1
- package/dist/attributes/types/address/PostOfficeBoxAddress.js.map +1 -1
- package/dist/attributes/types/address/StreetAddress.js.map +1 -1
- package/dist/attributes/types/affiliation/Affiliation.js.map +1 -1
- package/dist/attributes/types/birth/BirthPlace.js.map +1 -1
- package/dist/attributes/types/proprietary/ProprietaryJSON.js.map +1 -1
- package/dist/attributes/types/statement/AbstractIdentityDescriptor.d.ts +1 -1
- package/dist/attributes/types/statement/AbstractIdentityDescriptor.js.map +1 -1
- package/dist/attributes/types/statement/AbstractStatement.js.map +1 -1
- package/dist/attributes/types/statement/StatementPredicate.js.map +1 -1
- package/dist/buildInformation.js +5 -5
- package/dist/messages/Mail.js.map +1 -1
- package/dist/requests/RequestItemGroup.js.map +1 -1
- package/dist/requests/items/proposeAttribute/ProposeAttributeRequestItem.js.map +1 -1
- package/lib-web/nmshd.content.js +573 -234
- package/lib-web/nmshd.content.min.js +1 -1
- package/package.json +15 -15
package/lib-web/nmshd.content.js
CHANGED
|
@@ -210,7 +210,7 @@ var AttributeValues;
|
|
|
210
210
|
types_1.MiddleName,
|
|
211
211
|
types_1.SchematizedXML,
|
|
212
212
|
types_1.State,
|
|
213
|
-
|
|
213
|
+
// Statement,
|
|
214
214
|
types_1.Street,
|
|
215
215
|
types_1.Surname,
|
|
216
216
|
types_1.ZipCode
|
|
@@ -234,7 +234,7 @@ var AttributeValues;
|
|
|
234
234
|
"MiddleName",
|
|
235
235
|
"SchematizedXML",
|
|
236
236
|
"State",
|
|
237
|
-
"Statement",
|
|
237
|
+
// "Statement",
|
|
238
238
|
"Street",
|
|
239
239
|
"Surname",
|
|
240
240
|
"ZipCode"
|
|
@@ -331,7 +331,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
331
331
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
332
332
|
exports.IQLQuery = exports.IQLQueryCreationHints = void 0;
|
|
333
333
|
const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
|
|
334
|
-
const
|
|
334
|
+
const iql = __importStar(__webpack_require__(/*! @nmshd/iql */ "./node_modules/@nmshd/iql/dist/src/index.js"));
|
|
335
335
|
const AbstractAttributeQuery_1 = __webpack_require__(/*! ./AbstractAttributeQuery */ "./dist/attributes/AbstractAttributeQuery.js");
|
|
336
336
|
const AttributeValueTypes_1 = __webpack_require__(/*! ./AttributeValueTypes */ "./dist/attributes/AttributeValueTypes.js");
|
|
337
337
|
const IdentityAttribute_1 = __webpack_require__(/*! ./IdentityAttribute */ "./dist/attributes/IdentityAttribute.js");
|
|
@@ -368,7 +368,7 @@ __decorate([
|
|
|
368
368
|
(0, ts_serval_1.validate)({
|
|
369
369
|
max: 4096,
|
|
370
370
|
customValidator: (v) => {
|
|
371
|
-
const result =
|
|
371
|
+
const result = iql.validate(v);
|
|
372
372
|
return !result.isValid
|
|
373
373
|
? `invalid IQL query at character offset ${result.error.location.start.column}`
|
|
374
374
|
: undefined;
|
|
@@ -7157,11 +7157,11 @@ const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-s
|
|
|
7157
7157
|
const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
|
|
7158
7158
|
const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
|
|
7159
7159
|
exports.buildInformation = {
|
|
7160
|
-
version: "2.8.
|
|
7161
|
-
build: "
|
|
7162
|
-
date: "2023-11-
|
|
7163
|
-
commit: "
|
|
7164
|
-
dependencies: {"@js-soft/logging-abstractions":"^1.0.
|
|
7160
|
+
version: "2.8.1",
|
|
7161
|
+
build: "151",
|
|
7162
|
+
date: "2023-11-30T15:31:58+00:00",
|
|
7163
|
+
commit: "a6f4d7ad46956da432fe7cbd711c4482228ec205",
|
|
7164
|
+
dependencies: {"@js-soft/logging-abstractions":"^1.0.1","@nmshd/iql":"^1.0.0","easy-tsnameof":"^3.0.6","mocha-param":"^2.0.1"},
|
|
7165
7165
|
libraries: {
|
|
7166
7166
|
serval: ts_serval_1.buildInformation,
|
|
7167
7167
|
crypto: crypto_1.buildInformation,
|
|
@@ -11113,6 +11113,17 @@ function systemLocale() {
|
|
|
11113
11113
|
return sysLocaleCache;
|
|
11114
11114
|
}
|
|
11115
11115
|
}
|
|
11116
|
+
let weekInfoCache = {};
|
|
11117
|
+
function getCachedWeekInfo(locString) {
|
|
11118
|
+
let data = weekInfoCache[locString];
|
|
11119
|
+
if (!data) {
|
|
11120
|
+
const locale = new Intl.Locale(locString);
|
|
11121
|
+
// browsers currently implement this as a property, but spec says it should be a getter function
|
|
11122
|
+
data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
|
|
11123
|
+
weekInfoCache[locString] = data;
|
|
11124
|
+
}
|
|
11125
|
+
return data;
|
|
11126
|
+
}
|
|
11116
11127
|
function parseLocaleString(localeStr) {
|
|
11117
11128
|
// I really want to avoid writing a BCP 47 parser
|
|
11118
11129
|
// see, e.g. https://github.com/wooorm/bcp-47
|
|
@@ -11350,6 +11361,11 @@ class PolyRelFormatter {
|
|
|
11350
11361
|
}
|
|
11351
11362
|
}
|
|
11352
11363
|
}
|
|
11364
|
+
const fallbackWeekSettings = {
|
|
11365
|
+
firstDay: 1,
|
|
11366
|
+
minimalDays: 4,
|
|
11367
|
+
weekend: [6, 7]
|
|
11368
|
+
};
|
|
11353
11369
|
|
|
11354
11370
|
/**
|
|
11355
11371
|
* @private
|
|
@@ -11357,15 +11373,16 @@ class PolyRelFormatter {
|
|
|
11357
11373
|
|
|
11358
11374
|
class Locale {
|
|
11359
11375
|
static fromOpts(opts) {
|
|
11360
|
-
return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN);
|
|
11376
|
+
return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.weekSettings, opts.defaultToEN);
|
|
11361
11377
|
}
|
|
11362
|
-
static create(locale, numberingSystem, outputCalendar, defaultToEN = false) {
|
|
11378
|
+
static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
|
|
11363
11379
|
const specifiedLocale = locale || Settings.defaultLocale;
|
|
11364
11380
|
// the system locale is useful for human readable strings but annoying for parsing/formatting known formats
|
|
11365
11381
|
const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
|
|
11366
11382
|
const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
|
|
11367
11383
|
const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
|
|
11368
|
-
|
|
11384
|
+
const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
|
|
11385
|
+
return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
|
|
11369
11386
|
}
|
|
11370
11387
|
static resetCache() {
|
|
11371
11388
|
sysLocaleCache = null;
|
|
@@ -11376,15 +11393,17 @@ class Locale {
|
|
|
11376
11393
|
static fromObject({
|
|
11377
11394
|
locale,
|
|
11378
11395
|
numberingSystem,
|
|
11379
|
-
outputCalendar
|
|
11396
|
+
outputCalendar,
|
|
11397
|
+
weekSettings
|
|
11380
11398
|
} = {}) {
|
|
11381
|
-
return Locale.create(locale, numberingSystem, outputCalendar);
|
|
11399
|
+
return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
|
|
11382
11400
|
}
|
|
11383
|
-
constructor(locale, numbering, outputCalendar, specifiedLocale) {
|
|
11401
|
+
constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
|
|
11384
11402
|
const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
|
|
11385
11403
|
this.locale = parsedLocale;
|
|
11386
11404
|
this.numberingSystem = numbering || parsedNumberingSystem || null;
|
|
11387
11405
|
this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
|
|
11406
|
+
this.weekSettings = weekSettings;
|
|
11388
11407
|
this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
|
|
11389
11408
|
this.weekdaysCache = {
|
|
11390
11409
|
format: {},
|
|
@@ -11414,7 +11433,7 @@ class Locale {
|
|
|
11414
11433
|
if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
|
|
11415
11434
|
return this;
|
|
11416
11435
|
} else {
|
|
11417
|
-
return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false);
|
|
11436
|
+
return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, validateWeekSettings(alts.weekSettings) || this.weekSettings, alts.defaultToEN || false);
|
|
11418
11437
|
}
|
|
11419
11438
|
}
|
|
11420
11439
|
redefaultToEN(alts = {}) {
|
|
@@ -11512,6 +11531,24 @@ class Locale {
|
|
|
11512
11531
|
isEnglish() {
|
|
11513
11532
|
return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
|
|
11514
11533
|
}
|
|
11534
|
+
getWeekSettings() {
|
|
11535
|
+
if (this.weekSettings) {
|
|
11536
|
+
return this.weekSettings;
|
|
11537
|
+
} else if (!hasLocaleWeekInfo()) {
|
|
11538
|
+
return fallbackWeekSettings;
|
|
11539
|
+
} else {
|
|
11540
|
+
return getCachedWeekInfo(this.locale);
|
|
11541
|
+
}
|
|
11542
|
+
}
|
|
11543
|
+
getStartOfWeek() {
|
|
11544
|
+
return this.getWeekSettings().firstDay;
|
|
11545
|
+
}
|
|
11546
|
+
getMinDaysInFirstWeek() {
|
|
11547
|
+
return this.getWeekSettings().minimalDays;
|
|
11548
|
+
}
|
|
11549
|
+
getWeekendDays() {
|
|
11550
|
+
return this.getWeekSettings().weekend;
|
|
11551
|
+
}
|
|
11515
11552
|
equals(other) {
|
|
11516
11553
|
return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
|
|
11517
11554
|
}
|
|
@@ -11695,7 +11732,8 @@ let now = () => Date.now(),
|
|
|
11695
11732
|
defaultNumberingSystem = null,
|
|
11696
11733
|
defaultOutputCalendar = null,
|
|
11697
11734
|
twoDigitCutoffYear = 60,
|
|
11698
|
-
throwOnInvalid
|
|
11735
|
+
throwOnInvalid,
|
|
11736
|
+
defaultWeekSettings = null;
|
|
11699
11737
|
|
|
11700
11738
|
/**
|
|
11701
11739
|
* 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.
|
|
@@ -11786,6 +11824,31 @@ class Settings {
|
|
|
11786
11824
|
defaultOutputCalendar = outputCalendar;
|
|
11787
11825
|
}
|
|
11788
11826
|
|
|
11827
|
+
/**
|
|
11828
|
+
* @typedef {Object} WeekSettings
|
|
11829
|
+
* @property {number} firstDay
|
|
11830
|
+
* @property {number} minimalDays
|
|
11831
|
+
* @property {number[]} weekend
|
|
11832
|
+
*/
|
|
11833
|
+
|
|
11834
|
+
/**
|
|
11835
|
+
* @return {WeekSettings|null}
|
|
11836
|
+
*/
|
|
11837
|
+
static get defaultWeekSettings() {
|
|
11838
|
+
return defaultWeekSettings;
|
|
11839
|
+
}
|
|
11840
|
+
|
|
11841
|
+
/**
|
|
11842
|
+
* Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
|
|
11843
|
+
* how many days are required in the first week of a year.
|
|
11844
|
+
* Does not affect existing instances.
|
|
11845
|
+
*
|
|
11846
|
+
* @param {WeekSettings|null} weekSettings
|
|
11847
|
+
*/
|
|
11848
|
+
static set defaultWeekSettings(weekSettings) {
|
|
11849
|
+
defaultWeekSettings = validateWeekSettings(weekSettings);
|
|
11850
|
+
}
|
|
11851
|
+
|
|
11789
11852
|
/**
|
|
11790
11853
|
* Get the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
|
|
11791
11854
|
* @type {number}
|
|
@@ -11832,6 +11895,224 @@ class Settings {
|
|
|
11832
11895
|
}
|
|
11833
11896
|
}
|
|
11834
11897
|
|
|
11898
|
+
class Invalid {
|
|
11899
|
+
constructor(reason, explanation) {
|
|
11900
|
+
this.reason = reason;
|
|
11901
|
+
this.explanation = explanation;
|
|
11902
|
+
}
|
|
11903
|
+
toMessage() {
|
|
11904
|
+
if (this.explanation) {
|
|
11905
|
+
return `${this.reason}: ${this.explanation}`;
|
|
11906
|
+
} else {
|
|
11907
|
+
return this.reason;
|
|
11908
|
+
}
|
|
11909
|
+
}
|
|
11910
|
+
}
|
|
11911
|
+
|
|
11912
|
+
const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
|
|
11913
|
+
leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
|
|
11914
|
+
function unitOutOfRange(unit, value) {
|
|
11915
|
+
return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
|
|
11916
|
+
}
|
|
11917
|
+
function dayOfWeek(year, month, day) {
|
|
11918
|
+
const d = new Date(Date.UTC(year, month - 1, day));
|
|
11919
|
+
if (year < 100 && year >= 0) {
|
|
11920
|
+
d.setUTCFullYear(d.getUTCFullYear() - 1900);
|
|
11921
|
+
}
|
|
11922
|
+
const js = d.getUTCDay();
|
|
11923
|
+
return js === 0 ? 7 : js;
|
|
11924
|
+
}
|
|
11925
|
+
function computeOrdinal(year, month, day) {
|
|
11926
|
+
return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
|
|
11927
|
+
}
|
|
11928
|
+
function uncomputeOrdinal(year, ordinal) {
|
|
11929
|
+
const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
|
|
11930
|
+
month0 = table.findIndex(i => i < ordinal),
|
|
11931
|
+
day = ordinal - table[month0];
|
|
11932
|
+
return {
|
|
11933
|
+
month: month0 + 1,
|
|
11934
|
+
day
|
|
11935
|
+
};
|
|
11936
|
+
}
|
|
11937
|
+
function isoWeekdayToLocal(isoWeekday, startOfWeek) {
|
|
11938
|
+
return (isoWeekday - startOfWeek + 7) % 7 + 1;
|
|
11939
|
+
}
|
|
11940
|
+
|
|
11941
|
+
/**
|
|
11942
|
+
* @private
|
|
11943
|
+
*/
|
|
11944
|
+
|
|
11945
|
+
function gregorianToWeek(gregObj, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
11946
|
+
const {
|
|
11947
|
+
year,
|
|
11948
|
+
month,
|
|
11949
|
+
day
|
|
11950
|
+
} = gregObj,
|
|
11951
|
+
ordinal = computeOrdinal(year, month, day),
|
|
11952
|
+
weekday = isoWeekdayToLocal(dayOfWeek(year, month, day), startOfWeek);
|
|
11953
|
+
let weekNumber = Math.floor((ordinal - weekday + 14 - minDaysInFirstWeek) / 7),
|
|
11954
|
+
weekYear;
|
|
11955
|
+
if (weekNumber < 1) {
|
|
11956
|
+
weekYear = year - 1;
|
|
11957
|
+
weekNumber = weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek);
|
|
11958
|
+
} else if (weekNumber > weeksInWeekYear(year, minDaysInFirstWeek, startOfWeek)) {
|
|
11959
|
+
weekYear = year + 1;
|
|
11960
|
+
weekNumber = 1;
|
|
11961
|
+
} else {
|
|
11962
|
+
weekYear = year;
|
|
11963
|
+
}
|
|
11964
|
+
return {
|
|
11965
|
+
weekYear,
|
|
11966
|
+
weekNumber,
|
|
11967
|
+
weekday,
|
|
11968
|
+
...timeObject(gregObj)
|
|
11969
|
+
};
|
|
11970
|
+
}
|
|
11971
|
+
function weekToGregorian(weekData, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
11972
|
+
const {
|
|
11973
|
+
weekYear,
|
|
11974
|
+
weekNumber,
|
|
11975
|
+
weekday
|
|
11976
|
+
} = weekData,
|
|
11977
|
+
weekdayOfJan4 = isoWeekdayToLocal(dayOfWeek(weekYear, 1, minDaysInFirstWeek), startOfWeek),
|
|
11978
|
+
yearInDays = daysInYear(weekYear);
|
|
11979
|
+
let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 7 + minDaysInFirstWeek,
|
|
11980
|
+
year;
|
|
11981
|
+
if (ordinal < 1) {
|
|
11982
|
+
year = weekYear - 1;
|
|
11983
|
+
ordinal += daysInYear(year);
|
|
11984
|
+
} else if (ordinal > yearInDays) {
|
|
11985
|
+
year = weekYear + 1;
|
|
11986
|
+
ordinal -= daysInYear(weekYear);
|
|
11987
|
+
} else {
|
|
11988
|
+
year = weekYear;
|
|
11989
|
+
}
|
|
11990
|
+
const {
|
|
11991
|
+
month,
|
|
11992
|
+
day
|
|
11993
|
+
} = uncomputeOrdinal(year, ordinal);
|
|
11994
|
+
return {
|
|
11995
|
+
year,
|
|
11996
|
+
month,
|
|
11997
|
+
day,
|
|
11998
|
+
...timeObject(weekData)
|
|
11999
|
+
};
|
|
12000
|
+
}
|
|
12001
|
+
function gregorianToOrdinal(gregData) {
|
|
12002
|
+
const {
|
|
12003
|
+
year,
|
|
12004
|
+
month,
|
|
12005
|
+
day
|
|
12006
|
+
} = gregData;
|
|
12007
|
+
const ordinal = computeOrdinal(year, month, day);
|
|
12008
|
+
return {
|
|
12009
|
+
year,
|
|
12010
|
+
ordinal,
|
|
12011
|
+
...timeObject(gregData)
|
|
12012
|
+
};
|
|
12013
|
+
}
|
|
12014
|
+
function ordinalToGregorian(ordinalData) {
|
|
12015
|
+
const {
|
|
12016
|
+
year,
|
|
12017
|
+
ordinal
|
|
12018
|
+
} = ordinalData;
|
|
12019
|
+
const {
|
|
12020
|
+
month,
|
|
12021
|
+
day
|
|
12022
|
+
} = uncomputeOrdinal(year, ordinal);
|
|
12023
|
+
return {
|
|
12024
|
+
year,
|
|
12025
|
+
month,
|
|
12026
|
+
day,
|
|
12027
|
+
...timeObject(ordinalData)
|
|
12028
|
+
};
|
|
12029
|
+
}
|
|
12030
|
+
|
|
12031
|
+
/**
|
|
12032
|
+
* Check if local week units like localWeekday are used in obj.
|
|
12033
|
+
* If so, validates that they are not mixed with ISO week units and then copies them to the normal week unit properties.
|
|
12034
|
+
* Modifies obj in-place!
|
|
12035
|
+
* @param obj the object values
|
|
12036
|
+
*/
|
|
12037
|
+
function usesLocalWeekValues(obj, loc) {
|
|
12038
|
+
const hasLocaleWeekData = !isUndefined(obj.localWeekday) || !isUndefined(obj.localWeekNumber) || !isUndefined(obj.localWeekYear);
|
|
12039
|
+
if (hasLocaleWeekData) {
|
|
12040
|
+
const hasIsoWeekData = !isUndefined(obj.weekday) || !isUndefined(obj.weekNumber) || !isUndefined(obj.weekYear);
|
|
12041
|
+
if (hasIsoWeekData) {
|
|
12042
|
+
throw new ConflictingSpecificationError("Cannot mix locale-based week fields with ISO-based week fields");
|
|
12043
|
+
}
|
|
12044
|
+
if (!isUndefined(obj.localWeekday)) obj.weekday = obj.localWeekday;
|
|
12045
|
+
if (!isUndefined(obj.localWeekNumber)) obj.weekNumber = obj.localWeekNumber;
|
|
12046
|
+
if (!isUndefined(obj.localWeekYear)) obj.weekYear = obj.localWeekYear;
|
|
12047
|
+
delete obj.localWeekday;
|
|
12048
|
+
delete obj.localWeekNumber;
|
|
12049
|
+
delete obj.localWeekYear;
|
|
12050
|
+
return {
|
|
12051
|
+
minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
|
|
12052
|
+
startOfWeek: loc.getStartOfWeek()
|
|
12053
|
+
};
|
|
12054
|
+
} else {
|
|
12055
|
+
return {
|
|
12056
|
+
minDaysInFirstWeek: 4,
|
|
12057
|
+
startOfWeek: 1
|
|
12058
|
+
};
|
|
12059
|
+
}
|
|
12060
|
+
}
|
|
12061
|
+
function hasInvalidWeekData(obj, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
12062
|
+
const validYear = isInteger(obj.weekYear),
|
|
12063
|
+
validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear, minDaysInFirstWeek, startOfWeek)),
|
|
12064
|
+
validWeekday = integerBetween(obj.weekday, 1, 7);
|
|
12065
|
+
if (!validYear) {
|
|
12066
|
+
return unitOutOfRange("weekYear", obj.weekYear);
|
|
12067
|
+
} else if (!validWeek) {
|
|
12068
|
+
return unitOutOfRange("week", obj.weekNumber);
|
|
12069
|
+
} else if (!validWeekday) {
|
|
12070
|
+
return unitOutOfRange("weekday", obj.weekday);
|
|
12071
|
+
} else return false;
|
|
12072
|
+
}
|
|
12073
|
+
function hasInvalidOrdinalData(obj) {
|
|
12074
|
+
const validYear = isInteger(obj.year),
|
|
12075
|
+
validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
|
|
12076
|
+
if (!validYear) {
|
|
12077
|
+
return unitOutOfRange("year", obj.year);
|
|
12078
|
+
} else if (!validOrdinal) {
|
|
12079
|
+
return unitOutOfRange("ordinal", obj.ordinal);
|
|
12080
|
+
} else return false;
|
|
12081
|
+
}
|
|
12082
|
+
function hasInvalidGregorianData(obj) {
|
|
12083
|
+
const validYear = isInteger(obj.year),
|
|
12084
|
+
validMonth = integerBetween(obj.month, 1, 12),
|
|
12085
|
+
validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
|
|
12086
|
+
if (!validYear) {
|
|
12087
|
+
return unitOutOfRange("year", obj.year);
|
|
12088
|
+
} else if (!validMonth) {
|
|
12089
|
+
return unitOutOfRange("month", obj.month);
|
|
12090
|
+
} else if (!validDay) {
|
|
12091
|
+
return unitOutOfRange("day", obj.day);
|
|
12092
|
+
} else return false;
|
|
12093
|
+
}
|
|
12094
|
+
function hasInvalidTimeData(obj) {
|
|
12095
|
+
const {
|
|
12096
|
+
hour,
|
|
12097
|
+
minute,
|
|
12098
|
+
second,
|
|
12099
|
+
millisecond
|
|
12100
|
+
} = obj;
|
|
12101
|
+
const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
|
|
12102
|
+
validMinute = integerBetween(minute, 0, 59),
|
|
12103
|
+
validSecond = integerBetween(second, 0, 59),
|
|
12104
|
+
validMillisecond = integerBetween(millisecond, 0, 999);
|
|
12105
|
+
if (!validHour) {
|
|
12106
|
+
return unitOutOfRange("hour", hour);
|
|
12107
|
+
} else if (!validMinute) {
|
|
12108
|
+
return unitOutOfRange("minute", minute);
|
|
12109
|
+
} else if (!validSecond) {
|
|
12110
|
+
return unitOutOfRange("second", second);
|
|
12111
|
+
} else if (!validMillisecond) {
|
|
12112
|
+
return unitOutOfRange("millisecond", millisecond);
|
|
12113
|
+
} else return false;
|
|
12114
|
+
}
|
|
12115
|
+
|
|
11835
12116
|
/*
|
|
11836
12117
|
This is just a junk drawer, containing anything used across multiple classes.
|
|
11837
12118
|
Because Luxon is small(ish), this should stay small and we won't worry about splitting
|
|
@@ -11869,6 +12150,13 @@ function hasRelative() {
|
|
|
11869
12150
|
return false;
|
|
11870
12151
|
}
|
|
11871
12152
|
}
|
|
12153
|
+
function hasLocaleWeekInfo() {
|
|
12154
|
+
try {
|
|
12155
|
+
return typeof Intl !== "undefined" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
|
|
12156
|
+
} catch (e) {
|
|
12157
|
+
return false;
|
|
12158
|
+
}
|
|
12159
|
+
}
|
|
11872
12160
|
|
|
11873
12161
|
// OBJECTS AND ARRAYS
|
|
11874
12162
|
|
|
@@ -11899,6 +12187,22 @@ function pick(obj, keys) {
|
|
|
11899
12187
|
function hasOwnProperty(obj, prop) {
|
|
11900
12188
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
11901
12189
|
}
|
|
12190
|
+
function validateWeekSettings(settings) {
|
|
12191
|
+
if (settings == null) {
|
|
12192
|
+
return null;
|
|
12193
|
+
} else if (typeof settings !== "object") {
|
|
12194
|
+
throw new InvalidArgumentError("Week settings must be an object");
|
|
12195
|
+
} else {
|
|
12196
|
+
if (!integerBetween(settings.firstDay, 1, 7) || !integerBetween(settings.minimalDays, 1, 7) || !Array.isArray(settings.weekend) || settings.weekend.some(v => !integerBetween(v, 1, 7))) {
|
|
12197
|
+
throw new InvalidArgumentError("Invalid week settings");
|
|
12198
|
+
}
|
|
12199
|
+
return {
|
|
12200
|
+
firstDay: settings.firstDay,
|
|
12201
|
+
minimalDays: settings.minimalDays,
|
|
12202
|
+
weekend: Array.from(settings.weekend)
|
|
12203
|
+
};
|
|
12204
|
+
}
|
|
12205
|
+
}
|
|
11902
12206
|
|
|
11903
12207
|
// NUMBERS AND STRINGS
|
|
11904
12208
|
|
|
@@ -11981,11 +12285,16 @@ function objToLocalTS(obj) {
|
|
|
11981
12285
|
}
|
|
11982
12286
|
return +d;
|
|
11983
12287
|
}
|
|
11984
|
-
|
|
11985
|
-
|
|
11986
|
-
|
|
11987
|
-
|
|
11988
|
-
return
|
|
12288
|
+
|
|
12289
|
+
// adapted from moment.js: https://github.com/moment/moment/blob/000ac1800e620f770f4eb31b5ae908f6167b0ab2/src/lib/units/week-calendar-utils.js
|
|
12290
|
+
function firstWeekOffset(year, minDaysInFirstWeek, startOfWeek) {
|
|
12291
|
+
const fwdlw = isoWeekdayToLocal(dayOfWeek(year, 1, minDaysInFirstWeek), startOfWeek);
|
|
12292
|
+
return -fwdlw + minDaysInFirstWeek - 1;
|
|
12293
|
+
}
|
|
12294
|
+
function weeksInWeekYear(weekYear, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
12295
|
+
const weekOffset = firstWeekOffset(weekYear, minDaysInFirstWeek, startOfWeek);
|
|
12296
|
+
const weekOffsetNext = firstWeekOffset(weekYear + 1, minDaysInFirstWeek, startOfWeek);
|
|
12297
|
+
return (daysInYear(weekYear) - weekOffset + weekOffsetNext) / 7;
|
|
11989
12298
|
}
|
|
11990
12299
|
function untruncateYear(year) {
|
|
11991
12300
|
if (year > 99) {
|
|
@@ -12526,6 +12835,14 @@ class Formatter {
|
|
|
12526
12835
|
return this.num(dt.weekNumber);
|
|
12527
12836
|
case "WW":
|
|
12528
12837
|
return this.num(dt.weekNumber, 2);
|
|
12838
|
+
case "n":
|
|
12839
|
+
return this.num(dt.localWeekNumber);
|
|
12840
|
+
case "nn":
|
|
12841
|
+
return this.num(dt.localWeekNumber, 2);
|
|
12842
|
+
case "ii":
|
|
12843
|
+
return this.num(dt.localWeekYear.toString().slice(-2), 2);
|
|
12844
|
+
case "iiii":
|
|
12845
|
+
return this.num(dt.localWeekYear, 4);
|
|
12529
12846
|
case "o":
|
|
12530
12847
|
return this.num(dt.ordinal);
|
|
12531
12848
|
case "ooo":
|
|
@@ -12587,20 +12904,6 @@ class Formatter {
|
|
|
12587
12904
|
}
|
|
12588
12905
|
}
|
|
12589
12906
|
|
|
12590
|
-
class Invalid {
|
|
12591
|
-
constructor(reason, explanation) {
|
|
12592
|
-
this.reason = reason;
|
|
12593
|
-
this.explanation = explanation;
|
|
12594
|
-
}
|
|
12595
|
-
toMessage() {
|
|
12596
|
-
if (this.explanation) {
|
|
12597
|
-
return `${this.reason}: ${this.explanation}`;
|
|
12598
|
-
} else {
|
|
12599
|
-
return this.reason;
|
|
12600
|
-
}
|
|
12601
|
-
}
|
|
12602
|
-
}
|
|
12603
|
-
|
|
12604
12907
|
/*
|
|
12605
12908
|
* This file handles parsing for well-specified formats. Here's how it works:
|
|
12606
12909
|
* Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match.
|
|
@@ -13277,9 +13580,10 @@ class Duration {
|
|
|
13277
13580
|
|
|
13278
13581
|
/**
|
|
13279
13582
|
* Returns a string representation of a Duration with all units included.
|
|
13280
|
-
* To modify its behavior use
|
|
13281
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
|
|
13282
|
-
* @param opts -
|
|
13583
|
+
* To modify its behavior, use `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
|
|
13584
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
13585
|
+
* @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
|
|
13586
|
+
* @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.
|
|
13283
13587
|
* @example
|
|
13284
13588
|
* ```js
|
|
13285
13589
|
* var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
|
|
@@ -13400,6 +13704,18 @@ class Duration {
|
|
|
13400
13704
|
return this.toISO();
|
|
13401
13705
|
}
|
|
13402
13706
|
|
|
13707
|
+
/**
|
|
13708
|
+
* Returns a string representation of this Duration appropriate for the REPL.
|
|
13709
|
+
* @return {string}
|
|
13710
|
+
*/
|
|
13711
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
13712
|
+
if (this.isValid) {
|
|
13713
|
+
return `Duration { values: ${JSON.stringify(this.values)} }`;
|
|
13714
|
+
} else {
|
|
13715
|
+
return `Duration { Invalid, reason: ${this.invalidReason} }`;
|
|
13716
|
+
}
|
|
13717
|
+
}
|
|
13718
|
+
|
|
13403
13719
|
/**
|
|
13404
13720
|
* Returns an milliseconds value of this Duration.
|
|
13405
13721
|
* @return {number}
|
|
@@ -13535,7 +13851,7 @@ class Duration {
|
|
|
13535
13851
|
* Assuming the overall value of the Duration is positive, this means:
|
|
13536
13852
|
* - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
|
|
13537
13853
|
* - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
|
|
13538
|
-
* the overall value would be negative, see
|
|
13854
|
+
* the overall value would be negative, see third example)
|
|
13539
13855
|
* - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
|
|
13540
13856
|
*
|
|
13541
13857
|
* If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
|
|
@@ -13993,12 +14309,22 @@ class Interval {
|
|
|
13993
14309
|
* Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
|
|
13994
14310
|
* asks 'what dates are included in this interval?', not 'how many days long is this interval?'
|
|
13995
14311
|
* @param {string} [unit='milliseconds'] - the unit of time to count.
|
|
14312
|
+
* @param {Object} opts - options
|
|
14313
|
+
* @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
|
|
13996
14314
|
* @return {number}
|
|
13997
14315
|
*/
|
|
13998
|
-
count(unit = "milliseconds") {
|
|
14316
|
+
count(unit = "milliseconds", opts) {
|
|
13999
14317
|
if (!this.isValid) return NaN;
|
|
14000
|
-
const start = this.start.startOf(unit)
|
|
14001
|
-
|
|
14318
|
+
const start = this.start.startOf(unit, opts);
|
|
14319
|
+
let end;
|
|
14320
|
+
if (opts != null && opts.useLocaleWeeks) {
|
|
14321
|
+
end = this.end.reconfigure({
|
|
14322
|
+
locale: start.locale
|
|
14323
|
+
});
|
|
14324
|
+
} else {
|
|
14325
|
+
end = this.end;
|
|
14326
|
+
}
|
|
14327
|
+
end = end.startOf(unit, opts);
|
|
14002
14328
|
return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
|
|
14003
14329
|
}
|
|
14004
14330
|
|
|
@@ -14071,7 +14397,7 @@ class Interval {
|
|
|
14071
14397
|
*/
|
|
14072
14398
|
splitAt(...dateTimes) {
|
|
14073
14399
|
if (!this.isValid) return [];
|
|
14074
|
-
const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort(),
|
|
14400
|
+
const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort((a, b) => a.toMillis() - b.toMillis()),
|
|
14075
14401
|
results = [];
|
|
14076
14402
|
let {
|
|
14077
14403
|
s
|
|
@@ -14278,6 +14604,18 @@ class Interval {
|
|
|
14278
14604
|
return `[${this.s.toISO()} – ${this.e.toISO()})`;
|
|
14279
14605
|
}
|
|
14280
14606
|
|
|
14607
|
+
/**
|
|
14608
|
+
* Returns a string representation of this Interval appropriate for the REPL.
|
|
14609
|
+
* @return {string}
|
|
14610
|
+
*/
|
|
14611
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
14612
|
+
if (this.isValid) {
|
|
14613
|
+
return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
|
|
14614
|
+
} else {
|
|
14615
|
+
return `Interval { Invalid, reason: ${this.invalidReason} }`;
|
|
14616
|
+
}
|
|
14617
|
+
}
|
|
14618
|
+
|
|
14281
14619
|
/**
|
|
14282
14620
|
* Returns a localized string representing this Interval. Accepts the same options as the
|
|
14283
14621
|
* Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
|
|
@@ -14428,6 +14766,50 @@ class Info {
|
|
|
14428
14766
|
return normalizeZone(input, Settings.defaultZone);
|
|
14429
14767
|
}
|
|
14430
14768
|
|
|
14769
|
+
/**
|
|
14770
|
+
* Get the weekday on which the week starts according to the given locale.
|
|
14771
|
+
* @param {Object} opts - options
|
|
14772
|
+
* @param {string} [opts.locale] - the locale code
|
|
14773
|
+
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
14774
|
+
* @returns {number} the start of the week, 1 for Monday through 7 for Sunday
|
|
14775
|
+
*/
|
|
14776
|
+
static getStartOfWeek({
|
|
14777
|
+
locale = null,
|
|
14778
|
+
locObj = null
|
|
14779
|
+
} = {}) {
|
|
14780
|
+
return (locObj || Locale.create(locale)).getStartOfWeek();
|
|
14781
|
+
}
|
|
14782
|
+
|
|
14783
|
+
/**
|
|
14784
|
+
* Get the minimum number of days necessary in a week before it is considered part of the next year according
|
|
14785
|
+
* to the given locale.
|
|
14786
|
+
* @param {Object} opts - options
|
|
14787
|
+
* @param {string} [opts.locale] - the locale code
|
|
14788
|
+
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
14789
|
+
* @returns {number}
|
|
14790
|
+
*/
|
|
14791
|
+
static getMinimumDaysInFirstWeek({
|
|
14792
|
+
locale = null,
|
|
14793
|
+
locObj = null
|
|
14794
|
+
} = {}) {
|
|
14795
|
+
return (locObj || Locale.create(locale)).getMinDaysInFirstWeek();
|
|
14796
|
+
}
|
|
14797
|
+
|
|
14798
|
+
/**
|
|
14799
|
+
* Get the weekdays, which are considered the weekend according to the given locale
|
|
14800
|
+
* @param {Object} opts - options
|
|
14801
|
+
* @param {string} [opts.locale] - the locale code
|
|
14802
|
+
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
14803
|
+
* @returns {number[]} an array of weekdays, 1 for Monday through 7 for Sunday
|
|
14804
|
+
*/
|
|
14805
|
+
static getWeekendWeekdays({
|
|
14806
|
+
locale = null,
|
|
14807
|
+
locObj = null
|
|
14808
|
+
} = {}) {
|
|
14809
|
+
// copy the array, because we cache it internally
|
|
14810
|
+
return (locObj || Locale.create(locale)).getWeekendDays().slice();
|
|
14811
|
+
}
|
|
14812
|
+
|
|
14431
14813
|
/**
|
|
14432
14814
|
* Return an array of standalone month names.
|
|
14433
14815
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
|
|
@@ -14553,12 +14935,14 @@ class Info {
|
|
|
14553
14935
|
* 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.
|
|
14554
14936
|
* Keys:
|
|
14555
14937
|
* * `relative`: whether this environment supports relative time formatting
|
|
14556
|
-
*
|
|
14938
|
+
* * `localeWeek`: whether this environment supports different weekdays for the start of the week based on the locale
|
|
14939
|
+
* @example Info.features() //=> { relative: false, localeWeek: true }
|
|
14557
14940
|
* @return {Object}
|
|
14558
14941
|
*/
|
|
14559
14942
|
static features() {
|
|
14560
14943
|
return {
|
|
14561
|
-
relative: hasRelative()
|
|
14944
|
+
relative: hasRelative(),
|
|
14945
|
+
localeWeek: hasLocaleWeekInfo()
|
|
14562
14946
|
};
|
|
14563
14947
|
}
|
|
14564
14948
|
}
|
|
@@ -15162,176 +15546,6 @@ function formatOptsToTokens(formatOpts, locale) {
|
|
|
15162
15546
|
return parts.map(p => tokenForPart(p, formatOpts, resolvedOpts));
|
|
15163
15547
|
}
|
|
15164
15548
|
|
|
15165
|
-
const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
|
|
15166
|
-
leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
|
|
15167
|
-
function unitOutOfRange(unit, value) {
|
|
15168
|
-
return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
|
|
15169
|
-
}
|
|
15170
|
-
function dayOfWeek(year, month, day) {
|
|
15171
|
-
const d = new Date(Date.UTC(year, month - 1, day));
|
|
15172
|
-
if (year < 100 && year >= 0) {
|
|
15173
|
-
d.setUTCFullYear(d.getUTCFullYear() - 1900);
|
|
15174
|
-
}
|
|
15175
|
-
const js = d.getUTCDay();
|
|
15176
|
-
return js === 0 ? 7 : js;
|
|
15177
|
-
}
|
|
15178
|
-
function computeOrdinal(year, month, day) {
|
|
15179
|
-
return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
|
|
15180
|
-
}
|
|
15181
|
-
function uncomputeOrdinal(year, ordinal) {
|
|
15182
|
-
const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
|
|
15183
|
-
month0 = table.findIndex(i => i < ordinal),
|
|
15184
|
-
day = ordinal - table[month0];
|
|
15185
|
-
return {
|
|
15186
|
-
month: month0 + 1,
|
|
15187
|
-
day
|
|
15188
|
-
};
|
|
15189
|
-
}
|
|
15190
|
-
|
|
15191
|
-
/**
|
|
15192
|
-
* @private
|
|
15193
|
-
*/
|
|
15194
|
-
|
|
15195
|
-
function gregorianToWeek(gregObj) {
|
|
15196
|
-
const {
|
|
15197
|
-
year,
|
|
15198
|
-
month,
|
|
15199
|
-
day
|
|
15200
|
-
} = gregObj,
|
|
15201
|
-
ordinal = computeOrdinal(year, month, day),
|
|
15202
|
-
weekday = dayOfWeek(year, month, day);
|
|
15203
|
-
let weekNumber = Math.floor((ordinal - weekday + 10) / 7),
|
|
15204
|
-
weekYear;
|
|
15205
|
-
if (weekNumber < 1) {
|
|
15206
|
-
weekYear = year - 1;
|
|
15207
|
-
weekNumber = weeksInWeekYear(weekYear);
|
|
15208
|
-
} else if (weekNumber > weeksInWeekYear(year)) {
|
|
15209
|
-
weekYear = year + 1;
|
|
15210
|
-
weekNumber = 1;
|
|
15211
|
-
} else {
|
|
15212
|
-
weekYear = year;
|
|
15213
|
-
}
|
|
15214
|
-
return {
|
|
15215
|
-
weekYear,
|
|
15216
|
-
weekNumber,
|
|
15217
|
-
weekday,
|
|
15218
|
-
...timeObject(gregObj)
|
|
15219
|
-
};
|
|
15220
|
-
}
|
|
15221
|
-
function weekToGregorian(weekData) {
|
|
15222
|
-
const {
|
|
15223
|
-
weekYear,
|
|
15224
|
-
weekNumber,
|
|
15225
|
-
weekday
|
|
15226
|
-
} = weekData,
|
|
15227
|
-
weekdayOfJan4 = dayOfWeek(weekYear, 1, 4),
|
|
15228
|
-
yearInDays = daysInYear(weekYear);
|
|
15229
|
-
let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 3,
|
|
15230
|
-
year;
|
|
15231
|
-
if (ordinal < 1) {
|
|
15232
|
-
year = weekYear - 1;
|
|
15233
|
-
ordinal += daysInYear(year);
|
|
15234
|
-
} else if (ordinal > yearInDays) {
|
|
15235
|
-
year = weekYear + 1;
|
|
15236
|
-
ordinal -= daysInYear(weekYear);
|
|
15237
|
-
} else {
|
|
15238
|
-
year = weekYear;
|
|
15239
|
-
}
|
|
15240
|
-
const {
|
|
15241
|
-
month,
|
|
15242
|
-
day
|
|
15243
|
-
} = uncomputeOrdinal(year, ordinal);
|
|
15244
|
-
return {
|
|
15245
|
-
year,
|
|
15246
|
-
month,
|
|
15247
|
-
day,
|
|
15248
|
-
...timeObject(weekData)
|
|
15249
|
-
};
|
|
15250
|
-
}
|
|
15251
|
-
function gregorianToOrdinal(gregData) {
|
|
15252
|
-
const {
|
|
15253
|
-
year,
|
|
15254
|
-
month,
|
|
15255
|
-
day
|
|
15256
|
-
} = gregData;
|
|
15257
|
-
const ordinal = computeOrdinal(year, month, day);
|
|
15258
|
-
return {
|
|
15259
|
-
year,
|
|
15260
|
-
ordinal,
|
|
15261
|
-
...timeObject(gregData)
|
|
15262
|
-
};
|
|
15263
|
-
}
|
|
15264
|
-
function ordinalToGregorian(ordinalData) {
|
|
15265
|
-
const {
|
|
15266
|
-
year,
|
|
15267
|
-
ordinal
|
|
15268
|
-
} = ordinalData;
|
|
15269
|
-
const {
|
|
15270
|
-
month,
|
|
15271
|
-
day
|
|
15272
|
-
} = uncomputeOrdinal(year, ordinal);
|
|
15273
|
-
return {
|
|
15274
|
-
year,
|
|
15275
|
-
month,
|
|
15276
|
-
day,
|
|
15277
|
-
...timeObject(ordinalData)
|
|
15278
|
-
};
|
|
15279
|
-
}
|
|
15280
|
-
function hasInvalidWeekData(obj) {
|
|
15281
|
-
const validYear = isInteger(obj.weekYear),
|
|
15282
|
-
validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)),
|
|
15283
|
-
validWeekday = integerBetween(obj.weekday, 1, 7);
|
|
15284
|
-
if (!validYear) {
|
|
15285
|
-
return unitOutOfRange("weekYear", obj.weekYear);
|
|
15286
|
-
} else if (!validWeek) {
|
|
15287
|
-
return unitOutOfRange("week", obj.week);
|
|
15288
|
-
} else if (!validWeekday) {
|
|
15289
|
-
return unitOutOfRange("weekday", obj.weekday);
|
|
15290
|
-
} else return false;
|
|
15291
|
-
}
|
|
15292
|
-
function hasInvalidOrdinalData(obj) {
|
|
15293
|
-
const validYear = isInteger(obj.year),
|
|
15294
|
-
validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
|
|
15295
|
-
if (!validYear) {
|
|
15296
|
-
return unitOutOfRange("year", obj.year);
|
|
15297
|
-
} else if (!validOrdinal) {
|
|
15298
|
-
return unitOutOfRange("ordinal", obj.ordinal);
|
|
15299
|
-
} else return false;
|
|
15300
|
-
}
|
|
15301
|
-
function hasInvalidGregorianData(obj) {
|
|
15302
|
-
const validYear = isInteger(obj.year),
|
|
15303
|
-
validMonth = integerBetween(obj.month, 1, 12),
|
|
15304
|
-
validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
|
|
15305
|
-
if (!validYear) {
|
|
15306
|
-
return unitOutOfRange("year", obj.year);
|
|
15307
|
-
} else if (!validMonth) {
|
|
15308
|
-
return unitOutOfRange("month", obj.month);
|
|
15309
|
-
} else if (!validDay) {
|
|
15310
|
-
return unitOutOfRange("day", obj.day);
|
|
15311
|
-
} else return false;
|
|
15312
|
-
}
|
|
15313
|
-
function hasInvalidTimeData(obj) {
|
|
15314
|
-
const {
|
|
15315
|
-
hour,
|
|
15316
|
-
minute,
|
|
15317
|
-
second,
|
|
15318
|
-
millisecond
|
|
15319
|
-
} = obj;
|
|
15320
|
-
const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
|
|
15321
|
-
validMinute = integerBetween(minute, 0, 59),
|
|
15322
|
-
validSecond = integerBetween(second, 0, 59),
|
|
15323
|
-
validMillisecond = integerBetween(millisecond, 0, 999);
|
|
15324
|
-
if (!validHour) {
|
|
15325
|
-
return unitOutOfRange("hour", hour);
|
|
15326
|
-
} else if (!validMinute) {
|
|
15327
|
-
return unitOutOfRange("minute", minute);
|
|
15328
|
-
} else if (!validSecond) {
|
|
15329
|
-
return unitOutOfRange("second", second);
|
|
15330
|
-
} else if (!validMillisecond) {
|
|
15331
|
-
return unitOutOfRange("millisecond", millisecond);
|
|
15332
|
-
} else return false;
|
|
15333
|
-
}
|
|
15334
|
-
|
|
15335
15549
|
const INVALID = "Invalid DateTime";
|
|
15336
15550
|
const MAX_DATE = 8.64e15;
|
|
15337
15551
|
function unsupportedZone(zone) {
|
|
@@ -15339,6 +15553,9 @@ function unsupportedZone(zone) {
|
|
|
15339
15553
|
}
|
|
15340
15554
|
|
|
15341
15555
|
// we cache week data on the DT object and this intermediates the cache
|
|
15556
|
+
/**
|
|
15557
|
+
* @param {DateTime} dt
|
|
15558
|
+
*/
|
|
15342
15559
|
function possiblyCachedWeekData(dt) {
|
|
15343
15560
|
if (dt.weekData === null) {
|
|
15344
15561
|
dt.weekData = gregorianToWeek(dt.c);
|
|
@@ -15346,6 +15563,16 @@ function possiblyCachedWeekData(dt) {
|
|
|
15346
15563
|
return dt.weekData;
|
|
15347
15564
|
}
|
|
15348
15565
|
|
|
15566
|
+
/**
|
|
15567
|
+
* @param {DateTime} dt
|
|
15568
|
+
*/
|
|
15569
|
+
function possiblyCachedLocalWeekData(dt) {
|
|
15570
|
+
if (dt.localWeekData === null) {
|
|
15571
|
+
dt.localWeekData = gregorianToWeek(dt.c, dt.loc.getMinDaysInFirstWeek(), dt.loc.getStartOfWeek());
|
|
15572
|
+
}
|
|
15573
|
+
return dt.localWeekData;
|
|
15574
|
+
}
|
|
15575
|
+
|
|
15349
15576
|
// clone really means, "make a new object with these modifications". all "setters" really use this
|
|
15350
15577
|
// to create a new object while only changing some of the properties
|
|
15351
15578
|
function clone(inst, alts) {
|
|
@@ -15590,6 +15817,21 @@ function normalizeUnit(unit) {
|
|
|
15590
15817
|
if (!normalized) throw new InvalidUnitError(unit);
|
|
15591
15818
|
return normalized;
|
|
15592
15819
|
}
|
|
15820
|
+
function normalizeUnitWithLocalWeeks(unit) {
|
|
15821
|
+
switch (unit.toLowerCase()) {
|
|
15822
|
+
case "localweekday":
|
|
15823
|
+
case "localweekdays":
|
|
15824
|
+
return "localWeekday";
|
|
15825
|
+
case "localweeknumber":
|
|
15826
|
+
case "localweeknumbers":
|
|
15827
|
+
return "localWeekNumber";
|
|
15828
|
+
case "localweekyear":
|
|
15829
|
+
case "localweekyears":
|
|
15830
|
+
return "localWeekYear";
|
|
15831
|
+
default:
|
|
15832
|
+
return normalizeUnit(unit);
|
|
15833
|
+
}
|
|
15834
|
+
}
|
|
15593
15835
|
|
|
15594
15836
|
// this is a dumbed down version of fromObject() that runs about 60% faster
|
|
15595
15837
|
// but doesn't do any validation, makes a bunch of assumptions about what units
|
|
@@ -15724,6 +15966,10 @@ class DateTime {
|
|
|
15724
15966
|
* @access private
|
|
15725
15967
|
*/
|
|
15726
15968
|
this.weekData = null;
|
|
15969
|
+
/**
|
|
15970
|
+
* @access private
|
|
15971
|
+
*/
|
|
15972
|
+
this.localWeekData = null;
|
|
15727
15973
|
/**
|
|
15728
15974
|
* @access private
|
|
15729
15975
|
*/
|
|
@@ -15905,13 +16151,16 @@ class DateTime {
|
|
|
15905
16151
|
* @param {number} obj.weekYear - an ISO week year
|
|
15906
16152
|
* @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
|
|
15907
16153
|
* @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
|
|
16154
|
+
* @param {number} obj.localWeekYear - a week year, according to the locale
|
|
16155
|
+
* @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
|
|
16156
|
+
* @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
|
|
15908
16157
|
* @param {number} obj.hour - hour of the day, 0-23
|
|
15909
16158
|
* @param {number} obj.minute - minute of the hour, 0-59
|
|
15910
16159
|
* @param {number} obj.second - second of the minute, 0-59
|
|
15911
16160
|
* @param {number} obj.millisecond - millisecond of the second, 0-999
|
|
15912
16161
|
* @param {Object} opts - options for creating this DateTime
|
|
15913
16162
|
* @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()
|
|
15914
|
-
* @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
|
|
16163
|
+
* @param {string} [opts.locale='system\'s locale'] - a locale to set on the resulting DateTime instance
|
|
15915
16164
|
* @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
|
15916
16165
|
* @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
|
|
15917
16166
|
* @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
|
|
@@ -15921,6 +16170,7 @@ class DateTime {
|
|
|
15921
16170
|
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
|
|
15922
16171
|
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
|
|
15923
16172
|
* @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
|
|
16173
|
+
* @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
|
|
15924
16174
|
* @return {DateTime}
|
|
15925
16175
|
*/
|
|
15926
16176
|
static fromObject(obj, opts = {}) {
|
|
@@ -15929,15 +16179,19 @@ class DateTime {
|
|
|
15929
16179
|
if (!zoneToUse.isValid) {
|
|
15930
16180
|
return DateTime.invalid(unsupportedZone(zoneToUse));
|
|
15931
16181
|
}
|
|
16182
|
+
const loc = Locale.fromObject(opts);
|
|
16183
|
+
const normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
|
|
16184
|
+
const {
|
|
16185
|
+
minDaysInFirstWeek,
|
|
16186
|
+
startOfWeek
|
|
16187
|
+
} = usesLocalWeekValues(normalized, loc);
|
|
15932
16188
|
const tsNow = Settings.now(),
|
|
15933
16189
|
offsetProvis = !isUndefined(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow),
|
|
15934
|
-
normalized = normalizeObject(obj, normalizeUnit),
|
|
15935
16190
|
containsOrdinal = !isUndefined(normalized.ordinal),
|
|
15936
16191
|
containsGregorYear = !isUndefined(normalized.year),
|
|
15937
16192
|
containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
|
|
15938
16193
|
containsGregor = containsGregorYear || containsGregorMD,
|
|
15939
|
-
definiteWeekDef = normalized.weekYear || normalized.weekNumber
|
|
15940
|
-
loc = Locale.fromObject(opts);
|
|
16194
|
+
definiteWeekDef = normalized.weekYear || normalized.weekNumber;
|
|
15941
16195
|
|
|
15942
16196
|
// cases:
|
|
15943
16197
|
// just a weekday -> this week's instance of that weekday, no worries
|
|
@@ -15960,7 +16214,7 @@ class DateTime {
|
|
|
15960
16214
|
if (useWeekData) {
|
|
15961
16215
|
units = orderedWeekUnits;
|
|
15962
16216
|
defaultValues = defaultWeekUnitValues;
|
|
15963
|
-
objNow = gregorianToWeek(objNow);
|
|
16217
|
+
objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
|
|
15964
16218
|
} else if (containsOrdinal) {
|
|
15965
16219
|
units = orderedOrdinalUnits;
|
|
15966
16220
|
defaultValues = defaultOrdinalUnitValues;
|
|
@@ -15984,14 +16238,14 @@ class DateTime {
|
|
|
15984
16238
|
}
|
|
15985
16239
|
|
|
15986
16240
|
// make sure the values we have are in range
|
|
15987
|
-
const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
|
|
16241
|
+
const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
|
|
15988
16242
|
invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
|
|
15989
16243
|
if (invalid) {
|
|
15990
16244
|
return DateTime.invalid(invalid);
|
|
15991
16245
|
}
|
|
15992
16246
|
|
|
15993
16247
|
// compute the actual time
|
|
15994
|
-
const gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
|
|
16248
|
+
const gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
|
|
15995
16249
|
[tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
|
|
15996
16250
|
inst = new DateTime({
|
|
15997
16251
|
ts: tsFinal,
|
|
@@ -16370,6 +16624,43 @@ class DateTime {
|
|
|
16370
16624
|
return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
|
|
16371
16625
|
}
|
|
16372
16626
|
|
|
16627
|
+
/**
|
|
16628
|
+
* Returns true if this date is on a weekend according to the locale, false otherwise
|
|
16629
|
+
* @returns {boolean}
|
|
16630
|
+
*/
|
|
16631
|
+
get isWeekend() {
|
|
16632
|
+
return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
|
|
16633
|
+
}
|
|
16634
|
+
|
|
16635
|
+
/**
|
|
16636
|
+
* Get the day of the week according to the locale.
|
|
16637
|
+
* 1 is the first day of the week and 7 is the last day of the week.
|
|
16638
|
+
* If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
|
|
16639
|
+
* @returns {number}
|
|
16640
|
+
*/
|
|
16641
|
+
get localWeekday() {
|
|
16642
|
+
return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
|
|
16643
|
+
}
|
|
16644
|
+
|
|
16645
|
+
/**
|
|
16646
|
+
* Get the week number of the week year according to the locale. Different locales assign week numbers differently,
|
|
16647
|
+
* because the week can start on different days of the week (see localWeekday) and because a different number of days
|
|
16648
|
+
* is required for a week to count as the first week of a year.
|
|
16649
|
+
* @returns {number}
|
|
16650
|
+
*/
|
|
16651
|
+
get localWeekNumber() {
|
|
16652
|
+
return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
|
|
16653
|
+
}
|
|
16654
|
+
|
|
16655
|
+
/**
|
|
16656
|
+
* Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
|
|
16657
|
+
* differently, see localWeekNumber.
|
|
16658
|
+
* @returns {number}
|
|
16659
|
+
*/
|
|
16660
|
+
get localWeekYear() {
|
|
16661
|
+
return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : NaN;
|
|
16662
|
+
}
|
|
16663
|
+
|
|
16373
16664
|
/**
|
|
16374
16665
|
* Get the ordinal (meaning the day of the year)
|
|
16375
16666
|
* @example DateTime.local(2017, 5, 25).ordinal //=> 145
|
|
@@ -16570,6 +16861,16 @@ class DateTime {
|
|
|
16570
16861
|
return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
|
|
16571
16862
|
}
|
|
16572
16863
|
|
|
16864
|
+
/**
|
|
16865
|
+
* Returns the number of weeks in this DateTime's local week year
|
|
16866
|
+
* @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
|
|
16867
|
+
* @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
|
|
16868
|
+
* @type {number}
|
|
16869
|
+
*/
|
|
16870
|
+
get weeksInLocalWeekYear() {
|
|
16871
|
+
return this.isValid ? weeksInWeekYear(this.localWeekYear, this.loc.getMinDaysInFirstWeek(), this.loc.getStartOfWeek()) : NaN;
|
|
16872
|
+
}
|
|
16873
|
+
|
|
16573
16874
|
/**
|
|
16574
16875
|
* Returns the resolved Intl options for this DateTime.
|
|
16575
16876
|
* This is useful in understanding the behavior of formatting methods
|
|
@@ -16681,6 +16982,9 @@ class DateTime {
|
|
|
16681
16982
|
/**
|
|
16682
16983
|
* "Set" the values of specified units. Returns a newly-constructed DateTime.
|
|
16683
16984
|
* You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}.
|
|
16985
|
+
*
|
|
16986
|
+
* This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
|
|
16987
|
+
* They cannot be mixed with ISO-week units like `weekday`.
|
|
16684
16988
|
* @param {Object} values - a mapping of units to numbers
|
|
16685
16989
|
* @example dt.set({ year: 2017 })
|
|
16686
16990
|
* @example dt.set({ hour: 8, minute: 30 })
|
|
@@ -16690,8 +16994,12 @@ class DateTime {
|
|
|
16690
16994
|
*/
|
|
16691
16995
|
set(values) {
|
|
16692
16996
|
if (!this.isValid) return this;
|
|
16693
|
-
const normalized = normalizeObject(values,
|
|
16694
|
-
|
|
16997
|
+
const normalized = normalizeObject(values, normalizeUnitWithLocalWeeks);
|
|
16998
|
+
const {
|
|
16999
|
+
minDaysInFirstWeek,
|
|
17000
|
+
startOfWeek
|
|
17001
|
+
} = usesLocalWeekValues(normalized, this.loc);
|
|
17002
|
+
const settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
|
|
16695
17003
|
containsOrdinal = !isUndefined(normalized.ordinal),
|
|
16696
17004
|
containsGregorYear = !isUndefined(normalized.year),
|
|
16697
17005
|
containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
|
|
@@ -16706,9 +17014,9 @@ class DateTime {
|
|
|
16706
17014
|
let mixed;
|
|
16707
17015
|
if (settingWeekStuff) {
|
|
16708
17016
|
mixed = weekToGregorian({
|
|
16709
|
-
...gregorianToWeek(this.c),
|
|
17017
|
+
...gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek),
|
|
16710
17018
|
...normalized
|
|
16711
|
-
});
|
|
17019
|
+
}, minDaysInFirstWeek, startOfWeek);
|
|
16712
17020
|
} else if (!isUndefined(normalized.ordinal)) {
|
|
16713
17021
|
mixed = ordinalToGregorian({
|
|
16714
17022
|
...gregorianToOrdinal(this.c),
|
|
@@ -16767,6 +17075,8 @@ class DateTime {
|
|
|
16767
17075
|
/**
|
|
16768
17076
|
* "Set" this DateTime to the beginning of a unit of time.
|
|
16769
17077
|
* @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
|
|
17078
|
+
* @param {Object} opts - options
|
|
17079
|
+
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
|
|
16770
17080
|
* @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
|
|
16771
17081
|
* @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
|
|
16772
17082
|
* @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
|
|
@@ -16774,7 +17084,9 @@ class DateTime {
|
|
|
16774
17084
|
* @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
|
|
16775
17085
|
* @return {DateTime}
|
|
16776
17086
|
*/
|
|
16777
|
-
startOf(unit
|
|
17087
|
+
startOf(unit, {
|
|
17088
|
+
useLocaleWeeks = false
|
|
17089
|
+
} = {}) {
|
|
16778
17090
|
if (!this.isValid) return this;
|
|
16779
17091
|
const o = {},
|
|
16780
17092
|
normalizedUnit = Duration.normalizeUnit(unit);
|
|
@@ -16803,7 +17115,18 @@ class DateTime {
|
|
|
16803
17115
|
}
|
|
16804
17116
|
|
|
16805
17117
|
if (normalizedUnit === "weeks") {
|
|
16806
|
-
|
|
17118
|
+
if (useLocaleWeeks) {
|
|
17119
|
+
const startOfWeek = this.loc.getStartOfWeek();
|
|
17120
|
+
const {
|
|
17121
|
+
weekday
|
|
17122
|
+
} = this;
|
|
17123
|
+
if (weekday < startOfWeek) {
|
|
17124
|
+
o.weekNumber = this.weekNumber - 1;
|
|
17125
|
+
}
|
|
17126
|
+
o.weekday = startOfWeek;
|
|
17127
|
+
} else {
|
|
17128
|
+
o.weekday = 1;
|
|
17129
|
+
}
|
|
16807
17130
|
}
|
|
16808
17131
|
if (normalizedUnit === "quarters") {
|
|
16809
17132
|
const q = Math.ceil(this.month / 3);
|
|
@@ -16815,6 +17138,8 @@ class DateTime {
|
|
|
16815
17138
|
/**
|
|
16816
17139
|
* "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
|
|
16817
17140
|
* @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
|
|
17141
|
+
* @param {Object} opts - options
|
|
17142
|
+
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
|
|
16818
17143
|
* @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
|
|
16819
17144
|
* @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
|
|
16820
17145
|
* @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
|
|
@@ -16822,10 +17147,10 @@ class DateTime {
|
|
|
16822
17147
|
* @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
|
|
16823
17148
|
* @return {DateTime}
|
|
16824
17149
|
*/
|
|
16825
|
-
endOf(unit) {
|
|
17150
|
+
endOf(unit, opts) {
|
|
16826
17151
|
return this.isValid ? this.plus({
|
|
16827
17152
|
[unit]: 1
|
|
16828
|
-
}).startOf(unit).minus(1) : this;
|
|
17153
|
+
}).startOf(unit, opts).minus(1) : this;
|
|
16829
17154
|
}
|
|
16830
17155
|
|
|
16831
17156
|
// OUTPUT
|
|
@@ -17065,6 +17390,18 @@ class DateTime {
|
|
|
17065
17390
|
return this.isValid ? this.toISO() : INVALID;
|
|
17066
17391
|
}
|
|
17067
17392
|
|
|
17393
|
+
/**
|
|
17394
|
+
* Returns a string representation of this DateTime appropriate for the REPL.
|
|
17395
|
+
* @return {string}
|
|
17396
|
+
*/
|
|
17397
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
17398
|
+
if (this.isValid) {
|
|
17399
|
+
return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`;
|
|
17400
|
+
} else {
|
|
17401
|
+
return `DateTime { Invalid, reason: ${this.invalidReason} }`;
|
|
17402
|
+
}
|
|
17403
|
+
}
|
|
17404
|
+
|
|
17068
17405
|
/**
|
|
17069
17406
|
* Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
|
|
17070
17407
|
* @return {number}
|
|
@@ -17202,16 +17539,18 @@ class DateTime {
|
|
|
17202
17539
|
* 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.
|
|
17203
17540
|
* @param {DateTime} otherDateTime - the other DateTime
|
|
17204
17541
|
* @param {string} unit - the unit of time to check sameness on
|
|
17542
|
+
* @param {Object} opts - options
|
|
17543
|
+
* @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
|
|
17205
17544
|
* @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
|
|
17206
17545
|
* @return {boolean}
|
|
17207
17546
|
*/
|
|
17208
|
-
hasSame(otherDateTime, unit) {
|
|
17547
|
+
hasSame(otherDateTime, unit, opts) {
|
|
17209
17548
|
if (!this.isValid) return false;
|
|
17210
17549
|
const inputMs = otherDateTime.valueOf();
|
|
17211
17550
|
const adjustedToZone = this.setZone(otherDateTime.zone, {
|
|
17212
17551
|
keepLocalTime: true
|
|
17213
17552
|
});
|
|
17214
|
-
return adjustedToZone.startOf(unit) <= inputMs && inputMs <= adjustedToZone.endOf(unit);
|
|
17553
|
+
return adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts);
|
|
17215
17554
|
}
|
|
17216
17555
|
|
|
17217
17556
|
/**
|
|
@@ -17535,7 +17874,7 @@ function friendlyDateTime(dateTimeish) {
|
|
|
17535
17874
|
}
|
|
17536
17875
|
}
|
|
17537
17876
|
|
|
17538
|
-
const VERSION = "3.4.
|
|
17877
|
+
const VERSION = "3.4.4";
|
|
17539
17878
|
|
|
17540
17879
|
exports.DateTime = DateTime;
|
|
17541
17880
|
exports.Duration = Duration;
|