New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@softwareventures/date

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@softwareventures/date - npm Package Compare versions

Comparing version
4.1.1
to
5.0.0
+28
-4
index.d.ts

@@ -409,4 +409,7 @@ /** @file Data types and functions for working with dates in the Gregorian calendar. */

* Compares two dates and returns the earlier of the two.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
export declare function earliest<T extends DateOptions, U extends DateOptions>(a: T, b: U): T | U;
export declare function earliest(a: DateOptions, b: DateOptions): Date;
/**

@@ -417,2 +420,5 @@ * Compares two dates and returns the earlier of the two.

* that operate on other date/time types.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -424,4 +430,7 @@ export declare const earliestDate: typeof earliest;

* Curried variant of {@link earliest}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
export declare function earliestFn<T extends DateOptions, U extends DateOptions>(b: U): (a: T) => T | U;
export declare function earliestFn(b: DateOptions): (a: DateOptions) => Date;
/**

@@ -431,2 +440,5 @@ * Compares two dates and returns the earlier of the two.

* Curried variant of {@link earliestDate}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -436,4 +448,7 @@ export declare const earliestDateFn: typeof earliestFn;

* Compares two dates and returns the later of the two.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
export declare function latest<T extends DateOptions, U extends DateOptions>(a: T, b: U): T | U;
export declare function latest(a: DateOptions, b: DateOptions): Date;
/**

@@ -444,2 +459,5 @@ * Compares two dates and returns the later of the two.

* that operate on other date/time types.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -451,4 +469,7 @@ export declare const latestDate: typeof latest;

* Curried variant of {@link latest}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
export declare function latestFn<T extends DateOptions, U extends DateOptions>(b: U): (a: T) => T | U;
export declare function latestFn(b: DateOptions): (a: DateOptions) => Date;
/**

@@ -458,2 +479,5 @@ * Compares two dates and returns the later of the two.

* Curried variant of {@link latestDate}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -460,0 +484,0 @@ export declare const latestDateFn: typeof latestFn;

@@ -558,5 +558,10 @@ "use strict";

* Compares two dates and returns the earlier of the two.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
function earliest(a, b) {
return after(a, b) ? b : a;
const ad = toReferenceDays(a);
const bd = toReferenceDays(b);
return fromReferenceDays(ad < bd ? ad : bd);
}

@@ -569,2 +574,5 @@ exports.earliest = earliest;

* that operate on other date/time types.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -576,2 +584,5 @@ exports.earliestDate = earliest;

* Curried variant of {@link earliest}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -586,2 +597,5 @@ function earliestFn(b) {

* Curried variant of {@link earliestDate}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -591,5 +605,10 @@ exports.earliestDateFn = earliestFn;

* Compares two dates and returns the later of the two.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/
function latest(a, b) {
return before(a, b) ? b : a;
const ad = toReferenceDays(a);
const bd = toReferenceDays(b);
return fromReferenceDays(ad > bd ? ad : bd);
}

@@ -602,2 +621,5 @@ exports.latest = latest;

* that operate on other date/time types.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -609,2 +631,5 @@ exports.latestDate = latest;

* Curried variant of {@link latest}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -619,2 +644,5 @@ function latestFn(b) {

* Curried variant of {@link latestDate}.
*
* @throws {Error} if both specified `Date`s contain numeric fields that
* are non-finite.
*/

@@ -621,0 +649,0 @@ exports.latestDateFn = latestFn;

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,uFAAuF;;;;AAGvF,uDAAqD;AACrD,wCAAyC;AACzC,6DAAmD;AACnD,wDAAwD;AACxD,qCAAoC;AACpC,uCAAiC;AA+DjC,0DAA0D;AAC7C,QAAA,OAAO,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAErF,2DAA2D;AAC9C,QAAA,QAAQ,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEtF,wDAAwD;AAC3C,QAAA,KAAK,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEnF,wDAAwD;AAC3C,QAAA,KAAK,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEnF,sDAAsD;AACzC,QAAA,GAAG,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEjF,uDAAuD;AAC1C,QAAA,IAAI,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAElF,uDAAuD;AAC1C,QAAA,IAAI,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAElF,yDAAyD;AAC5C,QAAA,MAAM,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEpF,4DAA4D;AAC/C,QAAA,SAAS,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAEvF,0DAA0D;AAC7C,QAAA,OAAO,GAAG,EAAE,CAAC,CAAC,2DAA2D;AAEtF,2DAA2D;AAC9C,QAAA,QAAQ,GAAG,EAAE,CAAC,CAAC,2DAA2D;AAEvF,2DAA2D;AAC9C,QAAA,QAAQ,GAAG,EAAE,CAAC,CAAC,2DAA2D;AAEvF;;;;;;;;;;;;;GAaG;AACH,SAAgB,UAAU,CAAC,IAAY;IACnC,OAAO,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,IAAI,IAAI,GAAG,GAAG,KAAK,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pC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEnC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC;AAC5C,CAAC;AAXD,oCAWC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;GAIG;AACU,QAAA,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;AAE5C;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC","sourcesContent":["/** @file Data types and functions for working with dates in the Gregorian calendar. */\n\nimport type {Comparator} from \"@softwareventures/ordered\";\nimport {Comparison} from \"@softwareventures/ordered\";\nimport isInteger = require(\"is-integer\");\nimport isIntegerInRange from \"is-integer-in-range\";\nimport * as format from \"@softwareventures/format-date\";\nimport {hasProperty} from \"unknown\";\nimport {JsDate} from \"./js-date\";\n\n/** A date in the Gregorian calendar, with no associated time zone. */\nexport interface Date {\n /** Type discriminator identifying the object as a `Date`. */\n readonly type: \"Date\";\n /** The day of the month. Should be an integer in the range `1`-`31`. */\n day: number;\n /** The month of the year. Should be an integer in the range `1`-`12`. */\n month: number;\n /**\n * The year.\n *\n * Should be an integer.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to\n * npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\n year: number;\n}\n\n/**\n * Options required to construct a `Date`.\n *\n * An instance of {@link Date} may always be used in place of `DateOptions`.\n */\nexport interface DateOptions {\n /**\n * Type discriminator identifying the object as a `Date`.\n *\n * If specified, must be the string `\"Date\"`. This is to prevent errors\n * caused by a `DateTime` being accidentally passed to `Date` functions.\n */\n readonly type?: \"Date\";\n /** The day of the month. Should be in the range `1`-`31`. */\n readonly day: number;\n /** The month of the year. Should be in the range `1`-`12`. */\n readonly month: number;\n /**\n * The year.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to\n * npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\n readonly year: number;\n}\n\n/** The numeric representation of the month of January. */\nexport const JANUARY = 1; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of February. */\nexport const FEBRUARY = 2; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of March. */\nexport const MARCH = 3; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of April. */\nexport const APRIL = 4; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of May. */\nexport const MAY = 5; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of June. */\nexport const JUNE = 6; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of July. */\nexport const JULY = 7; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of August. */\nexport const AUGUST = 8; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of September. */\nexport const SEPTEMBER = 9; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of October. */\nexport const OCTOBER = 10; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of November. */\nexport const NOVEMBER = 11; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of December. */\nexport const DECEMBER = 12; // eslint-disable-line @typescript-eslint/naming-convention\n\n/**\n * Tests if the specified year is a leap year. Returns `true` if it is,\n * otherwise `false`.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\nexport function isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/**\n * Returns the number of days in the specified month in the specified year.\n *\n * @param month - An integer representing the month, in the range `1` (January)\n * to `12` (December).\n *\n * @param year - An integer representing the year. Positive values represent\n * years in the Common Era (CE/AD). For example `2020` represents 2020 CE,\n * the year this module was first published to npm. Negative values or zero\n * represent years before the Common Era (BCE/BC). Zero represents 1 BCE,\n * `-1` represents 2 BCE, `-2` represents 3 BCE, etc. There is no year zero\n * in the Gregorian calendar. The year 1 BCE was immediately followed by 1\n * CE.\n */\nexport function daysInMonth(month: number, year: number): number {\n if (month < JANUARY || month > DECEMBER) {\n throw new Error(\"Invalid month\");\n } else if (month === FEBRUARY && isLeapYear(year)) {\n return 29;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]!;\n }\n}\n\n/**\n * Returns `true` if the specified value has the shape of a {@link Date}\n * object.\n *\n * The `year`, `month` and `day` fields may be non-integers or outside the\n * valid range, meaning that the object may not represent a valid date.\n *\n * To test if the object represents a valid date, call {@link isValid} or\n * {@link isValidDate}.\n */\nexport function isDate(value: unknown): value is Date {\n return (\n typeof value === \"object\" &&\n value != null &&\n hasProperty(value, \"type\") &&\n value.type === \"Date\" &&\n hasProperty(value, \"year\") &&\n typeof value.year === \"number\" &&\n hasProperty(value, \"month\") &&\n typeof value.month === \"number\" &&\n hasProperty(value, \"day\") &&\n typeof (value as {day: unknown}).day === \"number\"\n );\n}\n\n/**\n * Tests if the specified value is a {@link Date} object representing a valid\n * date.\n *\n * Returns `true` if the value has the shape of a `Date` object and the `year`,\n * `month`, and `day` fields are all integers inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n */\nexport function isValidDate(value: unknown): value is Date {\n return isDate(value) && isValid(value);\n}\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers inside the\n * valid range.\n *\n * Dates returned by functions in this library are always valid.\n */\nexport function isValid(date: DateOptions): boolean {\n return (\n (!hasProperty(date, \"type\") || date.type === \"Date\") &&\n isInteger(date.year) &&\n isIntegerInRange(date.month, JANUARY, DECEMBER) &&\n isIntegerInRange(date.day, 1, daysInMonth(date.month, date.year))\n );\n}\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers\n * inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link isValid}, useful for disambiguation from similar functions\n * that operate on other types.\n */\nexport const isDateValid = isValid;\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers\n * inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link isValid}, useful for disambiguation from similar functions\n * that operate on other types.\n *\n * @deprecated Use {@link isDateValid} instead.\n */\nexport const dateIsValid = isValid;\n\n/**\n * Asserts that the specified {@link Date} object represents a valid date.\n *\n * Dates returned by functions in this library are always valid.\n *\n * @throws {Error} if any of the `year`, `month` or `day` fields are\n * non-integers or outside the valid range.\n */\nexport function validate(date: DateOptions): void {\n if (!isValid(date)) {\n throw new Error(\"Invalid date\");\n }\n}\n\n/**\n * Asserts that the specified {@link Date} object represents a valid date.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link validate}.\n *\n * @throws {Error} if any of the `year`, `month` or `day` fields are\n * non-integers or outside the valid range.\n */\nexport const validateDate = validate;\n\n/**\n * Constructs a normalized {@link Date} object from the specified `year`,\n * `month` and `day`.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers\n */\nexport function date(date: DateOptions): Date {\n return fromReferenceDays(toReferenceDays(date));\n}\n\n/**\n * Normalizes the specified {@link Date} object so that it represents a valid\n * date.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * Alias of {@link date}. Calling the function by this name instead might make\n * code clearer in cases where the purpose is to normalize an existing `Date`\n * object.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers */\nexport const normalize = date;\n\n/**\n * Normalizes the specified {@link Date} object so that it represents a valid date.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * Alias of {@link date}. Calling the function by this name instead might make\n * code clearer in cases where the purpose is to normalize an existing `Date`\n * object.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers */\nexport const normalizeDate = normalize;\n\n/**\n * Converts the specified {@link Date} to a count of the number of days since the\n * reference date of 1st January, 1 CE.\n */\nexport function toReferenceDays(date: Partial<DateOptions>): number {\n if (hasProperty(date, \"type\") && date.type !== \"Date\") {\n throw new TypeError();\n }\n\n const day = date.day ?? 1;\n const month = date.month ?? 1;\n const year = date.year ?? 1;\n\n const referenceMonths = (year - 1) * 12 + month - 1;\n\n return (\n Math.floor((referenceMonths * 365) / 12) +\n Math.floor((referenceMonths + 10) / 48) -\n Math.floor((referenceMonths + 10) / 1200) +\n Math.floor((referenceMonths + 10) / 4800) +\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [0, 1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0][(12 + (Math.floor(referenceMonths) % 12)) % 12]! +\n day -\n 1\n );\n}\n\n/**\n * Creates a {@link Date} corresponding to the specified count of the number\n * of days since the reference date of 1st January, 1 CE.\n *\n * @throws {Error} if `referenceDays` is non-finite.\n */\nexport function fromReferenceDays(referenceDays: number): Date {\n if (!isFinite(referenceDays)) {\n throw new Error(\"Invalid date\");\n }\n const rd = Math.floor(referenceDays);\n const quadricentennium = Math.floor((rd + 366) / 146097);\n const dayInQuadricentennium = rd + 366 - quadricentennium * 146097;\n const centuryInQuadricentennium =\n dayInQuadricentennium === 0 ? 0 : Math.floor((dayInQuadricentennium - 1) / 36524);\n const longCentury = centuryInQuadricentennium === 0;\n const dayInCentury =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n dayInQuadricentennium - [0, 36525, 73049, 109573][centuryInQuadricentennium]!;\n const quadrenniumInCentury = Math.floor(\n (dayInCentury + Number(centuryInQuadricentennium !== 0)) / 1461\n );\n const longQuadrennium = quadrenniumInCentury !== 0 || longCentury;\n const dayInQuadrennium =\n dayInCentury -\n quadrenniumInCentury * 1461 +\n Number(quadrenniumInCentury !== 0 && !longCentury);\n const yearInQuadrennium =\n dayInQuadrennium === 0 ? 0 : Math.floor((dayInQuadrennium - Number(longQuadrennium)) / 365);\n const dayInYear =\n dayInQuadrennium -\n yearInQuadrennium * 365 -\n Number(yearInQuadrennium !== 0 && longQuadrennium);\n const leapDay = Number(longQuadrennium && yearInQuadrennium === 0);\n\n const year =\n quadricentennium * 400 +\n centuryInQuadricentennium * 100 +\n quadrenniumInCentury * 4 +\n yearInQuadrennium;\n let month: number;\n let day: number;\n\n if (dayInYear < 181 + leapDay) {\n if (dayInYear < 90 + leapDay) {\n if (dayInYear < 31) {\n month = 1;\n day = dayInYear + 1;\n } else if (dayInYear < 59 + leapDay) {\n month = 2;\n day = dayInYear - 30;\n } else {\n month = 3;\n day = dayInYear - 58 - leapDay;\n }\n } else if (dayInYear < 120 + leapDay) {\n month = 4;\n day = dayInYear - 89 - leapDay;\n } else if (dayInYear < 151 + leapDay) {\n month = 5;\n day = dayInYear - 119 - leapDay;\n } else {\n month = 6;\n day = dayInYear - 150 - leapDay;\n }\n } else if (dayInYear < 273 + leapDay) {\n if (dayInYear < 212 + leapDay) {\n month = 7;\n day = dayInYear - 180 - leapDay;\n } else if (dayInYear < 243 + leapDay) {\n month = 8;\n day = dayInYear - 211 - leapDay;\n } else {\n month = 9;\n day = dayInYear - 242 - leapDay;\n }\n } else if (dayInYear < 304 + leapDay) {\n month = 10;\n day = dayInYear - 272 - leapDay;\n } else if (dayInYear < 334 + leapDay) {\n month = 11;\n day = dayInYear - 303 - leapDay;\n } else {\n month = 12;\n day = dayInYear - 333 - leapDay;\n }\n\n return {type: \"Date\", day, month, year};\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n */\nexport function equal(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) === toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Alias of {@link equal}, for disambiguation from other equality functions.\n */\nexport const datesEqual = equal;\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Curried variant of {@link equal}.\n */\nexport function equalFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => equal(a, b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Curried variant of {@link datesEqual}.\n */\nexport const datesEqualFn = equalFn;\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n */\nexport function notEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) !== toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Alias of {@link notEqual}, for disambiguation from other inequality functions.\n */\nexport const datesNotEqual = notEqual;\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Curried variant of {@link notEqual}.\n */\nexport function notEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => notEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Curried variant of {@link datesNotEqual}.\n */\nexport const datesNotEqualFn = notEqualFn;\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n */\nexport const compare: Comparator<DateOptions> = (a, b) => {\n const ad = toReferenceDays(a);\n const bd = toReferenceDays(b);\n\n if (ad < bd) {\n return Comparison.before;\n } else if (ad > bd) {\n return Comparison.after;\n } else if (ad === bd) {\n return Comparison.equal;\n } else {\n return Comparison.undefined;\n }\n};\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n *\n * Alias of {@link compare}, useful for disambiguation from other comparison\n * functions.\n */\nexport const compareDates = compare;\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n *\n * Curried variant of {@link compare}.\n */\nexport function compareFn(b: DateOptions): (a: DateOptions) => Comparison {\n return a => compare(a, b);\n}\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is before,\n * equal to, or after `b`.\n *\n * Curried variant of {@link compareDates}.\n */\nexport const compareDatesFn = compareFn;\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n */\nexport function before(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) < toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Alias of {@link before}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const dateBefore = before;\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Curried variant of {@link before}.\n */\nexport function beforeFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => before(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Curried variant of {@link dateBefore}.\n */\nexport const dateBeforeFn = beforeFn;\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n */\nexport function beforeOrEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) <= toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Alias of {@link beforeOrEqual}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const dateBeforeOrEqual = beforeOrEqual;\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Curried variant of {@link beforeOrEqual}.\n */\nexport function beforeOrEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => beforeOrEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Curried variant of {@link dateBeforeOrEqual}.\n */\nexport const dateBeforeOrEqualFn = beforeOrEqualFn;\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n */\nexport function after(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) > toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Alias of {@link after}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const dateAfter = after;\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Curried variant of {@link after}.\n */\nexport function afterFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => after(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Curried variant of {@link dateAfter}.\n */\nexport const dateAfterFn = afterFn;\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n */\nexport function afterOrEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) >= toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Alias of {@link afterOrEqual}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const dateAfterOrEqual = afterOrEqual;\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Curried variant of {@link afterOrEqual}.\n */\nexport function afterOrEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => afterOrEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Curried variant of {@link dateAfterOrEqual}.\n */\nexport const dateAfterOrEqualFn = afterOrEqualFn;\n\n/**\n * Compares two dates and returns the earlier of the two.\n */\nexport function earliest<T extends DateOptions, U extends DateOptions>(a: T, b: U): T | U {\n return after(a, b) ? b : a;\n}\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Alias of {@link earliest}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const earliestDate = earliest;\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Curried variant of {@link earliest}.\n */\nexport function earliestFn<T extends DateOptions, U extends DateOptions>(b: U): (a: T) => T | U {\n return a => earliest(a, b);\n}\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Curried variant of {@link earliestDate}.\n */\nexport const earliestDateFn = earliestFn;\n\n/**\n * Compares two dates and returns the later of the two.\n */\nexport function latest<T extends DateOptions, U extends DateOptions>(a: T, b: U): T | U {\n return before(a, b) ? b : a;\n}\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Alias of {@link latest}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const latestDate = latest;\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Curried variant of {@link latest}.\n */\nexport function latestFn<T extends DateOptions, U extends DateOptions>(b: U): (a: T) => T | U {\n return a => latest(a, b);\n}\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Curried variant of {@link latestDate}.\n */\nexport const latestDateFn = latestFn;\n\n/**\n * Returns today's date according to UTC.\n */\nexport function todayUtc(): Date {\n const today = new JsDate();\n return {\n type: \"Date\",\n day: today.getUTCDate(),\n month: today.getUTCMonth() + 1,\n year: today.getUTCFullYear()\n };\n}\n\n/**\n * Returns today's date, according to the device's local timezone.\n */\nexport function todayDeviceLocal(): Date {\n const today = new JsDate();\n return {\n type: \"Date\",\n day: today.getDate(),\n month: today.getMonth() + 1,\n year: today.getFullYear()\n };\n}\n\n/**\n * Returns today's date, according to the device's local timezone.\n *\n * Alias of {@link todayDeviceLocal}, retained for backwards compatibility.\n *\n * @deprecated Use {@link todayDeviceLocal} instead. This function has been\n * renamed to make it clear that the timezone used is the local timezone as\n * reported by the device.\n */\nexport const todayLocal = todayDeviceLocal;\n\n/**\n * Parses a {@link Date} from text in ISO 8601 format.\n *\n * The ISO 8601 text must not specify a time zone offset.\n *\n * If the specified text is not a valid ISO 8601 date then this function\n * returns `null`.\n *\n * Both extended `YYYY-MM-DD` and basic `YYYYMMDD` ISO 8601 formats are\n * accepted.\n */\nexport function parseIso8601(text: string): Date | null {\n const match = /^([+-]?\\d{4,})-?(\\d{2})-?(\\d{2})$/u.exec(text);\n if (match?.[1] == null || match[2] == null || match[3] == null) {\n return null;\n }\n\n const year = parseInt(match[1], 10);\n const month = parseInt(match[2], 10);\n const day = parseInt(match[3], 10);\n\n return {type: \"Date\", day, month, year};\n}\n\n/**\n * Parses a {@link Date} from text in ISO 8601 format.\n *\n * The ISO 8601 text must not specify a time zone offset.\n *\n * If the specified text is not a valid ISO 8601 date then this function\n * returns `null`.\n *\n * Both extended `YYYY-MM-DD` and basic `YYYYMMDD` ISO 8601 formats are\n * accepted.\n *\n * Alias of {@link parseIso8601}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const parseDateIso8601 = parseIso8601;\n\n/**\n * Formats the specified Date as IS0 8601 extended, e.g. `2021-05-01`.\n *\n * For other formats, see `@softwareventures/format-date`.\n */\nexport const formatIso8601 = format.iso8601;\n\n/**\n * Formats the specified Date as IS0 8601 extended, e.g. `2021-05-01`.\n *\n * For other formats, see `@softwareventures/format-date`.\n *\n * Alias of {@link formatIso8601}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const formatDateIso8601 = format.iso8601;\n"]}
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,uFAAuF;;;;AAGvF,uDAAqD;AACrD,wCAAyC;AACzC,6DAAmD;AACnD,wDAAwD;AACxD,qCAAoC;AACpC,uCAAiC;AA+DjC,0DAA0D;AAC7C,QAAA,OAAO,GAAG,CAAC,CAAC,CAAC,2DAA2D;AAErF,2DAA2D;AAC9C,QAAA,QAAQ,GAAG,CAAC,CA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AC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEnC,OAAO,EAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC;AAC5C,CAAC;AAXD,oCAWC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;GAIG;AACU,QAAA,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;AAE5C;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC","sourcesContent":["/** @file Data types and functions for working with dates in the Gregorian calendar. */\n\nimport type {Comparator} from \"@softwareventures/ordered\";\nimport {Comparison} from \"@softwareventures/ordered\";\nimport isInteger = require(\"is-integer\");\nimport isIntegerInRange from \"is-integer-in-range\";\nimport * as format from \"@softwareventures/format-date\";\nimport {hasProperty} from \"unknown\";\nimport {JsDate} from \"./js-date\";\n\n/** A date in the Gregorian calendar, with no associated time zone. */\nexport interface Date {\n /** Type discriminator identifying the object as a `Date`. */\n readonly type: \"Date\";\n /** The day of the month. Should be an integer in the range `1`-`31`. */\n day: number;\n /** The month of the year. Should be an integer in the range `1`-`12`. */\n month: number;\n /**\n * The year.\n *\n * Should be an integer.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to\n * npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\n year: number;\n}\n\n/**\n * Options required to construct a `Date`.\n *\n * An instance of {@link Date} may always be used in place of `DateOptions`.\n */\nexport interface DateOptions {\n /**\n * Type discriminator identifying the object as a `Date`.\n *\n * If specified, must be the string `\"Date\"`. This is to prevent errors\n * caused by a `DateTime` being accidentally passed to `Date` functions.\n */\n readonly type?: \"Date\";\n /** The day of the month. Should be in the range `1`-`31`. */\n readonly day: number;\n /** The month of the year. Should be in the range `1`-`12`. */\n readonly month: number;\n /**\n * The year.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to\n * npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\n readonly year: number;\n}\n\n/** The numeric representation of the month of January. */\nexport const JANUARY = 1; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of February. */\nexport const FEBRUARY = 2; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of March. */\nexport const MARCH = 3; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of April. */\nexport const APRIL = 4; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of May. */\nexport const MAY = 5; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of June. */\nexport const JUNE = 6; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of July. */\nexport const JULY = 7; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of August. */\nexport const AUGUST = 8; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of September. */\nexport const SEPTEMBER = 9; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of October. */\nexport const OCTOBER = 10; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of November. */\nexport const NOVEMBER = 11; // eslint-disable-line @typescript-eslint/naming-convention\n\n/** The numeric representation of the month of December. */\nexport const DECEMBER = 12; // eslint-disable-line @typescript-eslint/naming-convention\n\n/**\n * Tests if the specified year is a leap year. Returns `true` if it is,\n * otherwise `false`.\n *\n * Positive values represent years in the Common Era (CE/AD). For example\n * `2020` represents 2020 CE, the year this module was first published to npm.\n *\n * Negative values or zero represent years before the Common Era (BCE/BC).\n * Zero represents 1 BCE, `-1` represents 2 BCE, `-2` represents 3 BCE,\n * etc.\n *\n * Note that there is no year zero in the Gregorian calendar. The year\n * 1 BCE was immediately followed by 1 CE.\n */\nexport function isLeapYear(year: number): boolean {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\n/**\n * Returns the number of days in the specified month in the specified year.\n *\n * @param month - An integer representing the month, in the range `1` (January)\n * to `12` (December).\n *\n * @param year - An integer representing the year. Positive values represent\n * years in the Common Era (CE/AD). For example `2020` represents 2020 CE,\n * the year this module was first published to npm. Negative values or zero\n * represent years before the Common Era (BCE/BC). Zero represents 1 BCE,\n * `-1` represents 2 BCE, `-2` represents 3 BCE, etc. There is no year zero\n * in the Gregorian calendar. The year 1 BCE was immediately followed by 1\n * CE.\n */\nexport function daysInMonth(month: number, year: number): number {\n if (month < JANUARY || month > DECEMBER) {\n throw new Error(\"Invalid month\");\n } else if (month === FEBRUARY && isLeapYear(year)) {\n return 29;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]!;\n }\n}\n\n/**\n * Returns `true` if the specified value has the shape of a {@link Date}\n * object.\n *\n * The `year`, `month` and `day` fields may be non-integers or outside the\n * valid range, meaning that the object may not represent a valid date.\n *\n * To test if the object represents a valid date, call {@link isValid} or\n * {@link isValidDate}.\n */\nexport function isDate(value: unknown): value is Date {\n return (\n typeof value === \"object\" &&\n value != null &&\n hasProperty(value, \"type\") &&\n value.type === \"Date\" &&\n hasProperty(value, \"year\") &&\n typeof value.year === \"number\" &&\n hasProperty(value, \"month\") &&\n typeof value.month === \"number\" &&\n hasProperty(value, \"day\") &&\n typeof (value as {day: unknown}).day === \"number\"\n );\n}\n\n/**\n * Tests if the specified value is a {@link Date} object representing a valid\n * date.\n *\n * Returns `true` if the value has the shape of a `Date` object and the `year`,\n * `month`, and `day` fields are all integers inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n */\nexport function isValidDate(value: unknown): value is Date {\n return isDate(value) && isValid(value);\n}\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers inside the\n * valid range.\n *\n * Dates returned by functions in this library are always valid.\n */\nexport function isValid(date: DateOptions): boolean {\n return (\n (!hasProperty(date, \"type\") || date.type === \"Date\") &&\n isInteger(date.year) &&\n isIntegerInRange(date.month, JANUARY, DECEMBER) &&\n isIntegerInRange(date.day, 1, daysInMonth(date.month, date.year))\n );\n}\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers\n * inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link isValid}, useful for disambiguation from similar functions\n * that operate on other types.\n */\nexport const isDateValid = isValid;\n\n/**\n * Tests if the specified {@link Date} object represents a valid date.\n *\n * Returns `true` if the `year`, `month` and `day` fields are all integers\n * inside the valid range.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link isValid}, useful for disambiguation from similar functions\n * that operate on other types.\n *\n * @deprecated Use {@link isDateValid} instead.\n */\nexport const dateIsValid = isValid;\n\n/**\n * Asserts that the specified {@link Date} object represents a valid date.\n *\n * Dates returned by functions in this library are always valid.\n *\n * @throws {Error} if any of the `year`, `month` or `day` fields are\n * non-integers or outside the valid range.\n */\nexport function validate(date: DateOptions): void {\n if (!isValid(date)) {\n throw new Error(\"Invalid date\");\n }\n}\n\n/**\n * Asserts that the specified {@link Date} object represents a valid date.\n *\n * Dates returned by functions in this library are always valid.\n *\n * Alias of {@link validate}.\n *\n * @throws {Error} if any of the `year`, `month` or `day` fields are\n * non-integers or outside the valid range.\n */\nexport const validateDate = validate;\n\n/**\n * Constructs a normalized {@link Date} object from the specified `year`,\n * `month` and `day`.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers\n */\nexport function date(date: DateOptions): Date {\n return fromReferenceDays(toReferenceDays(date));\n}\n\n/**\n * Normalizes the specified {@link Date} object so that it represents a valid\n * date.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * Alias of {@link date}. Calling the function by this name instead might make\n * code clearer in cases where the purpose is to normalize an existing `Date`\n * object.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers */\nexport const normalize = date;\n\n/**\n * Normalizes the specified {@link Date} object so that it represents a valid date.\n *\n * If the `month` or `day` fields are outside the valid range, then they will\n * roll over into the next month or year.\n *\n * Alias of {@link date}. Calling the function by this name instead might make\n * code clearer in cases where the purpose is to normalize an existing `Date`\n * object.\n *\n * @throws {Error} if the `year`, `month` or `day` fields are not finite\n * numbers */\nexport const normalizeDate = normalize;\n\n/**\n * Converts the specified {@link Date} to a count of the number of days since the\n * reference date of 1st January, 1 CE.\n */\nexport function toReferenceDays(date: Partial<DateOptions>): number {\n if (hasProperty(date, \"type\") && date.type !== \"Date\") {\n throw new TypeError();\n }\n\n const day = date.day ?? 1;\n const month = date.month ?? 1;\n const year = date.year ?? 1;\n\n const referenceMonths = (year - 1) * 12 + month - 1;\n\n return (\n Math.floor((referenceMonths * 365) / 12) +\n Math.floor((referenceMonths + 10) / 48) -\n Math.floor((referenceMonths + 10) / 1200) +\n Math.floor((referenceMonths + 10) / 4800) +\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [0, 1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0][(12 + (Math.floor(referenceMonths) % 12)) % 12]! +\n day -\n 1\n );\n}\n\n/**\n * Creates a {@link Date} corresponding to the specified count of the number\n * of days since the reference date of 1st January, 1 CE.\n *\n * @throws {Error} if `referenceDays` is non-finite.\n */\nexport function fromReferenceDays(referenceDays: number): Date {\n if (!isFinite(referenceDays)) {\n throw new Error(\"Invalid date\");\n }\n const rd = Math.floor(referenceDays);\n const quadricentennium = Math.floor((rd + 366) / 146097);\n const dayInQuadricentennium = rd + 366 - quadricentennium * 146097;\n const centuryInQuadricentennium =\n dayInQuadricentennium === 0 ? 0 : Math.floor((dayInQuadricentennium - 1) / 36524);\n const longCentury = centuryInQuadricentennium === 0;\n const dayInCentury =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n dayInQuadricentennium - [0, 36525, 73049, 109573][centuryInQuadricentennium]!;\n const quadrenniumInCentury = Math.floor(\n (dayInCentury + Number(centuryInQuadricentennium !== 0)) / 1461\n );\n const longQuadrennium = quadrenniumInCentury !== 0 || longCentury;\n const dayInQuadrennium =\n dayInCentury -\n quadrenniumInCentury * 1461 +\n Number(quadrenniumInCentury !== 0 && !longCentury);\n const yearInQuadrennium =\n dayInQuadrennium === 0 ? 0 : Math.floor((dayInQuadrennium - Number(longQuadrennium)) / 365);\n const dayInYear =\n dayInQuadrennium -\n yearInQuadrennium * 365 -\n Number(yearInQuadrennium !== 0 && longQuadrennium);\n const leapDay = Number(longQuadrennium && yearInQuadrennium === 0);\n\n const year =\n quadricentennium * 400 +\n centuryInQuadricentennium * 100 +\n quadrenniumInCentury * 4 +\n yearInQuadrennium;\n let month: number;\n let day: number;\n\n if (dayInYear < 181 + leapDay) {\n if (dayInYear < 90 + leapDay) {\n if (dayInYear < 31) {\n month = 1;\n day = dayInYear + 1;\n } else if (dayInYear < 59 + leapDay) {\n month = 2;\n day = dayInYear - 30;\n } else {\n month = 3;\n day = dayInYear - 58 - leapDay;\n }\n } else if (dayInYear < 120 + leapDay) {\n month = 4;\n day = dayInYear - 89 - leapDay;\n } else if (dayInYear < 151 + leapDay) {\n month = 5;\n day = dayInYear - 119 - leapDay;\n } else {\n month = 6;\n day = dayInYear - 150 - leapDay;\n }\n } else if (dayInYear < 273 + leapDay) {\n if (dayInYear < 212 + leapDay) {\n month = 7;\n day = dayInYear - 180 - leapDay;\n } else if (dayInYear < 243 + leapDay) {\n month = 8;\n day = dayInYear - 211 - leapDay;\n } else {\n month = 9;\n day = dayInYear - 242 - leapDay;\n }\n } else if (dayInYear < 304 + leapDay) {\n month = 10;\n day = dayInYear - 272 - leapDay;\n } else if (dayInYear < 334 + leapDay) {\n month = 11;\n day = dayInYear - 303 - leapDay;\n } else {\n month = 12;\n day = dayInYear - 333 - leapDay;\n }\n\n return {type: \"Date\", day, month, year};\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n */\nexport function equal(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) === toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Alias of {@link equal}, for disambiguation from other equality functions.\n */\nexport const datesEqual = equal;\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Curried variant of {@link equal}.\n */\nexport function equalFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => equal(a, b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to the same date.\n *\n * Curried variant of {@link datesEqual}.\n */\nexport const datesEqualFn = equalFn;\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n */\nexport function notEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) !== toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Alias of {@link notEqual}, for disambiguation from other inequality functions.\n */\nexport const datesNotEqual = notEqual;\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Curried variant of {@link notEqual}.\n */\nexport function notEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => notEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` and `b` refer to different dates.\n *\n * Curried variant of {@link datesNotEqual}.\n */\nexport const datesNotEqualFn = notEqualFn;\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n */\nexport const compare: Comparator<DateOptions> = (a, b) => {\n const ad = toReferenceDays(a);\n const bd = toReferenceDays(b);\n\n if (ad < bd) {\n return Comparison.before;\n } else if (ad > bd) {\n return Comparison.after;\n } else if (ad === bd) {\n return Comparison.equal;\n } else {\n return Comparison.undefined;\n }\n};\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n *\n * Alias of {@link compare}, useful for disambiguation from other comparison\n * functions.\n */\nexport const compareDates = compare;\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is\n * before, equal to, or after `b`.\n *\n * Curried variant of {@link compare}.\n */\nexport function compareFn(b: DateOptions): (a: DateOptions) => Comparison {\n return a => compare(a, b);\n}\n\n/**\n * Compares two dates and returns a {@link Comparison} specifying if `a` is before,\n * equal to, or after `b`.\n *\n * Curried variant of {@link compareDates}.\n */\nexport const compareDatesFn = compareFn;\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n */\nexport function before(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) < toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Alias of {@link before}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const dateBefore = before;\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Curried variant of {@link before}.\n */\nexport function beforeFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => before(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before `b`.\n *\n * Curried variant of {@link dateBefore}.\n */\nexport const dateBeforeFn = beforeFn;\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n */\nexport function beforeOrEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) <= toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Alias of {@link beforeOrEqual}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const dateBeforeOrEqual = beforeOrEqual;\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Curried variant of {@link beforeOrEqual}.\n */\nexport function beforeOrEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => beforeOrEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date before or the same as `b`.\n *\n * Curried variant of {@link dateBeforeOrEqual}.\n */\nexport const dateBeforeOrEqualFn = beforeOrEqualFn;\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n */\nexport function after(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) > toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Alias of {@link after}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n */\nexport const dateAfter = after;\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Curried variant of {@link after}.\n */\nexport function afterFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => after(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after `b`.\n *\n * Curried variant of {@link dateAfter}.\n */\nexport const dateAfterFn = afterFn;\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n */\nexport function afterOrEqual(a: DateOptions, b: DateOptions): boolean {\n return toReferenceDays(a) >= toReferenceDays(b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Alias of {@link afterOrEqual}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const dateAfterOrEqual = afterOrEqual;\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Curried variant of {@link afterOrEqual}.\n */\nexport function afterOrEqualFn(b: DateOptions): (a: DateOptions) => boolean {\n return a => afterOrEqual(a, b);\n}\n\n/**\n * Returns `true` if `a` refers to a date after or the same as `b`.\n *\n * Curried variant of {@link dateAfterOrEqual}.\n */\nexport const dateAfterOrEqualFn = afterOrEqualFn;\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport function earliest(a: DateOptions, b: DateOptions): Date {\n const ad = toReferenceDays(a);\n const bd = toReferenceDays(b);\n return fromReferenceDays(ad < bd ? ad : bd);\n}\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Alias of {@link earliest}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport const earliestDate = earliest;\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Curried variant of {@link earliest}.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport function earliestFn(b: DateOptions): (a: DateOptions) => Date {\n return a => earliest(a, b);\n}\n\n/**\n * Compares two dates and returns the earlier of the two.\n *\n * Curried variant of {@link earliestDate}.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport const earliestDateFn = earliestFn;\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport function latest(a: DateOptions, b: DateOptions): Date {\n const ad = toReferenceDays(a);\n const bd = toReferenceDays(b);\n return fromReferenceDays(ad > bd ? ad : bd);\n}\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Alias of {@link latest}, useful for disambiguation from similar functions\n * that operate on other date/time types.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport const latestDate = latest;\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Curried variant of {@link latest}.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport function latestFn(b: DateOptions): (a: DateOptions) => Date {\n return a => latest(a, b);\n}\n\n/**\n * Compares two dates and returns the later of the two.\n *\n * Curried variant of {@link latestDate}.\n *\n * @throws {Error} if both specified `Date`s contain numeric fields that\n * are non-finite.\n */\nexport const latestDateFn = latestFn;\n\n/**\n * Returns today's date according to UTC.\n */\nexport function todayUtc(): Date {\n const today = new JsDate();\n return {\n type: \"Date\",\n day: today.getUTCDate(),\n month: today.getUTCMonth() + 1,\n year: today.getUTCFullYear()\n };\n}\n\n/**\n * Returns today's date, according to the device's local timezone.\n */\nexport function todayDeviceLocal(): Date {\n const today = new JsDate();\n return {\n type: \"Date\",\n day: today.getDate(),\n month: today.getMonth() + 1,\n year: today.getFullYear()\n };\n}\n\n/**\n * Returns today's date, according to the device's local timezone.\n *\n * Alias of {@link todayDeviceLocal}, retained for backwards compatibility.\n *\n * @deprecated Use {@link todayDeviceLocal} instead. This function has been\n * renamed to make it clear that the timezone used is the local timezone as\n * reported by the device.\n */\nexport const todayLocal = todayDeviceLocal;\n\n/**\n * Parses a {@link Date} from text in ISO 8601 format.\n *\n * The ISO 8601 text must not specify a time zone offset.\n *\n * If the specified text is not a valid ISO 8601 date then this function\n * returns `null`.\n *\n * Both extended `YYYY-MM-DD` and basic `YYYYMMDD` ISO 8601 formats are\n * accepted.\n */\nexport function parseIso8601(text: string): Date | null {\n const match = /^([+-]?\\d{4,})-?(\\d{2})-?(\\d{2})$/u.exec(text);\n if (match?.[1] == null || match[2] == null || match[3] == null) {\n return null;\n }\n\n const year = parseInt(match[1], 10);\n const month = parseInt(match[2], 10);\n const day = parseInt(match[3], 10);\n\n return {type: \"Date\", day, month, year};\n}\n\n/**\n * Parses a {@link Date} from text in ISO 8601 format.\n *\n * The ISO 8601 text must not specify a time zone offset.\n *\n * If the specified text is not a valid ISO 8601 date then this function\n * returns `null`.\n *\n * Both extended `YYYY-MM-DD` and basic `YYYYMMDD` ISO 8601 formats are\n * accepted.\n *\n * Alias of {@link parseIso8601}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const parseDateIso8601 = parseIso8601;\n\n/**\n * Formats the specified Date as IS0 8601 extended, e.g. `2021-05-01`.\n *\n * For other formats, see `@softwareventures/format-date`.\n */\nexport const formatIso8601 = format.iso8601;\n\n/**\n * Formats the specified Date as IS0 8601 extended, e.g. `2021-05-01`.\n *\n * For other formats, see `@softwareventures/format-date`.\n *\n * Alias of {@link formatIso8601}, useful for disambiguation from similar\n * functions that operate on other date/time types.\n */\nexport const formatDateIso8601 = format.iso8601;\n"]}
{
"name": "@softwareventures/date",
"version": "4.1.1",
"version": "5.0.0",
"description": "An abstract date, with no associated time zone",

@@ -5,0 +5,0 @@ "keywords": [