Upload folder using huggingface_hub (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/date-fns/differenceInCalendarYears.d.cts +33 -0
- node_modules/date-fns/differenceInCalendarYears.d.ts +33 -0
- node_modules/date-fns/differenceInCalendarYears.js +39 -0
- node_modules/date-fns/differenceInDays.cjs +107 -0
- node_modules/date-fns/differenceInDays.d.cts +63 -0
- node_modules/date-fns/differenceInDays.d.ts +63 -0
- node_modules/date-fns/differenceInDays.js +108 -0
- node_modules/date-fns/differenceInHours.cjs +41 -0
- node_modules/date-fns/differenceInHours.d.cts +34 -0
- node_modules/date-fns/differenceInHours.d.ts +34 -0
- node_modules/date-fns/differenceInHours.js +42 -0
- node_modules/date-fns/differenceInISOWeekYears.cjs +65 -0
- node_modules/date-fns/differenceInISOWeekYears.d.cts +34 -0
- node_modules/date-fns/differenceInISOWeekYears.d.ts +34 -0
- node_modules/date-fns/differenceInISOWeekYears.js +58 -0
- node_modules/date-fns/differenceInMilliseconds.cjs +29 -0
- node_modules/date-fns/differenceInMilliseconds.d.cts +27 -0
- node_modules/date-fns/differenceInMilliseconds.d.ts +27 -0
- node_modules/date-fns/differenceInMilliseconds.js +30 -0
- node_modules/date-fns/differenceInMinutes.cjs +46 -0
- node_modules/date-fns/differenceInMinutes.d.cts +40 -0
- node_modules/date-fns/differenceInMinutes.d.ts +40 -0
- node_modules/date-fns/differenceInMinutes.js +46 -0
- node_modules/date-fns/differenceInMonths.cjs +57 -0
- node_modules/date-fns/differenceInMonths.d.cts +26 -0
- node_modules/date-fns/differenceInMonths.d.ts +26 -0
- node_modules/date-fns/differenceInMonths.js +61 -0
- node_modules/date-fns/differenceInQuarters.cjs +33 -0
- node_modules/date-fns/differenceInQuarters.d.cts +31 -0
- node_modules/date-fns/differenceInQuarters.d.ts +31 -0
- node_modules/date-fns/differenceInQuarters.js +33 -0
- node_modules/date-fns/differenceInSeconds.cjs +37 -0
- node_modules/date-fns/differenceInSeconds.d.cts +33 -0
- node_modules/date-fns/differenceInSeconds.d.ts +33 -0
- node_modules/date-fns/differenceInSeconds.js +37 -0
- node_modules/date-fns/differenceInWeeks.cjs +54 -0
- node_modules/date-fns/differenceInWeeks.d.cts +52 -0
- node_modules/date-fns/differenceInWeeks.d.ts +52 -0
- node_modules/date-fns/differenceInWeeks.js +54 -0
- node_modules/date-fns/differenceInYears.cjs +64 -0
- node_modules/date-fns/differenceInYears.d.cts +29 -0
- node_modules/date-fns/differenceInYears.d.ts +29 -0
- node_modules/date-fns/differenceInYears.js +63 -0
- node_modules/date-fns/docs/cdn.md +120 -0
- node_modules/date-fns/docs/config.d.ts +2 -0
- node_modules/date-fns/docs/config.js +135 -0
- node_modules/date-fns/docs/fp.md +72 -0
- node_modules/date-fns/docs/gettingStarted.md +76 -0
- node_modules/date-fns/docs/i18n.md +91 -0
- node_modules/date-fns/docs/i18nContributionGuide.md +1059 -0
node_modules/date-fns/differenceInCalendarYears.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInCalendarYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInCalendarYearsOptions
|
| 6 |
+
extends ContextOptions<Date> {}
|
| 7 |
+
/**
|
| 8 |
+
* @name differenceInCalendarYears
|
| 9 |
+
* @category Year Helpers
|
| 10 |
+
* @summary Get the number of calendar years between the given dates.
|
| 11 |
+
*
|
| 12 |
+
* @description
|
| 13 |
+
* Get the number of calendar years between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @param laterDate - The later date
|
| 16 |
+
* @param earlierDate - The earlier date
|
| 17 |
+
* @param options - An object with options
|
| 18 |
+
|
| 19 |
+
* @returns The number of calendar years
|
| 20 |
+
*
|
| 21 |
+
* @example
|
| 22 |
+
* // How many calendar years are between 31 December 2013 and 11 February 2015?
|
| 23 |
+
* const result = differenceInCalendarYears(
|
| 24 |
+
* new Date(2015, 1, 11),
|
| 25 |
+
* new Date(2013, 11, 31)
|
| 26 |
+
* );
|
| 27 |
+
* //=> 2
|
| 28 |
+
*/
|
| 29 |
+
export declare function differenceInCalendarYears(
|
| 30 |
+
laterDate: DateArg<Date> & {},
|
| 31 |
+
earlierDate: DateArg<Date> & {},
|
| 32 |
+
options?: DifferenceInCalendarYearsOptions | undefined,
|
| 33 |
+
): number;
|
node_modules/date-fns/differenceInCalendarYears.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInCalendarYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInCalendarYearsOptions
|
| 6 |
+
extends ContextOptions<Date> {}
|
| 7 |
+
/**
|
| 8 |
+
* @name differenceInCalendarYears
|
| 9 |
+
* @category Year Helpers
|
| 10 |
+
* @summary Get the number of calendar years between the given dates.
|
| 11 |
+
*
|
| 12 |
+
* @description
|
| 13 |
+
* Get the number of calendar years between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @param laterDate - The later date
|
| 16 |
+
* @param earlierDate - The earlier date
|
| 17 |
+
* @param options - An object with options
|
| 18 |
+
|
| 19 |
+
* @returns The number of calendar years
|
| 20 |
+
*
|
| 21 |
+
* @example
|
| 22 |
+
* // How many calendar years are between 31 December 2013 and 11 February 2015?
|
| 23 |
+
* const result = differenceInCalendarYears(
|
| 24 |
+
* new Date(2015, 1, 11),
|
| 25 |
+
* new Date(2013, 11, 31)
|
| 26 |
+
* );
|
| 27 |
+
* //=> 2
|
| 28 |
+
*/
|
| 29 |
+
export declare function differenceInCalendarYears(
|
| 30 |
+
laterDate: DateArg<Date> & {},
|
| 31 |
+
earlierDate: DateArg<Date> & {},
|
| 32 |
+
options?: DifferenceInCalendarYearsOptions | undefined,
|
| 33 |
+
): number;
|
node_modules/date-fns/differenceInCalendarYears.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* The {@link differenceInCalendarYears} function options.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* @name differenceInCalendarYears
|
| 9 |
+
* @category Year Helpers
|
| 10 |
+
* @summary Get the number of calendar years between the given dates.
|
| 11 |
+
*
|
| 12 |
+
* @description
|
| 13 |
+
* Get the number of calendar years between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @param laterDate - The later date
|
| 16 |
+
* @param earlierDate - The earlier date
|
| 17 |
+
* @param options - An object with options
|
| 18 |
+
|
| 19 |
+
* @returns The number of calendar years
|
| 20 |
+
*
|
| 21 |
+
* @example
|
| 22 |
+
* // How many calendar years are between 31 December 2013 and 11 February 2015?
|
| 23 |
+
* const result = differenceInCalendarYears(
|
| 24 |
+
* new Date(2015, 1, 11),
|
| 25 |
+
* new Date(2013, 11, 31)
|
| 26 |
+
* );
|
| 27 |
+
* //=> 2
|
| 28 |
+
*/
|
| 29 |
+
export function differenceInCalendarYears(laterDate, earlierDate, options) {
|
| 30 |
+
const [laterDate_, earlierDate_] = normalizeDates(
|
| 31 |
+
options?.in,
|
| 32 |
+
laterDate,
|
| 33 |
+
earlierDate,
|
| 34 |
+
);
|
| 35 |
+
return laterDate_.getFullYear() - earlierDate_.getFullYear();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// Fallback for modularized imports:
|
| 39 |
+
export default differenceInCalendarYears;
|
node_modules/date-fns/differenceInDays.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInDays = differenceInDays;
|
| 3 |
+
var _index = require("./_lib/normalizeDates.cjs");
|
| 4 |
+
var _index2 = require("./differenceInCalendarDays.cjs");
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInDays} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInDays
|
| 12 |
+
* @category Day Helpers
|
| 13 |
+
* @summary Get the number of full days between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @description
|
| 16 |
+
* Get the number of full day periods between two dates. Fractional days are
|
| 17 |
+
* truncated towards zero.
|
| 18 |
+
*
|
| 19 |
+
* One "full day" is the distance between a local time in one day to the same
|
| 20 |
+
* local time on the next or previous day. A full day can sometimes be less than
|
| 21 |
+
* or more than 24 hours if a daylight savings change happens between two dates.
|
| 22 |
+
*
|
| 23 |
+
* To ignore DST and only measure exact 24-hour periods, use this instead:
|
| 24 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
|
| 25 |
+
*
|
| 26 |
+
* @param laterDate - The later date
|
| 27 |
+
* @param earlierDate - The earlier date
|
| 28 |
+
* @param options - An object with options
|
| 29 |
+
*
|
| 30 |
+
* @returns The number of full days according to the local timezone
|
| 31 |
+
*
|
| 32 |
+
* @example
|
| 33 |
+
* // How many full days are between
|
| 34 |
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
| 35 |
+
* const result = differenceInDays(
|
| 36 |
+
* new Date(2012, 6, 2, 0, 0),
|
| 37 |
+
* new Date(2011, 6, 2, 23, 0)
|
| 38 |
+
* )
|
| 39 |
+
* //=> 365
|
| 40 |
+
*
|
| 41 |
+
* @example
|
| 42 |
+
* // How many full days are between
|
| 43 |
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
| 44 |
+
* const result = differenceInDays(
|
| 45 |
+
* new Date(2011, 6, 3, 0, 1),
|
| 46 |
+
* new Date(2011, 6, 2, 23, 59)
|
| 47 |
+
* )
|
| 48 |
+
* //=> 0
|
| 49 |
+
*
|
| 50 |
+
* @example
|
| 51 |
+
* // How many full days are between
|
| 52 |
+
* // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
| 53 |
+
* // Note: because local time is used, the
|
| 54 |
+
* // result will always be 92 days, even in
|
| 55 |
+
* // time zones where DST starts and the
|
| 56 |
+
* // period has only 92*24-1 hours.
|
| 57 |
+
* const result = differenceInDays(
|
| 58 |
+
* new Date(2020, 5, 1),
|
| 59 |
+
* new Date(2020, 2, 1)
|
| 60 |
+
* )
|
| 61 |
+
* //=> 92
|
| 62 |
+
*/
|
| 63 |
+
function differenceInDays(laterDate, earlierDate, options) {
|
| 64 |
+
const [laterDate_, earlierDate_] = (0, _index.normalizeDates)(
|
| 65 |
+
options?.in,
|
| 66 |
+
laterDate,
|
| 67 |
+
earlierDate,
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
const sign = compareLocalAsc(laterDate_, earlierDate_);
|
| 71 |
+
const difference = Math.abs(
|
| 72 |
+
(0, _index2.differenceInCalendarDays)(laterDate_, earlierDate_),
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
laterDate_.setDate(laterDate_.getDate() - sign * difference);
|
| 76 |
+
|
| 77 |
+
// Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full
|
| 78 |
+
// If so, result must be decreased by 1 in absolute value
|
| 79 |
+
const isLastDayNotFull = Number(
|
| 80 |
+
compareLocalAsc(laterDate_, earlierDate_) === -sign,
|
| 81 |
+
);
|
| 82 |
+
|
| 83 |
+
const result = sign * (difference - isLastDayNotFull);
|
| 84 |
+
// Prevent negative zero
|
| 85 |
+
return result === 0 ? 0 : result;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// Like `compareAsc` but uses local time not UTC, which is needed
|
| 89 |
+
// for accurate equality comparisons of UTC timestamps that end up
|
| 90 |
+
// having the same representation in local time, e.g. one hour before
|
| 91 |
+
// DST ends vs. the instant that DST ends.
|
| 92 |
+
function compareLocalAsc(laterDate, earlierDate) {
|
| 93 |
+
const diff =
|
| 94 |
+
laterDate.getFullYear() - earlierDate.getFullYear() ||
|
| 95 |
+
laterDate.getMonth() - earlierDate.getMonth() ||
|
| 96 |
+
laterDate.getDate() - earlierDate.getDate() ||
|
| 97 |
+
laterDate.getHours() - earlierDate.getHours() ||
|
| 98 |
+
laterDate.getMinutes() - earlierDate.getMinutes() ||
|
| 99 |
+
laterDate.getSeconds() - earlierDate.getSeconds() ||
|
| 100 |
+
laterDate.getMilliseconds() - earlierDate.getMilliseconds();
|
| 101 |
+
|
| 102 |
+
if (diff < 0) return -1;
|
| 103 |
+
if (diff > 0) return 1;
|
| 104 |
+
|
| 105 |
+
// Return 0 if diff is 0; return NaN if diff is NaN
|
| 106 |
+
return diff;
|
| 107 |
+
}
|
node_modules/date-fns/differenceInDays.d.cts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInDays} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInDaysOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInDays
|
| 8 |
+
* @category Day Helpers
|
| 9 |
+
* @summary Get the number of full days between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full day periods between two dates. Fractional days are
|
| 13 |
+
* truncated towards zero.
|
| 14 |
+
*
|
| 15 |
+
* One "full day" is the distance between a local time in one day to the same
|
| 16 |
+
* local time on the next or previous day. A full day can sometimes be less than
|
| 17 |
+
* or more than 24 hours if a daylight savings change happens between two dates.
|
| 18 |
+
*
|
| 19 |
+
* To ignore DST and only measure exact 24-hour periods, use this instead:
|
| 20 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
|
| 21 |
+
*
|
| 22 |
+
* @param laterDate - The later date
|
| 23 |
+
* @param earlierDate - The earlier date
|
| 24 |
+
* @param options - An object with options
|
| 25 |
+
*
|
| 26 |
+
* @returns The number of full days according to the local timezone
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* // How many full days are between
|
| 30 |
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
| 31 |
+
* const result = differenceInDays(
|
| 32 |
+
* new Date(2012, 6, 2, 0, 0),
|
| 33 |
+
* new Date(2011, 6, 2, 23, 0)
|
| 34 |
+
* )
|
| 35 |
+
* //=> 365
|
| 36 |
+
*
|
| 37 |
+
* @example
|
| 38 |
+
* // How many full days are between
|
| 39 |
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
| 40 |
+
* const result = differenceInDays(
|
| 41 |
+
* new Date(2011, 6, 3, 0, 1),
|
| 42 |
+
* new Date(2011, 6, 2, 23, 59)
|
| 43 |
+
* )
|
| 44 |
+
* //=> 0
|
| 45 |
+
*
|
| 46 |
+
* @example
|
| 47 |
+
* // How many full days are between
|
| 48 |
+
* // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
| 49 |
+
* // Note: because local time is used, the
|
| 50 |
+
* // result will always be 92 days, even in
|
| 51 |
+
* // time zones where DST starts and the
|
| 52 |
+
* // period has only 92*24-1 hours.
|
| 53 |
+
* const result = differenceInDays(
|
| 54 |
+
* new Date(2020, 5, 1),
|
| 55 |
+
* new Date(2020, 2, 1)
|
| 56 |
+
* )
|
| 57 |
+
* //=> 92
|
| 58 |
+
*/
|
| 59 |
+
export declare function differenceInDays(
|
| 60 |
+
laterDate: DateArg<Date> & {},
|
| 61 |
+
earlierDate: DateArg<Date> & {},
|
| 62 |
+
options?: DifferenceInDaysOptions | undefined,
|
| 63 |
+
): number;
|
node_modules/date-fns/differenceInDays.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInDays} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInDaysOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInDays
|
| 8 |
+
* @category Day Helpers
|
| 9 |
+
* @summary Get the number of full days between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full day periods between two dates. Fractional days are
|
| 13 |
+
* truncated towards zero.
|
| 14 |
+
*
|
| 15 |
+
* One "full day" is the distance between a local time in one day to the same
|
| 16 |
+
* local time on the next or previous day. A full day can sometimes be less than
|
| 17 |
+
* or more than 24 hours if a daylight savings change happens between two dates.
|
| 18 |
+
*
|
| 19 |
+
* To ignore DST and only measure exact 24-hour periods, use this instead:
|
| 20 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
|
| 21 |
+
*
|
| 22 |
+
* @param laterDate - The later date
|
| 23 |
+
* @param earlierDate - The earlier date
|
| 24 |
+
* @param options - An object with options
|
| 25 |
+
*
|
| 26 |
+
* @returns The number of full days according to the local timezone
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* // How many full days are between
|
| 30 |
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
| 31 |
+
* const result = differenceInDays(
|
| 32 |
+
* new Date(2012, 6, 2, 0, 0),
|
| 33 |
+
* new Date(2011, 6, 2, 23, 0)
|
| 34 |
+
* )
|
| 35 |
+
* //=> 365
|
| 36 |
+
*
|
| 37 |
+
* @example
|
| 38 |
+
* // How many full days are between
|
| 39 |
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
| 40 |
+
* const result = differenceInDays(
|
| 41 |
+
* new Date(2011, 6, 3, 0, 1),
|
| 42 |
+
* new Date(2011, 6, 2, 23, 59)
|
| 43 |
+
* )
|
| 44 |
+
* //=> 0
|
| 45 |
+
*
|
| 46 |
+
* @example
|
| 47 |
+
* // How many full days are between
|
| 48 |
+
* // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
| 49 |
+
* // Note: because local time is used, the
|
| 50 |
+
* // result will always be 92 days, even in
|
| 51 |
+
* // time zones where DST starts and the
|
| 52 |
+
* // period has only 92*24-1 hours.
|
| 53 |
+
* const result = differenceInDays(
|
| 54 |
+
* new Date(2020, 5, 1),
|
| 55 |
+
* new Date(2020, 2, 1)
|
| 56 |
+
* )
|
| 57 |
+
* //=> 92
|
| 58 |
+
*/
|
| 59 |
+
export declare function differenceInDays(
|
| 60 |
+
laterDate: DateArg<Date> & {},
|
| 61 |
+
earlierDate: DateArg<Date> & {},
|
| 62 |
+
options?: DifferenceInDaysOptions | undefined,
|
| 63 |
+
): number;
|
node_modules/date-fns/differenceInDays.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 2 |
+
import { differenceInCalendarDays } from "./differenceInCalendarDays.js";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* The {@link differenceInDays} function options.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInDays
|
| 10 |
+
* @category Day Helpers
|
| 11 |
+
* @summary Get the number of full days between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of full day periods between two dates. Fractional days are
|
| 15 |
+
* truncated towards zero.
|
| 16 |
+
*
|
| 17 |
+
* One "full day" is the distance between a local time in one day to the same
|
| 18 |
+
* local time on the next or previous day. A full day can sometimes be less than
|
| 19 |
+
* or more than 24 hours if a daylight savings change happens between two dates.
|
| 20 |
+
*
|
| 21 |
+
* To ignore DST and only measure exact 24-hour periods, use this instead:
|
| 22 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
|
| 23 |
+
*
|
| 24 |
+
* @param laterDate - The later date
|
| 25 |
+
* @param earlierDate - The earlier date
|
| 26 |
+
* @param options - An object with options
|
| 27 |
+
*
|
| 28 |
+
* @returns The number of full days according to the local timezone
|
| 29 |
+
*
|
| 30 |
+
* @example
|
| 31 |
+
* // How many full days are between
|
| 32 |
+
* // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
| 33 |
+
* const result = differenceInDays(
|
| 34 |
+
* new Date(2012, 6, 2, 0, 0),
|
| 35 |
+
* new Date(2011, 6, 2, 23, 0)
|
| 36 |
+
* )
|
| 37 |
+
* //=> 365
|
| 38 |
+
*
|
| 39 |
+
* @example
|
| 40 |
+
* // How many full days are between
|
| 41 |
+
* // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
| 42 |
+
* const result = differenceInDays(
|
| 43 |
+
* new Date(2011, 6, 3, 0, 1),
|
| 44 |
+
* new Date(2011, 6, 2, 23, 59)
|
| 45 |
+
* )
|
| 46 |
+
* //=> 0
|
| 47 |
+
*
|
| 48 |
+
* @example
|
| 49 |
+
* // How many full days are between
|
| 50 |
+
* // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
| 51 |
+
* // Note: because local time is used, the
|
| 52 |
+
* // result will always be 92 days, even in
|
| 53 |
+
* // time zones where DST starts and the
|
| 54 |
+
* // period has only 92*24-1 hours.
|
| 55 |
+
* const result = differenceInDays(
|
| 56 |
+
* new Date(2020, 5, 1),
|
| 57 |
+
* new Date(2020, 2, 1)
|
| 58 |
+
* )
|
| 59 |
+
* //=> 92
|
| 60 |
+
*/
|
| 61 |
+
export function differenceInDays(laterDate, earlierDate, options) {
|
| 62 |
+
const [laterDate_, earlierDate_] = normalizeDates(
|
| 63 |
+
options?.in,
|
| 64 |
+
laterDate,
|
| 65 |
+
earlierDate,
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
const sign = compareLocalAsc(laterDate_, earlierDate_);
|
| 69 |
+
const difference = Math.abs(
|
| 70 |
+
differenceInCalendarDays(laterDate_, earlierDate_),
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
laterDate_.setDate(laterDate_.getDate() - sign * difference);
|
| 74 |
+
|
| 75 |
+
// Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full
|
| 76 |
+
// If so, result must be decreased by 1 in absolute value
|
| 77 |
+
const isLastDayNotFull = Number(
|
| 78 |
+
compareLocalAsc(laterDate_, earlierDate_) === -sign,
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
const result = sign * (difference - isLastDayNotFull);
|
| 82 |
+
// Prevent negative zero
|
| 83 |
+
return result === 0 ? 0 : result;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Like `compareAsc` but uses local time not UTC, which is needed
|
| 87 |
+
// for accurate equality comparisons of UTC timestamps that end up
|
| 88 |
+
// having the same representation in local time, e.g. one hour before
|
| 89 |
+
// DST ends vs. the instant that DST ends.
|
| 90 |
+
function compareLocalAsc(laterDate, earlierDate) {
|
| 91 |
+
const diff =
|
| 92 |
+
laterDate.getFullYear() - earlierDate.getFullYear() ||
|
| 93 |
+
laterDate.getMonth() - earlierDate.getMonth() ||
|
| 94 |
+
laterDate.getDate() - earlierDate.getDate() ||
|
| 95 |
+
laterDate.getHours() - earlierDate.getHours() ||
|
| 96 |
+
laterDate.getMinutes() - earlierDate.getMinutes() ||
|
| 97 |
+
laterDate.getSeconds() - earlierDate.getSeconds() ||
|
| 98 |
+
laterDate.getMilliseconds() - earlierDate.getMilliseconds();
|
| 99 |
+
|
| 100 |
+
if (diff < 0) return -1;
|
| 101 |
+
if (diff > 0) return 1;
|
| 102 |
+
|
| 103 |
+
// Return 0 if diff is 0; return NaN if diff is NaN
|
| 104 |
+
return diff;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// Fallback for modularized imports:
|
| 108 |
+
export default differenceInDays;
|
node_modules/date-fns/differenceInHours.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInHours = differenceInHours;
|
| 3 |
+
var _index = require("./_lib/getRoundingMethod.cjs");
|
| 4 |
+
var _index2 = require("./_lib/normalizeDates.cjs");
|
| 5 |
+
var _index3 = require("./constants.cjs");
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* The {@link differenceInHours} function options.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @name differenceInHours
|
| 13 |
+
* @category Hour Helpers
|
| 14 |
+
* @summary Get the number of hours between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @description
|
| 17 |
+
* Get the number of hours between the given dates.
|
| 18 |
+
*
|
| 19 |
+
* @param laterDate - The later date
|
| 20 |
+
* @param earlierDate - The earlier date
|
| 21 |
+
* @param options - An object with options.
|
| 22 |
+
*
|
| 23 |
+
* @returns The number of hours
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
| 27 |
+
* const result = differenceInHours(
|
| 28 |
+
* new Date(2014, 6, 2, 19, 0),
|
| 29 |
+
* new Date(2014, 6, 2, 6, 50)
|
| 30 |
+
* )
|
| 31 |
+
* //=> 12
|
| 32 |
+
*/
|
| 33 |
+
function differenceInHours(laterDate, earlierDate, options) {
|
| 34 |
+
const [laterDate_, earlierDate_] = (0, _index2.normalizeDates)(
|
| 35 |
+
options?.in,
|
| 36 |
+
laterDate,
|
| 37 |
+
earlierDate,
|
| 38 |
+
);
|
| 39 |
+
const diff = (+laterDate_ - +earlierDate_) / _index3.millisecondsInHour;
|
| 40 |
+
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
| 41 |
+
}
|
node_modules/date-fns/differenceInHours.d.cts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInHours} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInHoursOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInHours
|
| 10 |
+
* @category Hour Helpers
|
| 11 |
+
* @summary Get the number of hours between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of hours between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of hours
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
| 24 |
+
* const result = differenceInHours(
|
| 25 |
+
* new Date(2014, 6, 2, 19, 0),
|
| 26 |
+
* new Date(2014, 6, 2, 6, 50)
|
| 27 |
+
* )
|
| 28 |
+
* //=> 12
|
| 29 |
+
*/
|
| 30 |
+
export declare function differenceInHours(
|
| 31 |
+
laterDate: DateArg<Date> & {},
|
| 32 |
+
earlierDate: DateArg<Date> & {},
|
| 33 |
+
options?: DifferenceInHoursOptions,
|
| 34 |
+
): number;
|
node_modules/date-fns/differenceInHours.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInHours} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInHoursOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInHours
|
| 10 |
+
* @category Hour Helpers
|
| 11 |
+
* @summary Get the number of hours between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of hours between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of hours
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
| 24 |
+
* const result = differenceInHours(
|
| 25 |
+
* new Date(2014, 6, 2, 19, 0),
|
| 26 |
+
* new Date(2014, 6, 2, 6, 50)
|
| 27 |
+
* )
|
| 28 |
+
* //=> 12
|
| 29 |
+
*/
|
| 30 |
+
export declare function differenceInHours(
|
| 31 |
+
laterDate: DateArg<Date> & {},
|
| 32 |
+
earlierDate: DateArg<Date> & {},
|
| 33 |
+
options?: DifferenceInHoursOptions,
|
| 34 |
+
): number;
|
node_modules/date-fns/differenceInHours.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
| 2 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 3 |
+
import { millisecondsInHour } from "./constants.js";
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* The {@link differenceInHours} function options.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @name differenceInHours
|
| 11 |
+
* @category Hour Helpers
|
| 12 |
+
* @summary Get the number of hours between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @description
|
| 15 |
+
* Get the number of hours between the given dates.
|
| 16 |
+
*
|
| 17 |
+
* @param laterDate - The later date
|
| 18 |
+
* @param earlierDate - The earlier date
|
| 19 |
+
* @param options - An object with options.
|
| 20 |
+
*
|
| 21 |
+
* @returns The number of hours
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
|
| 25 |
+
* const result = differenceInHours(
|
| 26 |
+
* new Date(2014, 6, 2, 19, 0),
|
| 27 |
+
* new Date(2014, 6, 2, 6, 50)
|
| 28 |
+
* )
|
| 29 |
+
* //=> 12
|
| 30 |
+
*/
|
| 31 |
+
export function differenceInHours(laterDate, earlierDate, options) {
|
| 32 |
+
const [laterDate_, earlierDate_] = normalizeDates(
|
| 33 |
+
options?.in,
|
| 34 |
+
laterDate,
|
| 35 |
+
earlierDate,
|
| 36 |
+
);
|
| 37 |
+
const diff = (+laterDate_ - +earlierDate_) / millisecondsInHour;
|
| 38 |
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Fallback for modularized imports:
|
| 42 |
+
export default differenceInHours;
|
node_modules/date-fns/differenceInISOWeekYears.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInISOWeekYears = differenceInISOWeekYears;
|
| 3 |
+
var _index = require("./_lib/normalizeDates.cjs");
|
| 4 |
+
var _index2 = require("./compareAsc.cjs");
|
| 5 |
+
var _index3 = require("./differenceInCalendarISOWeekYears.cjs");
|
| 6 |
+
var _index4 = require("./subISOWeekYears.cjs");
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* The {@link differenceInISOWeekYears} function options.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* @name differenceInISOWeekYears
|
| 14 |
+
* @category ISO Week-Numbering Year Helpers
|
| 15 |
+
* @summary Get the number of full ISO week-numbering years between the given dates.
|
| 16 |
+
*
|
| 17 |
+
* @description
|
| 18 |
+
* Get the number of full ISO week-numbering years between the given dates.
|
| 19 |
+
*
|
| 20 |
+
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
| 21 |
+
*
|
| 22 |
+
* @param laterDate - The later date
|
| 23 |
+
* @param earlierDate - The earlier date
|
| 24 |
+
* @param options - The options
|
| 25 |
+
*
|
| 26 |
+
* @returns The number of full ISO week-numbering years
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012?
|
| 30 |
+
* const result = differenceInISOWeekYears(
|
| 31 |
+
* new Date(2012, 0, 1),
|
| 32 |
+
* new Date(2010, 0, 1)
|
| 33 |
+
* )
|
| 34 |
+
* // => 1
|
| 35 |
+
*/
|
| 36 |
+
function differenceInISOWeekYears(laterDate, earlierDate, options) {
|
| 37 |
+
const [laterDate_, earlierDate_] = (0, _index.normalizeDates)(
|
| 38 |
+
options?.in,
|
| 39 |
+
laterDate,
|
| 40 |
+
earlierDate,
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
const sign = (0, _index2.compareAsc)(laterDate_, earlierDate_);
|
| 44 |
+
const diff = Math.abs(
|
| 45 |
+
(0, _index3.differenceInCalendarISOWeekYears)(
|
| 46 |
+
laterDate_,
|
| 47 |
+
earlierDate_,
|
| 48 |
+
options,
|
| 49 |
+
),
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
const adjustedDate = (0, _index4.subISOWeekYears)(
|
| 53 |
+
laterDate_,
|
| 54 |
+
sign * diff,
|
| 55 |
+
options,
|
| 56 |
+
);
|
| 57 |
+
|
| 58 |
+
const isLastISOWeekYearNotFull = Number(
|
| 59 |
+
(0, _index2.compareAsc)(adjustedDate, earlierDate_) === -sign,
|
| 60 |
+
);
|
| 61 |
+
const result = sign * (diff - isLastISOWeekYearNotFull);
|
| 62 |
+
|
| 63 |
+
// Prevent negative zero
|
| 64 |
+
return result === 0 ? 0 : result;
|
| 65 |
+
}
|
node_modules/date-fns/differenceInISOWeekYears.d.cts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInISOWeekYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInISOWeekYearsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInISOWeekYears
|
| 8 |
+
* @category ISO Week-Numbering Year Helpers
|
| 9 |
+
* @summary Get the number of full ISO week-numbering years between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full ISO week-numbering years between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - The options
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of full ISO week-numbering years
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012?
|
| 24 |
+
* const result = differenceInISOWeekYears(
|
| 25 |
+
* new Date(2012, 0, 1),
|
| 26 |
+
* new Date(2010, 0, 1)
|
| 27 |
+
* )
|
| 28 |
+
* // => 1
|
| 29 |
+
*/
|
| 30 |
+
export declare function differenceInISOWeekYears(
|
| 31 |
+
laterDate: DateArg<Date> & {},
|
| 32 |
+
earlierDate: DateArg<Date> & {},
|
| 33 |
+
options?: DifferenceInISOWeekYearsOptions | undefined,
|
| 34 |
+
): number;
|
node_modules/date-fns/differenceInISOWeekYears.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInISOWeekYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInISOWeekYearsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInISOWeekYears
|
| 8 |
+
* @category ISO Week-Numbering Year Helpers
|
| 9 |
+
* @summary Get the number of full ISO week-numbering years between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full ISO week-numbering years between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - The options
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of full ISO week-numbering years
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012?
|
| 24 |
+
* const result = differenceInISOWeekYears(
|
| 25 |
+
* new Date(2012, 0, 1),
|
| 26 |
+
* new Date(2010, 0, 1)
|
| 27 |
+
* )
|
| 28 |
+
* // => 1
|
| 29 |
+
*/
|
| 30 |
+
export declare function differenceInISOWeekYears(
|
| 31 |
+
laterDate: DateArg<Date> & {},
|
| 32 |
+
earlierDate: DateArg<Date> & {},
|
| 33 |
+
options?: DifferenceInISOWeekYearsOptions | undefined,
|
| 34 |
+
): number;
|
node_modules/date-fns/differenceInISOWeekYears.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 2 |
+
import { compareAsc } from "./compareAsc.js";
|
| 3 |
+
import { differenceInCalendarISOWeekYears } from "./differenceInCalendarISOWeekYears.js";
|
| 4 |
+
import { subISOWeekYears } from "./subISOWeekYears.js";
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInISOWeekYears} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInISOWeekYears
|
| 12 |
+
* @category ISO Week-Numbering Year Helpers
|
| 13 |
+
* @summary Get the number of full ISO week-numbering years between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @description
|
| 16 |
+
* Get the number of full ISO week-numbering years between the given dates.
|
| 17 |
+
*
|
| 18 |
+
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
| 19 |
+
*
|
| 20 |
+
* @param laterDate - The later date
|
| 21 |
+
* @param earlierDate - The earlier date
|
| 22 |
+
* @param options - The options
|
| 23 |
+
*
|
| 24 |
+
* @returns The number of full ISO week-numbering years
|
| 25 |
+
*
|
| 26 |
+
* @example
|
| 27 |
+
* // How many full ISO week-numbering years are between 1 January 2010 and 1 January 2012?
|
| 28 |
+
* const result = differenceInISOWeekYears(
|
| 29 |
+
* new Date(2012, 0, 1),
|
| 30 |
+
* new Date(2010, 0, 1)
|
| 31 |
+
* )
|
| 32 |
+
* // => 1
|
| 33 |
+
*/
|
| 34 |
+
export function differenceInISOWeekYears(laterDate, earlierDate, options) {
|
| 35 |
+
const [laterDate_, earlierDate_] = normalizeDates(
|
| 36 |
+
options?.in,
|
| 37 |
+
laterDate,
|
| 38 |
+
earlierDate,
|
| 39 |
+
);
|
| 40 |
+
|
| 41 |
+
const sign = compareAsc(laterDate_, earlierDate_);
|
| 42 |
+
const diff = Math.abs(
|
| 43 |
+
differenceInCalendarISOWeekYears(laterDate_, earlierDate_, options),
|
| 44 |
+
);
|
| 45 |
+
|
| 46 |
+
const adjustedDate = subISOWeekYears(laterDate_, sign * diff, options);
|
| 47 |
+
|
| 48 |
+
const isLastISOWeekYearNotFull = Number(
|
| 49 |
+
compareAsc(adjustedDate, earlierDate_) === -sign,
|
| 50 |
+
);
|
| 51 |
+
const result = sign * (diff - isLastISOWeekYearNotFull);
|
| 52 |
+
|
| 53 |
+
// Prevent negative zero
|
| 54 |
+
return result === 0 ? 0 : result;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Fallback for modularized imports:
|
| 58 |
+
export default differenceInISOWeekYears;
|
node_modules/date-fns/differenceInMilliseconds.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInMilliseconds = differenceInMilliseconds;
|
| 3 |
+
var _index = require("./toDate.cjs");
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* @name differenceInMilliseconds
|
| 7 |
+
* @category Millisecond Helpers
|
| 8 |
+
* @summary Get the number of milliseconds between the given dates.
|
| 9 |
+
*
|
| 10 |
+
* @description
|
| 11 |
+
* Get the number of milliseconds between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @param laterDate - The later date
|
| 14 |
+
* @param earlierDate - The earlier date
|
| 15 |
+
*
|
| 16 |
+
* @returns The number of milliseconds
|
| 17 |
+
*
|
| 18 |
+
* @example
|
| 19 |
+
* // How many milliseconds are between
|
| 20 |
+
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
| 21 |
+
* const result = differenceInMilliseconds(
|
| 22 |
+
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
| 23 |
+
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
| 24 |
+
* )
|
| 25 |
+
* //=> 1100
|
| 26 |
+
*/
|
| 27 |
+
function differenceInMilliseconds(laterDate, earlierDate) {
|
| 28 |
+
return +(0, _index.toDate)(laterDate) - +(0, _index.toDate)(earlierDate);
|
| 29 |
+
}
|
node_modules/date-fns/differenceInMilliseconds.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* @name differenceInMilliseconds
|
| 4 |
+
* @category Millisecond Helpers
|
| 5 |
+
* @summary Get the number of milliseconds between the given dates.
|
| 6 |
+
*
|
| 7 |
+
* @description
|
| 8 |
+
* Get the number of milliseconds between the given dates.
|
| 9 |
+
*
|
| 10 |
+
* @param laterDate - The later date
|
| 11 |
+
* @param earlierDate - The earlier date
|
| 12 |
+
*
|
| 13 |
+
* @returns The number of milliseconds
|
| 14 |
+
*
|
| 15 |
+
* @example
|
| 16 |
+
* // How many milliseconds are between
|
| 17 |
+
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
| 18 |
+
* const result = differenceInMilliseconds(
|
| 19 |
+
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
| 20 |
+
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
| 21 |
+
* )
|
| 22 |
+
* //=> 1100
|
| 23 |
+
*/
|
| 24 |
+
export declare function differenceInMilliseconds(
|
| 25 |
+
laterDate: DateArg<Date> & {},
|
| 26 |
+
earlierDate: DateArg<Date> & {},
|
| 27 |
+
): number;
|
node_modules/date-fns/differenceInMilliseconds.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* @name differenceInMilliseconds
|
| 4 |
+
* @category Millisecond Helpers
|
| 5 |
+
* @summary Get the number of milliseconds between the given dates.
|
| 6 |
+
*
|
| 7 |
+
* @description
|
| 8 |
+
* Get the number of milliseconds between the given dates.
|
| 9 |
+
*
|
| 10 |
+
* @param laterDate - The later date
|
| 11 |
+
* @param earlierDate - The earlier date
|
| 12 |
+
*
|
| 13 |
+
* @returns The number of milliseconds
|
| 14 |
+
*
|
| 15 |
+
* @example
|
| 16 |
+
* // How many milliseconds are between
|
| 17 |
+
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
| 18 |
+
* const result = differenceInMilliseconds(
|
| 19 |
+
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
| 20 |
+
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
| 21 |
+
* )
|
| 22 |
+
* //=> 1100
|
| 23 |
+
*/
|
| 24 |
+
export declare function differenceInMilliseconds(
|
| 25 |
+
laterDate: DateArg<Date> & {},
|
| 26 |
+
earlierDate: DateArg<Date> & {},
|
| 27 |
+
): number;
|
node_modules/date-fns/differenceInMilliseconds.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { toDate } from "./toDate.js";
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* @name differenceInMilliseconds
|
| 5 |
+
* @category Millisecond Helpers
|
| 6 |
+
* @summary Get the number of milliseconds between the given dates.
|
| 7 |
+
*
|
| 8 |
+
* @description
|
| 9 |
+
* Get the number of milliseconds between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @param laterDate - The later date
|
| 12 |
+
* @param earlierDate - The earlier date
|
| 13 |
+
*
|
| 14 |
+
* @returns The number of milliseconds
|
| 15 |
+
*
|
| 16 |
+
* @example
|
| 17 |
+
* // How many milliseconds are between
|
| 18 |
+
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
| 19 |
+
* const result = differenceInMilliseconds(
|
| 20 |
+
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
| 21 |
+
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
| 22 |
+
* )
|
| 23 |
+
* //=> 1100
|
| 24 |
+
*/
|
| 25 |
+
export function differenceInMilliseconds(laterDate, earlierDate) {
|
| 26 |
+
return +toDate(laterDate) - +toDate(earlierDate);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Fallback for modularized imports:
|
| 30 |
+
export default differenceInMilliseconds;
|
node_modules/date-fns/differenceInMinutes.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInMinutes = differenceInMinutes;
|
| 3 |
+
var _index = require("./_lib/getRoundingMethod.cjs");
|
| 4 |
+
var _index2 = require("./constants.cjs");
|
| 5 |
+
var _index3 = require("./differenceInMilliseconds.cjs");
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* The {@link differenceInMinutes} function options.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @name differenceInMinutes
|
| 13 |
+
* @category Minute Helpers
|
| 14 |
+
* @summary Get the number of minutes between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @description
|
| 17 |
+
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
| 18 |
+
*
|
| 19 |
+
* @param dateLeft - The later date
|
| 20 |
+
* @param dateRight - The earlier date
|
| 21 |
+
* @param options - An object with options.
|
| 22 |
+
*
|
| 23 |
+
* @returns The number of minutes
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
| 27 |
+
* const result = differenceInMinutes(
|
| 28 |
+
* new Date(2014, 6, 2, 12, 20, 0),
|
| 29 |
+
* new Date(2014, 6, 2, 12, 7, 59)
|
| 30 |
+
* )
|
| 31 |
+
* //=> 12
|
| 32 |
+
*
|
| 33 |
+
* @example
|
| 34 |
+
* // How many minutes are between 10:01:59 and 10:00:00
|
| 35 |
+
* const result = differenceInMinutes(
|
| 36 |
+
* new Date(2000, 0, 1, 10, 0, 0),
|
| 37 |
+
* new Date(2000, 0, 1, 10, 1, 59)
|
| 38 |
+
* )
|
| 39 |
+
* //=> -1
|
| 40 |
+
*/
|
| 41 |
+
function differenceInMinutes(dateLeft, dateRight, options) {
|
| 42 |
+
const diff =
|
| 43 |
+
(0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
|
| 44 |
+
_index2.millisecondsInMinute;
|
| 45 |
+
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
| 46 |
+
}
|
node_modules/date-fns/differenceInMinutes.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInMinutes} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInMinutesOptions extends RoundingOptions {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInMinutes
|
| 8 |
+
* @category Minute Helpers
|
| 9 |
+
* @summary Get the number of minutes between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param dateLeft - The later date
|
| 15 |
+
* @param dateRight - The earlier date
|
| 16 |
+
* @param options - An object with options.
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of minutes
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
| 22 |
+
* const result = differenceInMinutes(
|
| 23 |
+
* new Date(2014, 6, 2, 12, 20, 0),
|
| 24 |
+
* new Date(2014, 6, 2, 12, 7, 59)
|
| 25 |
+
* )
|
| 26 |
+
* //=> 12
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* // How many minutes are between 10:01:59 and 10:00:00
|
| 30 |
+
* const result = differenceInMinutes(
|
| 31 |
+
* new Date(2000, 0, 1, 10, 0, 0),
|
| 32 |
+
* new Date(2000, 0, 1, 10, 1, 59)
|
| 33 |
+
* )
|
| 34 |
+
* //=> -1
|
| 35 |
+
*/
|
| 36 |
+
export declare function differenceInMinutes(
|
| 37 |
+
dateLeft: DateArg<Date> & {},
|
| 38 |
+
dateRight: DateArg<Date> & {},
|
| 39 |
+
options?: DifferenceInMinutesOptions,
|
| 40 |
+
): number;
|
node_modules/date-fns/differenceInMinutes.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInMinutes} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInMinutesOptions extends RoundingOptions {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInMinutes
|
| 8 |
+
* @category Minute Helpers
|
| 9 |
+
* @summary Get the number of minutes between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param dateLeft - The later date
|
| 15 |
+
* @param dateRight - The earlier date
|
| 16 |
+
* @param options - An object with options.
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of minutes
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
| 22 |
+
* const result = differenceInMinutes(
|
| 23 |
+
* new Date(2014, 6, 2, 12, 20, 0),
|
| 24 |
+
* new Date(2014, 6, 2, 12, 7, 59)
|
| 25 |
+
* )
|
| 26 |
+
* //=> 12
|
| 27 |
+
*
|
| 28 |
+
* @example
|
| 29 |
+
* // How many minutes are between 10:01:59 and 10:00:00
|
| 30 |
+
* const result = differenceInMinutes(
|
| 31 |
+
* new Date(2000, 0, 1, 10, 0, 0),
|
| 32 |
+
* new Date(2000, 0, 1, 10, 1, 59)
|
| 33 |
+
* )
|
| 34 |
+
* //=> -1
|
| 35 |
+
*/
|
| 36 |
+
export declare function differenceInMinutes(
|
| 37 |
+
dateLeft: DateArg<Date> & {},
|
| 38 |
+
dateRight: DateArg<Date> & {},
|
| 39 |
+
options?: DifferenceInMinutesOptions,
|
| 40 |
+
): number;
|
node_modules/date-fns/differenceInMinutes.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
| 2 |
+
import { millisecondsInMinute } from "./constants.js";
|
| 3 |
+
import { differenceInMilliseconds } from "./differenceInMilliseconds.js";
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* The {@link differenceInMinutes} function options.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @name differenceInMinutes
|
| 11 |
+
* @category Minute Helpers
|
| 12 |
+
* @summary Get the number of minutes between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @description
|
| 15 |
+
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
| 16 |
+
*
|
| 17 |
+
* @param dateLeft - The later date
|
| 18 |
+
* @param dateRight - The earlier date
|
| 19 |
+
* @param options - An object with options.
|
| 20 |
+
*
|
| 21 |
+
* @returns The number of minutes
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
| 25 |
+
* const result = differenceInMinutes(
|
| 26 |
+
* new Date(2014, 6, 2, 12, 20, 0),
|
| 27 |
+
* new Date(2014, 6, 2, 12, 7, 59)
|
| 28 |
+
* )
|
| 29 |
+
* //=> 12
|
| 30 |
+
*
|
| 31 |
+
* @example
|
| 32 |
+
* // How many minutes are between 10:01:59 and 10:00:00
|
| 33 |
+
* const result = differenceInMinutes(
|
| 34 |
+
* new Date(2000, 0, 1, 10, 0, 0),
|
| 35 |
+
* new Date(2000, 0, 1, 10, 1, 59)
|
| 36 |
+
* )
|
| 37 |
+
* //=> -1
|
| 38 |
+
*/
|
| 39 |
+
export function differenceInMinutes(dateLeft, dateRight, options) {
|
| 40 |
+
const diff =
|
| 41 |
+
differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
| 42 |
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// Fallback for modularized imports:
|
| 46 |
+
export default differenceInMinutes;
|
node_modules/date-fns/differenceInMonths.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInMonths = differenceInMonths;
|
| 3 |
+
var _index = require("./_lib/normalizeDates.cjs");
|
| 4 |
+
var _index2 = require("./compareAsc.cjs");
|
| 5 |
+
var _index3 = require("./differenceInCalendarMonths.cjs");
|
| 6 |
+
var _index4 = require("./isLastDayOfMonth.cjs");
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* The {@link differenceInMonths} function options.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* @name differenceInMonths
|
| 14 |
+
* @category Month Helpers
|
| 15 |
+
* @summary Get the number of full months between the given dates.
|
| 16 |
+
*
|
| 17 |
+
* @param laterDate - The later date
|
| 18 |
+
* @param earlierDate - The earlier date
|
| 19 |
+
* @param options - An object with options
|
| 20 |
+
*
|
| 21 |
+
* @returns The number of full months
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* // How many full months are between 31 January 2014 and 1 September 2014?
|
| 25 |
+
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
| 26 |
+
* //=> 7
|
| 27 |
+
*/
|
| 28 |
+
function differenceInMonths(laterDate, earlierDate, options) {
|
| 29 |
+
const [laterDate_, workingLaterDate, earlierDate_] = (0,
|
| 30 |
+
_index.normalizeDates)(options?.in, laterDate, laterDate, earlierDate);
|
| 31 |
+
|
| 32 |
+
const sign = (0, _index2.compareAsc)(workingLaterDate, earlierDate_);
|
| 33 |
+
const difference = Math.abs(
|
| 34 |
+
(0, _index3.differenceInCalendarMonths)(workingLaterDate, earlierDate_),
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
+
if (difference < 1) return 0;
|
| 38 |
+
|
| 39 |
+
if (workingLaterDate.getMonth() === 1 && workingLaterDate.getDate() > 27)
|
| 40 |
+
workingLaterDate.setDate(30);
|
| 41 |
+
|
| 42 |
+
workingLaterDate.setMonth(workingLaterDate.getMonth() - sign * difference);
|
| 43 |
+
|
| 44 |
+
let isLastMonthNotFull =
|
| 45 |
+
(0, _index2.compareAsc)(workingLaterDate, earlierDate_) === -sign;
|
| 46 |
+
|
| 47 |
+
if (
|
| 48 |
+
(0, _index4.isLastDayOfMonth)(laterDate_) &&
|
| 49 |
+
difference === 1 &&
|
| 50 |
+
(0, _index2.compareAsc)(laterDate_, earlierDate_) === 1
|
| 51 |
+
) {
|
| 52 |
+
isLastMonthNotFull = false;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
const result = sign * (difference - +isLastMonthNotFull);
|
| 56 |
+
return result === 0 ? 0 : result;
|
| 57 |
+
}
|
node_modules/date-fns/differenceInMonths.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInMonths} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInMonthsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInMonths
|
| 8 |
+
* @category Month Helpers
|
| 9 |
+
* @summary Get the number of full months between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @param laterDate - The later date
|
| 12 |
+
* @param earlierDate - The earlier date
|
| 13 |
+
* @param options - An object with options
|
| 14 |
+
*
|
| 15 |
+
* @returns The number of full months
|
| 16 |
+
*
|
| 17 |
+
* @example
|
| 18 |
+
* // How many full months are between 31 January 2014 and 1 September 2014?
|
| 19 |
+
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
| 20 |
+
* //=> 7
|
| 21 |
+
*/
|
| 22 |
+
export declare function differenceInMonths(
|
| 23 |
+
laterDate: DateArg<Date> & {},
|
| 24 |
+
earlierDate: DateArg<Date> & {},
|
| 25 |
+
options?: DifferenceInMonthsOptions | undefined,
|
| 26 |
+
): number;
|
node_modules/date-fns/differenceInMonths.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInMonths} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInMonthsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInMonths
|
| 8 |
+
* @category Month Helpers
|
| 9 |
+
* @summary Get the number of full months between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @param laterDate - The later date
|
| 12 |
+
* @param earlierDate - The earlier date
|
| 13 |
+
* @param options - An object with options
|
| 14 |
+
*
|
| 15 |
+
* @returns The number of full months
|
| 16 |
+
*
|
| 17 |
+
* @example
|
| 18 |
+
* // How many full months are between 31 January 2014 and 1 September 2014?
|
| 19 |
+
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
| 20 |
+
* //=> 7
|
| 21 |
+
*/
|
| 22 |
+
export declare function differenceInMonths(
|
| 23 |
+
laterDate: DateArg<Date> & {},
|
| 24 |
+
earlierDate: DateArg<Date> & {},
|
| 25 |
+
options?: DifferenceInMonthsOptions | undefined,
|
| 26 |
+
): number;
|
node_modules/date-fns/differenceInMonths.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 2 |
+
import { compareAsc } from "./compareAsc.js";
|
| 3 |
+
import { differenceInCalendarMonths } from "./differenceInCalendarMonths.js";
|
| 4 |
+
import { isLastDayOfMonth } from "./isLastDayOfMonth.js";
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInMonths} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInMonths
|
| 12 |
+
* @category Month Helpers
|
| 13 |
+
* @summary Get the number of full months between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @param laterDate - The later date
|
| 16 |
+
* @param earlierDate - The earlier date
|
| 17 |
+
* @param options - An object with options
|
| 18 |
+
*
|
| 19 |
+
* @returns The number of full months
|
| 20 |
+
*
|
| 21 |
+
* @example
|
| 22 |
+
* // How many full months are between 31 January 2014 and 1 September 2014?
|
| 23 |
+
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
|
| 24 |
+
* //=> 7
|
| 25 |
+
*/
|
| 26 |
+
export function differenceInMonths(laterDate, earlierDate, options) {
|
| 27 |
+
const [laterDate_, workingLaterDate, earlierDate_] = normalizeDates(
|
| 28 |
+
options?.in,
|
| 29 |
+
laterDate,
|
| 30 |
+
laterDate,
|
| 31 |
+
earlierDate,
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
const sign = compareAsc(workingLaterDate, earlierDate_);
|
| 35 |
+
const difference = Math.abs(
|
| 36 |
+
differenceInCalendarMonths(workingLaterDate, earlierDate_),
|
| 37 |
+
);
|
| 38 |
+
|
| 39 |
+
if (difference < 1) return 0;
|
| 40 |
+
|
| 41 |
+
if (workingLaterDate.getMonth() === 1 && workingLaterDate.getDate() > 27)
|
| 42 |
+
workingLaterDate.setDate(30);
|
| 43 |
+
|
| 44 |
+
workingLaterDate.setMonth(workingLaterDate.getMonth() - sign * difference);
|
| 45 |
+
|
| 46 |
+
let isLastMonthNotFull = compareAsc(workingLaterDate, earlierDate_) === -sign;
|
| 47 |
+
|
| 48 |
+
if (
|
| 49 |
+
isLastDayOfMonth(laterDate_) &&
|
| 50 |
+
difference === 1 &&
|
| 51 |
+
compareAsc(laterDate_, earlierDate_) === 1
|
| 52 |
+
) {
|
| 53 |
+
isLastMonthNotFull = false;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
const result = sign * (difference - +isLastMonthNotFull);
|
| 57 |
+
return result === 0 ? 0 : result;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Fallback for modularized imports:
|
| 61 |
+
export default differenceInMonths;
|
node_modules/date-fns/differenceInQuarters.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInQuarters = differenceInQuarters;
|
| 3 |
+
var _index = require("./_lib/getRoundingMethod.cjs");
|
| 4 |
+
var _index2 = require("./differenceInMonths.cjs");
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInQuarters} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInQuarters
|
| 12 |
+
* @category Quarter Helpers
|
| 13 |
+
* @summary Get the number of quarters between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @description
|
| 16 |
+
* Get the number of quarters between the given dates.
|
| 17 |
+
*
|
| 18 |
+
* @param laterDate - The later date
|
| 19 |
+
* @param earlierDate - The earlier date
|
| 20 |
+
* @param options - An object with options.
|
| 21 |
+
*
|
| 22 |
+
* @returns The number of full quarters
|
| 23 |
+
*
|
| 24 |
+
* @example
|
| 25 |
+
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
| 26 |
+
* const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
| 27 |
+
* //=> 2
|
| 28 |
+
*/
|
| 29 |
+
function differenceInQuarters(laterDate, earlierDate, options) {
|
| 30 |
+
const diff =
|
| 31 |
+
(0, _index2.differenceInMonths)(laterDate, earlierDate, options) / 3;
|
| 32 |
+
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
| 33 |
+
}
|
node_modules/date-fns/differenceInQuarters.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInQuarters} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInQuartersOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInQuarters
|
| 10 |
+
* @category Quarter Helpers
|
| 11 |
+
* @summary Get the number of quarters between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of quarters between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of full quarters
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
| 24 |
+
* const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
| 25 |
+
* //=> 2
|
| 26 |
+
*/
|
| 27 |
+
export declare function differenceInQuarters(
|
| 28 |
+
laterDate: DateArg<Date> & {},
|
| 29 |
+
earlierDate: DateArg<Date> & {},
|
| 30 |
+
options?: DifferenceInQuartersOptions | undefined,
|
| 31 |
+
): number;
|
node_modules/date-fns/differenceInQuarters.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInQuarters} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInQuartersOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInQuarters
|
| 10 |
+
* @category Quarter Helpers
|
| 11 |
+
* @summary Get the number of quarters between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of quarters between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of full quarters
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
| 24 |
+
* const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
| 25 |
+
* //=> 2
|
| 26 |
+
*/
|
| 27 |
+
export declare function differenceInQuarters(
|
| 28 |
+
laterDate: DateArg<Date> & {},
|
| 29 |
+
earlierDate: DateArg<Date> & {},
|
| 30 |
+
options?: DifferenceInQuartersOptions | undefined,
|
| 31 |
+
): number;
|
node_modules/date-fns/differenceInQuarters.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
| 2 |
+
import { differenceInMonths } from "./differenceInMonths.js";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* The {@link differenceInQuarters} function options.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInQuarters
|
| 10 |
+
* @category Quarter Helpers
|
| 11 |
+
* @summary Get the number of quarters between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of quarters between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of full quarters
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many full quarters are between 31 December 2013 and 2 July 2014?
|
| 24 |
+
* const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
|
| 25 |
+
* //=> 2
|
| 26 |
+
*/
|
| 27 |
+
export function differenceInQuarters(laterDate, earlierDate, options) {
|
| 28 |
+
const diff = differenceInMonths(laterDate, earlierDate, options) / 3;
|
| 29 |
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// Fallback for modularized imports:
|
| 33 |
+
export default differenceInQuarters;
|
node_modules/date-fns/differenceInSeconds.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInSeconds = differenceInSeconds;
|
| 3 |
+
var _index = require("./_lib/getRoundingMethod.cjs");
|
| 4 |
+
var _index2 = require("./differenceInMilliseconds.cjs");
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInSeconds} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInSeconds
|
| 12 |
+
* @category Second Helpers
|
| 13 |
+
* @summary Get the number of seconds between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @description
|
| 16 |
+
* Get the number of seconds between the given dates.
|
| 17 |
+
*
|
| 18 |
+
* @param laterDate - The later date
|
| 19 |
+
* @param earlierDate - The earlier date
|
| 20 |
+
* @param options - An object with options.
|
| 21 |
+
*
|
| 22 |
+
* @returns The number of seconds
|
| 23 |
+
*
|
| 24 |
+
* @example
|
| 25 |
+
* // How many seconds are between
|
| 26 |
+
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
| 27 |
+
* const result = differenceInSeconds(
|
| 28 |
+
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
| 29 |
+
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
| 30 |
+
* )
|
| 31 |
+
* //=> 12
|
| 32 |
+
*/
|
| 33 |
+
function differenceInSeconds(laterDate, earlierDate, options) {
|
| 34 |
+
const diff =
|
| 35 |
+
(0, _index2.differenceInMilliseconds)(laterDate, earlierDate) / 1000;
|
| 36 |
+
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
| 37 |
+
}
|
node_modules/date-fns/differenceInSeconds.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInSeconds} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInSecondsOptions extends RoundingOptions {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInSeconds
|
| 8 |
+
* @category Second Helpers
|
| 9 |
+
* @summary Get the number of seconds between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of seconds between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param laterDate - The later date
|
| 15 |
+
* @param earlierDate - The earlier date
|
| 16 |
+
* @param options - An object with options.
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of seconds
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many seconds are between
|
| 22 |
+
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
| 23 |
+
* const result = differenceInSeconds(
|
| 24 |
+
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
| 25 |
+
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
| 26 |
+
* )
|
| 27 |
+
* //=> 12
|
| 28 |
+
*/
|
| 29 |
+
export declare function differenceInSeconds(
|
| 30 |
+
laterDate: DateArg<Date> & {},
|
| 31 |
+
earlierDate: DateArg<Date> & {},
|
| 32 |
+
options?: DifferenceInSecondsOptions,
|
| 33 |
+
): number;
|
node_modules/date-fns/differenceInSeconds.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInSeconds} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInSecondsOptions extends RoundingOptions {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInSeconds
|
| 8 |
+
* @category Second Helpers
|
| 9 |
+
* @summary Get the number of seconds between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of seconds between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param laterDate - The later date
|
| 15 |
+
* @param earlierDate - The earlier date
|
| 16 |
+
* @param options - An object with options.
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of seconds
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many seconds are between
|
| 22 |
+
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
| 23 |
+
* const result = differenceInSeconds(
|
| 24 |
+
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
| 25 |
+
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
| 26 |
+
* )
|
| 27 |
+
* //=> 12
|
| 28 |
+
*/
|
| 29 |
+
export declare function differenceInSeconds(
|
| 30 |
+
laterDate: DateArg<Date> & {},
|
| 31 |
+
earlierDate: DateArg<Date> & {},
|
| 32 |
+
options?: DifferenceInSecondsOptions,
|
| 33 |
+
): number;
|
node_modules/date-fns/differenceInSeconds.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
| 2 |
+
import { differenceInMilliseconds } from "./differenceInMilliseconds.js";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* The {@link differenceInSeconds} function options.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInSeconds
|
| 10 |
+
* @category Second Helpers
|
| 11 |
+
* @summary Get the number of seconds between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of seconds between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @param laterDate - The later date
|
| 17 |
+
* @param earlierDate - The earlier date
|
| 18 |
+
* @param options - An object with options.
|
| 19 |
+
*
|
| 20 |
+
* @returns The number of seconds
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* // How many seconds are between
|
| 24 |
+
* // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
|
| 25 |
+
* const result = differenceInSeconds(
|
| 26 |
+
* new Date(2014, 6, 2, 12, 30, 20, 0),
|
| 27 |
+
* new Date(2014, 6, 2, 12, 30, 7, 999)
|
| 28 |
+
* )
|
| 29 |
+
* //=> 12
|
| 30 |
+
*/
|
| 31 |
+
export function differenceInSeconds(laterDate, earlierDate, options) {
|
| 32 |
+
const diff = differenceInMilliseconds(laterDate, earlierDate) / 1000;
|
| 33 |
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Fallback for modularized imports:
|
| 37 |
+
export default differenceInSeconds;
|
node_modules/date-fns/differenceInWeeks.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInWeeks = differenceInWeeks;
|
| 3 |
+
var _index = require("./_lib/getRoundingMethod.cjs");
|
| 4 |
+
var _index2 = require("./differenceInDays.cjs");
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* The {@link differenceInWeeks} function options.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @name differenceInWeeks
|
| 12 |
+
* @category Week Helpers
|
| 13 |
+
* @summary Get the number of full weeks between the given dates.
|
| 14 |
+
*
|
| 15 |
+
* @description
|
| 16 |
+
* Get the number of full weeks between two dates. Fractional weeks are
|
| 17 |
+
* truncated towards zero by default.
|
| 18 |
+
*
|
| 19 |
+
* One "full week" is the distance between a local time in one day to the same
|
| 20 |
+
* local time 7 days earlier or later. A full week can sometimes be less than
|
| 21 |
+
* or more than 7*24 hours if a daylight savings change happens between two dates.
|
| 22 |
+
*
|
| 23 |
+
* To ignore DST and only measure exact 7*24-hour periods, use this instead:
|
| 24 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`.
|
| 25 |
+
*
|
| 26 |
+
* @param laterDate - The later date
|
| 27 |
+
* @param earlierDate - The earlier date
|
| 28 |
+
* @param options - An object with options
|
| 29 |
+
*
|
| 30 |
+
* @returns The number of full weeks
|
| 31 |
+
*
|
| 32 |
+
* @example
|
| 33 |
+
* // How many full weeks are between 5 July 2014 and 20 July 2014?
|
| 34 |
+
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
|
| 35 |
+
* //=> 2
|
| 36 |
+
*
|
| 37 |
+
* @example
|
| 38 |
+
* // How many full weeks are between
|
| 39 |
+
* // 1 March 2020 0:00 and 6 June 2020 0:00 ?
|
| 40 |
+
* // Note: because local time is used, the
|
| 41 |
+
* // result will always be 8 weeks (54 days),
|
| 42 |
+
* // even if DST starts and the period has
|
| 43 |
+
* // only 54*24-1 hours.
|
| 44 |
+
* const result = differenceInWeeks(
|
| 45 |
+
* new Date(2020, 5, 1),
|
| 46 |
+
* new Date(2020, 2, 6)
|
| 47 |
+
* )
|
| 48 |
+
* //=> 8
|
| 49 |
+
*/
|
| 50 |
+
function differenceInWeeks(laterDate, earlierDate, options) {
|
| 51 |
+
const diff =
|
| 52 |
+
(0, _index2.differenceInDays)(laterDate, earlierDate, options) / 7;
|
| 53 |
+
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
|
| 54 |
+
}
|
node_modules/date-fns/differenceInWeeks.d.cts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInWeeks} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInWeeksOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInWeeks
|
| 10 |
+
* @category Week Helpers
|
| 11 |
+
* @summary Get the number of full weeks between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of full weeks between two dates. Fractional weeks are
|
| 15 |
+
* truncated towards zero by default.
|
| 16 |
+
*
|
| 17 |
+
* One "full week" is the distance between a local time in one day to the same
|
| 18 |
+
* local time 7 days earlier or later. A full week can sometimes be less than
|
| 19 |
+
* or more than 7*24 hours if a daylight savings change happens between two dates.
|
| 20 |
+
*
|
| 21 |
+
* To ignore DST and only measure exact 7*24-hour periods, use this instead:
|
| 22 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`.
|
| 23 |
+
*
|
| 24 |
+
* @param laterDate - The later date
|
| 25 |
+
* @param earlierDate - The earlier date
|
| 26 |
+
* @param options - An object with options
|
| 27 |
+
*
|
| 28 |
+
* @returns The number of full weeks
|
| 29 |
+
*
|
| 30 |
+
* @example
|
| 31 |
+
* // How many full weeks are between 5 July 2014 and 20 July 2014?
|
| 32 |
+
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
|
| 33 |
+
* //=> 2
|
| 34 |
+
*
|
| 35 |
+
* @example
|
| 36 |
+
* // How many full weeks are between
|
| 37 |
+
* // 1 March 2020 0:00 and 6 June 2020 0:00 ?
|
| 38 |
+
* // Note: because local time is used, the
|
| 39 |
+
* // result will always be 8 weeks (54 days),
|
| 40 |
+
* // even if DST starts and the period has
|
| 41 |
+
* // only 54*24-1 hours.
|
| 42 |
+
* const result = differenceInWeeks(
|
| 43 |
+
* new Date(2020, 5, 1),
|
| 44 |
+
* new Date(2020, 2, 6)
|
| 45 |
+
* )
|
| 46 |
+
* //=> 8
|
| 47 |
+
*/
|
| 48 |
+
export declare function differenceInWeeks(
|
| 49 |
+
laterDate: DateArg<Date> & {},
|
| 50 |
+
earlierDate: DateArg<Date> & {},
|
| 51 |
+
options?: DifferenceInWeeksOptions | undefined,
|
| 52 |
+
): number;
|
node_modules/date-fns/differenceInWeeks.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg, RoundingOptions } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInWeeks} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInWeeksOptions
|
| 6 |
+
extends RoundingOptions,
|
| 7 |
+
ContextOptions<Date> {}
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInWeeks
|
| 10 |
+
* @category Week Helpers
|
| 11 |
+
* @summary Get the number of full weeks between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of full weeks between two dates. Fractional weeks are
|
| 15 |
+
* truncated towards zero by default.
|
| 16 |
+
*
|
| 17 |
+
* One "full week" is the distance between a local time in one day to the same
|
| 18 |
+
* local time 7 days earlier or later. A full week can sometimes be less than
|
| 19 |
+
* or more than 7*24 hours if a daylight savings change happens between two dates.
|
| 20 |
+
*
|
| 21 |
+
* To ignore DST and only measure exact 7*24-hour periods, use this instead:
|
| 22 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`.
|
| 23 |
+
*
|
| 24 |
+
* @param laterDate - The later date
|
| 25 |
+
* @param earlierDate - The earlier date
|
| 26 |
+
* @param options - An object with options
|
| 27 |
+
*
|
| 28 |
+
* @returns The number of full weeks
|
| 29 |
+
*
|
| 30 |
+
* @example
|
| 31 |
+
* // How many full weeks are between 5 July 2014 and 20 July 2014?
|
| 32 |
+
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
|
| 33 |
+
* //=> 2
|
| 34 |
+
*
|
| 35 |
+
* @example
|
| 36 |
+
* // How many full weeks are between
|
| 37 |
+
* // 1 March 2020 0:00 and 6 June 2020 0:00 ?
|
| 38 |
+
* // Note: because local time is used, the
|
| 39 |
+
* // result will always be 8 weeks (54 days),
|
| 40 |
+
* // even if DST starts and the period has
|
| 41 |
+
* // only 54*24-1 hours.
|
| 42 |
+
* const result = differenceInWeeks(
|
| 43 |
+
* new Date(2020, 5, 1),
|
| 44 |
+
* new Date(2020, 2, 6)
|
| 45 |
+
* )
|
| 46 |
+
* //=> 8
|
| 47 |
+
*/
|
| 48 |
+
export declare function differenceInWeeks(
|
| 49 |
+
laterDate: DateArg<Date> & {},
|
| 50 |
+
earlierDate: DateArg<Date> & {},
|
| 51 |
+
options?: DifferenceInWeeksOptions | undefined,
|
| 52 |
+
): number;
|
node_modules/date-fns/differenceInWeeks.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
| 2 |
+
import { differenceInDays } from "./differenceInDays.js";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* The {@link differenceInWeeks} function options.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* @name differenceInWeeks
|
| 10 |
+
* @category Week Helpers
|
| 11 |
+
* @summary Get the number of full weeks between the given dates.
|
| 12 |
+
*
|
| 13 |
+
* @description
|
| 14 |
+
* Get the number of full weeks between two dates. Fractional weeks are
|
| 15 |
+
* truncated towards zero by default.
|
| 16 |
+
*
|
| 17 |
+
* One "full week" is the distance between a local time in one day to the same
|
| 18 |
+
* local time 7 days earlier or later. A full week can sometimes be less than
|
| 19 |
+
* or more than 7*24 hours if a daylight savings change happens between two dates.
|
| 20 |
+
*
|
| 21 |
+
* To ignore DST and only measure exact 7*24-hour periods, use this instead:
|
| 22 |
+
* `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`.
|
| 23 |
+
*
|
| 24 |
+
* @param laterDate - The later date
|
| 25 |
+
* @param earlierDate - The earlier date
|
| 26 |
+
* @param options - An object with options
|
| 27 |
+
*
|
| 28 |
+
* @returns The number of full weeks
|
| 29 |
+
*
|
| 30 |
+
* @example
|
| 31 |
+
* // How many full weeks are between 5 July 2014 and 20 July 2014?
|
| 32 |
+
* const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
|
| 33 |
+
* //=> 2
|
| 34 |
+
*
|
| 35 |
+
* @example
|
| 36 |
+
* // How many full weeks are between
|
| 37 |
+
* // 1 March 2020 0:00 and 6 June 2020 0:00 ?
|
| 38 |
+
* // Note: because local time is used, the
|
| 39 |
+
* // result will always be 8 weeks (54 days),
|
| 40 |
+
* // even if DST starts and the period has
|
| 41 |
+
* // only 54*24-1 hours.
|
| 42 |
+
* const result = differenceInWeeks(
|
| 43 |
+
* new Date(2020, 5, 1),
|
| 44 |
+
* new Date(2020, 2, 6)
|
| 45 |
+
* )
|
| 46 |
+
* //=> 8
|
| 47 |
+
*/
|
| 48 |
+
export function differenceInWeeks(laterDate, earlierDate, options) {
|
| 49 |
+
const diff = differenceInDays(laterDate, earlierDate, options) / 7;
|
| 50 |
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// Fallback for modularized imports:
|
| 54 |
+
export default differenceInWeeks;
|
node_modules/date-fns/differenceInYears.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
exports.differenceInYears = differenceInYears;
|
| 3 |
+
var _index = require("./_lib/normalizeDates.cjs");
|
| 4 |
+
var _index2 = require("./compareAsc.cjs");
|
| 5 |
+
var _index3 = require("./differenceInCalendarYears.cjs");
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* The {@link differenceInYears} function options.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @name differenceInYears
|
| 13 |
+
* @category Year Helpers
|
| 14 |
+
* @summary Get the number of full years between the given dates.
|
| 15 |
+
*
|
| 16 |
+
* @description
|
| 17 |
+
* Get the number of full years between the given dates.
|
| 18 |
+
*
|
| 19 |
+
* @param laterDate - The later date
|
| 20 |
+
* @param earlierDate - The earlier date
|
| 21 |
+
* @param options - An object with options
|
| 22 |
+
*
|
| 23 |
+
* @returns The number of full years
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* // How many full years are between 31 December 2013 and 11 February 2015?
|
| 27 |
+
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
| 28 |
+
* //=> 1
|
| 29 |
+
*/
|
| 30 |
+
function differenceInYears(laterDate, earlierDate, options) {
|
| 31 |
+
const [laterDate_, earlierDate_] = (0, _index.normalizeDates)(
|
| 32 |
+
options?.in,
|
| 33 |
+
laterDate,
|
| 34 |
+
earlierDate,
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
+
// -1 if the left date is earlier than the right date
|
| 38 |
+
// 2023-12-31 - 2024-01-01 = -1
|
| 39 |
+
const sign = (0, _index2.compareAsc)(laterDate_, earlierDate_);
|
| 40 |
+
|
| 41 |
+
// First calculate the difference in calendar years
|
| 42 |
+
// 2024-01-01 - 2023-12-31 = 1 year
|
| 43 |
+
const diff = Math.abs(
|
| 44 |
+
(0, _index3.differenceInCalendarYears)(laterDate_, earlierDate_),
|
| 45 |
+
);
|
| 46 |
+
|
| 47 |
+
// Now we need to calculate if the difference is full. To do that we set
|
| 48 |
+
// both dates to the same year and check if the both date's month and day
|
| 49 |
+
// form a full year.
|
| 50 |
+
laterDate_.setFullYear(1584);
|
| 51 |
+
earlierDate_.setFullYear(1584);
|
| 52 |
+
|
| 53 |
+
// For it to be true, when the later date is indeed later than the earlier date
|
| 54 |
+
// (2026-02-01 - 2023-12-10 = 3 years), the difference is full if
|
| 55 |
+
// the normalized later date is also later than the normalized earlier date.
|
| 56 |
+
// In our example, 1584-02-01 is earlier than 1584-12-10, so the difference
|
| 57 |
+
// is partial, hence we need to subtract 1 from the difference 3 - 1 = 2.
|
| 58 |
+
const partial = (0, _index2.compareAsc)(laterDate_, earlierDate_) === -sign;
|
| 59 |
+
|
| 60 |
+
const result = sign * (diff - +partial);
|
| 61 |
+
|
| 62 |
+
// Prevent negative zero
|
| 63 |
+
return result === 0 ? 0 : result;
|
| 64 |
+
}
|
node_modules/date-fns/differenceInYears.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInYearsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInYears
|
| 8 |
+
* @category Year Helpers
|
| 9 |
+
* @summary Get the number of full years between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full years between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param laterDate - The later date
|
| 15 |
+
* @param earlierDate - The earlier date
|
| 16 |
+
* @param options - An object with options
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of full years
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many full years are between 31 December 2013 and 11 February 2015?
|
| 22 |
+
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
| 23 |
+
* //=> 1
|
| 24 |
+
*/
|
| 25 |
+
export declare function differenceInYears(
|
| 26 |
+
laterDate: DateArg<Date> & {},
|
| 27 |
+
earlierDate: DateArg<Date> & {},
|
| 28 |
+
options?: DifferenceInYearsOptions | undefined,
|
| 29 |
+
): number;
|
node_modules/date-fns/differenceInYears.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ContextOptions, DateArg } from "./types.ts";
|
| 2 |
+
/**
|
| 3 |
+
* The {@link differenceInYears} function options.
|
| 4 |
+
*/
|
| 5 |
+
export interface DifferenceInYearsOptions extends ContextOptions<Date> {}
|
| 6 |
+
/**
|
| 7 |
+
* @name differenceInYears
|
| 8 |
+
* @category Year Helpers
|
| 9 |
+
* @summary Get the number of full years between the given dates.
|
| 10 |
+
*
|
| 11 |
+
* @description
|
| 12 |
+
* Get the number of full years between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @param laterDate - The later date
|
| 15 |
+
* @param earlierDate - The earlier date
|
| 16 |
+
* @param options - An object with options
|
| 17 |
+
*
|
| 18 |
+
* @returns The number of full years
|
| 19 |
+
*
|
| 20 |
+
* @example
|
| 21 |
+
* // How many full years are between 31 December 2013 and 11 February 2015?
|
| 22 |
+
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
| 23 |
+
* //=> 1
|
| 24 |
+
*/
|
| 25 |
+
export declare function differenceInYears(
|
| 26 |
+
laterDate: DateArg<Date> & {},
|
| 27 |
+
earlierDate: DateArg<Date> & {},
|
| 28 |
+
options?: DifferenceInYearsOptions | undefined,
|
| 29 |
+
): number;
|
node_modules/date-fns/differenceInYears.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { normalizeDates } from "./_lib/normalizeDates.js";
|
| 2 |
+
import { compareAsc } from "./compareAsc.js";
|
| 3 |
+
import { differenceInCalendarYears } from "./differenceInCalendarYears.js";
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* The {@link differenceInYears} function options.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* @name differenceInYears
|
| 11 |
+
* @category Year Helpers
|
| 12 |
+
* @summary Get the number of full years between the given dates.
|
| 13 |
+
*
|
| 14 |
+
* @description
|
| 15 |
+
* Get the number of full years between the given dates.
|
| 16 |
+
*
|
| 17 |
+
* @param laterDate - The later date
|
| 18 |
+
* @param earlierDate - The earlier date
|
| 19 |
+
* @param options - An object with options
|
| 20 |
+
*
|
| 21 |
+
* @returns The number of full years
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* // How many full years are between 31 December 2013 and 11 February 2015?
|
| 25 |
+
* const result = differenceInYears(new Date(2015, 1, 11), new Date(2013, 11, 31))
|
| 26 |
+
* //=> 1
|
| 27 |
+
*/
|
| 28 |
+
export function differenceInYears(laterDate, earlierDate, options) {
|
| 29 |
+
const [laterDate_, earlierDate_] = normalizeDates(
|
| 30 |
+
options?.in,
|
| 31 |
+
laterDate,
|
| 32 |
+
earlierDate,
|
| 33 |
+
);
|
| 34 |
+
|
| 35 |
+
// -1 if the left date is earlier than the right date
|
| 36 |
+
// 2023-12-31 - 2024-01-01 = -1
|
| 37 |
+
const sign = compareAsc(laterDate_, earlierDate_);
|
| 38 |
+
|
| 39 |
+
// First calculate the difference in calendar years
|
| 40 |
+
// 2024-01-01 - 2023-12-31 = 1 year
|
| 41 |
+
const diff = Math.abs(differenceInCalendarYears(laterDate_, earlierDate_));
|
| 42 |
+
|
| 43 |
+
// Now we need to calculate if the difference is full. To do that we set
|
| 44 |
+
// both dates to the same year and check if the both date's month and day
|
| 45 |
+
// form a full year.
|
| 46 |
+
laterDate_.setFullYear(1584);
|
| 47 |
+
earlierDate_.setFullYear(1584);
|
| 48 |
+
|
| 49 |
+
// For it to be true, when the later date is indeed later than the earlier date
|
| 50 |
+
// (2026-02-01 - 2023-12-10 = 3 years), the difference is full if
|
| 51 |
+
// the normalized later date is also later than the normalized earlier date.
|
| 52 |
+
// In our example, 1584-02-01 is earlier than 1584-12-10, so the difference
|
| 53 |
+
// is partial, hence we need to subtract 1 from the difference 3 - 1 = 2.
|
| 54 |
+
const partial = compareAsc(laterDate_, earlierDate_) === -sign;
|
| 55 |
+
|
| 56 |
+
const result = sign * (diff - +partial);
|
| 57 |
+
|
| 58 |
+
// Prevent negative zero
|
| 59 |
+
return result === 0 ? 0 : result;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Fallback for modularized imports:
|
| 63 |
+
export default differenceInYears;
|
node_modules/date-fns/docs/cdn.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CDN
|
| 2 |
+
|
| 3 |
+
The CDN versions of date-fns are available as the [`@date-fns/cdn`](https://www.jsdelivr.com/package/npm/@date-fns/cdn) package on jsDelivr and other CDNs. They expose the date-fns functionality via the `window.dateFns` global variable.
|
| 4 |
+
|
| 5 |
+
> ⚠️ The legacy CDN files in the `date-fns` package are deprecated and will be removed in a future version. They remain available for compatibility, but they log a migration notice in the console. Please update your URLs from `date-fns` to `@date-fns/cdn`.
|
| 6 |
+
|
| 7 |
+
Unlike the npm package, the CDN is transpiled to be compatible with IE11, so it supports a wide variety of legacy browsers and environments.
|
| 8 |
+
|
| 9 |
+
```html
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
|
| 11 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/es/cdn.min.js"></script>
|
| 12 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/ru/cdn.min.js"></script>
|
| 13 |
+
<script>
|
| 14 |
+
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date());
|
| 15 |
+
//=> "last Friday at 7:26 p.m."
|
| 16 |
+
|
| 17 |
+
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
|
| 18 |
+
locale: dateFns.locale.es,
|
| 19 |
+
});
|
| 20 |
+
//=> "el viernes pasado a las 19:26"
|
| 21 |
+
|
| 22 |
+
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
|
| 23 |
+
locale: dateFns.locale.ru,
|
| 24 |
+
});
|
| 25 |
+
//=> "в прошлую пятницу в 19:26"
|
| 26 |
+
</script>
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Legacy URLs still work for now but should be replaced:
|
| 30 |
+
|
| 31 |
+
```diff
|
| 32 |
+
- https://cdn.jsdelivr.net/npm/date-fns@VERSION/cdn.min.js
|
| 33 |
+
+ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/cdn.min.js
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
The CDN versions are available for the main module, all & individual locales, and the FP submodule.
|
| 37 |
+
|
| 38 |
+
They come in two flavors: `cdn.js` and `cdn.min.js`. The latter is minified and should be used in production. The former is useful for debugging and development.
|
| 39 |
+
|
| 40 |
+
Keep in mind that using the CDN versions in production is suboptimal because they bundle all the date-fns functionality you will never use. It's much better to use the npm package and a tree-shaking-enabled bundler like webpack or Rollup. However, the CDN versions are helpful for quick prototyping, small projects, educational purposes, or working in a legacy environment.
|
| 41 |
+
|
| 42 |
+
## Main module
|
| 43 |
+
|
| 44 |
+
The main module with all functions bundled:
|
| 45 |
+
|
| 46 |
+
```
|
| 47 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/cdn.js
|
| 48 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/cdn.min.js
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
You can access it via the `dateFns` global variable:
|
| 52 |
+
|
| 53 |
+
```html
|
| 54 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
|
| 55 |
+
<script>
|
| 56 |
+
dateFns.addDays(new Date(2014, 1, 11), 10);
|
| 57 |
+
//=> Tue Feb 21 2014 00:00:00
|
| 58 |
+
</script>
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## The FP submodule
|
| 62 |
+
|
| 63 |
+
The FP submodule with all functions bundled:
|
| 64 |
+
|
| 65 |
+
```
|
| 66 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/fp/cdn.js
|
| 67 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/fp/cdn.min.js
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
You can access it via the `dateFns.fp` global variable:
|
| 71 |
+
|
| 72 |
+
```html
|
| 73 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/fp/cdn.min.js"></script>
|
| 74 |
+
<script>
|
| 75 |
+
dateFns.fp.addDays(10, new Date(2014, 1, 11));
|
| 76 |
+
//=> Tue Feb 21 2014 00:00:00
|
| 77 |
+
</script>
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## Locales
|
| 81 |
+
|
| 82 |
+
All locales bundled:
|
| 83 |
+
|
| 84 |
+
```
|
| 85 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/cdn.js
|
| 86 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/cdn.min.js
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
You can access them via the `dateFns.locale` global variable:
|
| 90 |
+
|
| 91 |
+
```html
|
| 92 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
|
| 93 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/cdn.min.js"></script>
|
| 94 |
+
<script>
|
| 95 |
+
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
|
| 96 |
+
locale: dateFns.locale.es,
|
| 97 |
+
});
|
| 98 |
+
//=> "el viernes pasado a las 19:26"
|
| 99 |
+
</script>
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
The locales are also available as individual files.
|
| 103 |
+
|
| 104 |
+
```
|
| 105 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/LOCALE/cdn.js
|
| 106 |
+
https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/LOCALE/cdn.min.js
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
You can access them via the `dateFns.locale.LOCALE` global variable:
|
| 110 |
+
|
| 111 |
+
```html
|
| 112 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
|
| 113 |
+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/es/cdn.min.js"></script>
|
| 114 |
+
<script>
|
| 115 |
+
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
|
| 116 |
+
locale: dateFns.locale.es,
|
| 117 |
+
});
|
| 118 |
+
//=> "el viernes pasado a las 19:26"
|
| 119 |
+
</script>
|
| 120 |
+
```
|
node_modules/date-fns/docs/config.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { DateFnsDocs } from "@date-fns/docs";
|
| 2 |
+
export declare const config: DateFnsDocs.Config;
|
node_modules/date-fns/docs/config.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('@date-fns/docs').DateFnsDocs.Config} */
|
| 2 |
+
export const config = {
|
| 3 |
+
package: "..",
|
| 4 |
+
|
| 5 |
+
json: "../tmp/docs.json",
|
| 6 |
+
|
| 7 |
+
categories: [
|
| 8 |
+
"General",
|
| 9 |
+
"Misc",
|
| 10 |
+
"Common Helpers",
|
| 11 |
+
"Conversion Helpers",
|
| 12 |
+
"Interval Helpers",
|
| 13 |
+
"Timestamp Helpers",
|
| 14 |
+
"Millisecond Helpers",
|
| 15 |
+
"Second Helpers",
|
| 16 |
+
"Minute Helpers",
|
| 17 |
+
"Hour Helpers",
|
| 18 |
+
"Day Helpers",
|
| 19 |
+
"Weekday Helpers",
|
| 20 |
+
"Week Helpers",
|
| 21 |
+
"ISO Week Helpers",
|
| 22 |
+
"Month Helpers",
|
| 23 |
+
"Quarter Helpers",
|
| 24 |
+
"Year Helpers",
|
| 25 |
+
"ISO Week-Numbering Year Helpers",
|
| 26 |
+
"Decade Helpers",
|
| 27 |
+
"Generic Helpers",
|
| 28 |
+
],
|
| 29 |
+
|
| 30 |
+
files: [
|
| 31 |
+
{
|
| 32 |
+
type: "markdown",
|
| 33 |
+
slug: "Getting-Started",
|
| 34 |
+
category: "General",
|
| 35 |
+
title: "Getting Started",
|
| 36 |
+
summary: "Introduction & installation instructions",
|
| 37 |
+
path: "gettingStarted.md",
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
type: "markdown",
|
| 41 |
+
slug: "Change-Log",
|
| 42 |
+
category: "General",
|
| 43 |
+
title: "Change Log",
|
| 44 |
+
summary: "Changes for each version of the library",
|
| 45 |
+
path: "../CHANGELOG.md",
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
type: "markdown",
|
| 49 |
+
slug: "Contributing",
|
| 50 |
+
category: "General",
|
| 51 |
+
title: "Contributing",
|
| 52 |
+
summary: "Contribution manual",
|
| 53 |
+
path: "../../../CONTRIBUTING.md",
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
type: "markdown",
|
| 57 |
+
slug: "Security",
|
| 58 |
+
category: "General",
|
| 59 |
+
title: "Security policy",
|
| 60 |
+
summary: "Security policy",
|
| 61 |
+
path: "../../../SECURITY.md",
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
type: "markdown",
|
| 65 |
+
slug: "I18n",
|
| 66 |
+
category: "General",
|
| 67 |
+
title: "I18n",
|
| 68 |
+
summary: "Internationalization",
|
| 69 |
+
path: "i18n.md",
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
type: "markdown",
|
| 73 |
+
slug: "I18n-Contribution-Guide",
|
| 74 |
+
category: "General",
|
| 75 |
+
title: "I18n Contribution Guide",
|
| 76 |
+
summary: "Locales manual",
|
| 77 |
+
path: "i18nContributionGuide.md",
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
type: "markdown",
|
| 81 |
+
slug: "Time-Zones",
|
| 82 |
+
category: "General",
|
| 83 |
+
title: "Time Zones",
|
| 84 |
+
summary: "Time zone support",
|
| 85 |
+
path: "timeZones.md",
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
type: "markdown",
|
| 89 |
+
slug: "CDN",
|
| 90 |
+
category: "General",
|
| 91 |
+
title: "CDN",
|
| 92 |
+
summary: "CDN version of date-fns",
|
| 93 |
+
path: "cdn.md",
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
type: "markdown",
|
| 97 |
+
slug: "webpack",
|
| 98 |
+
category: "General",
|
| 99 |
+
title: "webpack",
|
| 100 |
+
summary: "Using date-fns with webpack",
|
| 101 |
+
path: "webpack.md",
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
type: "markdown",
|
| 105 |
+
slug: "FP-Guide",
|
| 106 |
+
category: "General",
|
| 107 |
+
title: "FP Guide",
|
| 108 |
+
summary: "Curried functions",
|
| 109 |
+
path: "fp.md",
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
type: "markdown",
|
| 113 |
+
slug: "Unicode-Tokens",
|
| 114 |
+
category: "General",
|
| 115 |
+
title: "Unicode Tokens",
|
| 116 |
+
summary: "Usage of the Unicode tokens in parse and format",
|
| 117 |
+
path: "unicodeTokens.md",
|
| 118 |
+
},
|
| 119 |
+
{
|
| 120 |
+
type: "markdown",
|
| 121 |
+
slug: "License",
|
| 122 |
+
category: "General",
|
| 123 |
+
title: "License",
|
| 124 |
+
summary: "MIT © Sasha Koss",
|
| 125 |
+
path: "../LICENSE.md",
|
| 126 |
+
},
|
| 127 |
+
],
|
| 128 |
+
|
| 129 |
+
kindsMap: {
|
| 130 |
+
"src/constants/index.ts": {
|
| 131 |
+
kind: "constants",
|
| 132 |
+
category: "Misc",
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
+
};
|
node_modules/date-fns/docs/fp.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FP Guide
|
| 2 |
+
|
| 3 |
+
**date-fns** v2.x provides [functional programming](https://en.wikipedia.org/wiki/Functional_programming) (FP)
|
| 4 |
+
friendly functions, like those in [lodash](https://github.com/lodash/lodash/wiki/FP-Guide),
|
| 5 |
+
that support [currying](https://en.wikipedia.org/wiki/Currying).
|
| 6 |
+
|
| 7 |
+
## Table of Contents
|
| 8 |
+
|
| 9 |
+
- [Usage](#usage)
|
| 10 |
+
|
| 11 |
+
- [Using Function Composition](#using-function-composition)
|
| 12 |
+
|
| 13 |
+
## Usage
|
| 14 |
+
|
| 15 |
+
FP functions are provided via `'date-fns/fp'` submodule.
|
| 16 |
+
|
| 17 |
+
Functions with options (`format`, `parse`, etc.) have two FP counterparts:
|
| 18 |
+
one that has the options object as its first argument and one that hasn't.
|
| 19 |
+
The name of the former has `WithOptions` added to the end of its name.
|
| 20 |
+
|
| 21 |
+
In **date-fns'** FP functions, the order of arguments is reversed.
|
| 22 |
+
|
| 23 |
+
```javascript
|
| 24 |
+
import { addYears, formatWithOptions } from "date-fns/fp";
|
| 25 |
+
import { eo } from "date-fns/locale";
|
| 26 |
+
import toUpper from "lodash/fp/toUpper"; // 'date-fns/fp' is compatible with 'lodash/fp'!
|
| 27 |
+
|
| 28 |
+
// If FP function has not received enough arguments, it returns another function
|
| 29 |
+
const addFiveYears = addYears(5);
|
| 30 |
+
|
| 31 |
+
// Several arguments can be curried at once
|
| 32 |
+
const dateToString = formatWithOptions({ locale: eo }, "d MMMM yyyy");
|
| 33 |
+
|
| 34 |
+
const dates = [
|
| 35 |
+
new Date(2017, 0 /* Jan */, 1),
|
| 36 |
+
new Date(2017, 1 /* Feb */, 11),
|
| 37 |
+
new Date(2017, 6 /* Jul */, 2),
|
| 38 |
+
];
|
| 39 |
+
|
| 40 |
+
const formattedDates = dates.map(addFiveYears).map(dateToString).map(toUpper);
|
| 41 |
+
//=> ['1 JANUARO 2022', '11 FEBRUARO 2022', '2 JULIO 2022']
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## Using Function Composition
|
| 45 |
+
|
| 46 |
+
The main advantage of FP functions is support of functional-style
|
| 47 |
+
[function composing](https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba).
|
| 48 |
+
|
| 49 |
+
In the example above, you can compose `addFiveYears`, `dateToString` and `toUpper` into a single function:
|
| 50 |
+
|
| 51 |
+
```javascript
|
| 52 |
+
const formattedDates = dates.map((date) =>
|
| 53 |
+
toUpper(dateToString(addFiveYears(date))),
|
| 54 |
+
);
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Or you can use `compose` function provided by [lodash](https://lodash.com) to do the same in more idiomatic way:
|
| 58 |
+
|
| 59 |
+
```javascript
|
| 60 |
+
import { compose } from "lodash/fp/compose";
|
| 61 |
+
|
| 62 |
+
const formattedDates = dates.map(compose(toUpper, dateToString, addFiveYears));
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Or if you prefer natural direction of composing (as opposed to the computationally correct order),
|
| 66 |
+
you can use lodash' `flow` instead:
|
| 67 |
+
|
| 68 |
+
```javascript
|
| 69 |
+
import flow from "lodash/fp/flow";
|
| 70 |
+
|
| 71 |
+
const formattedDates = dates.map(flow(addFiveYears, dateToString, toUpper));
|
| 72 |
+
```
|
node_modules/date-fns/docs/gettingStarted.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Getting Started
|
| 2 |
+
|
| 3 |
+
## Table of Contents
|
| 4 |
+
|
| 5 |
+
- [Introduction](#introduction)
|
| 6 |
+
|
| 7 |
+
- [Submodules](#submodules)
|
| 8 |
+
|
| 9 |
+
- [Installation](#installation)
|
| 10 |
+
|
| 11 |
+
## Introduction
|
| 12 |
+
|
| 13 |
+
**date-fns** provides the most comprehensive, yet simple and consistent toolset
|
| 14 |
+
for manipulating **JavaScript dates** in **a browser** & **Node.js**.
|
| 15 |
+
|
| 16 |
+
**date-fns** is like [lodash](https://lodash.com) for dates. It has
|
| 17 |
+
[**200+ functions** for all occasions](https://date-fns.org/docs/).
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
import { format, compareAsc } from "date-fns";
|
| 21 |
+
|
| 22 |
+
format(new Date(2014, 1, 11), "MM/dd/yyyy");
|
| 23 |
+
//=> '02/11/2014'
|
| 24 |
+
|
| 25 |
+
const dates = [
|
| 26 |
+
new Date(1995, 6, 2),
|
| 27 |
+
new Date(1987, 1, 11),
|
| 28 |
+
new Date(1989, 6, 10),
|
| 29 |
+
];
|
| 30 |
+
dates.sort(compareAsc);
|
| 31 |
+
//=> [
|
| 32 |
+
// Wed Feb 11 1987 00:00:00,
|
| 33 |
+
// Mon Jul 10 1989 00:00:00,
|
| 34 |
+
// Sun Jul 02 1995 00:00:00
|
| 35 |
+
// ]
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Submodules
|
| 39 |
+
|
| 40 |
+
**date-fns** includes some optional features as submodules in the npm package.
|
| 41 |
+
Here is the list of them, in order of nesting:
|
| 42 |
+
|
| 43 |
+
- FP — functional programming-friendly variations of the functions. See [FP Guide](https://date-fns.org/docs/FP-Guide);
|
| 44 |
+
|
| 45 |
+
The later submodules are also included inside the former if you want to use multiple features from the list.
|
| 46 |
+
|
| 47 |
+
To use submodule features, [install the npm package](#npm) and then import a function from a submodule:
|
| 48 |
+
|
| 49 |
+
```js
|
| 50 |
+
// The main submodule:
|
| 51 |
+
import { addDays } from "date-fns";
|
| 52 |
+
|
| 53 |
+
// FP variation:
|
| 54 |
+
import { addDays, format } from "date-fns/fp";
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Installation
|
| 58 |
+
|
| 59 |
+
The library is available as an [npm package](https://www.npmjs.com/package/date-fns).
|
| 60 |
+
|
| 61 |
+
To install the package, run:
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
npm install date-fns --save
|
| 65 |
+
# or
|
| 66 |
+
yarn add date-fns
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
Start using:
|
| 70 |
+
|
| 71 |
+
```js
|
| 72 |
+
import { formatDistance, subDays } from "date-fns";
|
| 73 |
+
|
| 74 |
+
formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true });
|
| 75 |
+
//=> "3 days ago"
|
| 76 |
+
```
|
node_modules/date-fns/docs/i18n.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Internationalization
|
| 2 |
+
|
| 3 |
+
## Table of Contents
|
| 4 |
+
|
| 5 |
+
- [Usage](#usage)
|
| 6 |
+
|
| 7 |
+
- [Adding New Language](#adding-new-language)
|
| 8 |
+
|
| 9 |
+
## Usage
|
| 10 |
+
|
| 11 |
+
There are just a few functions that support I18n:
|
| 12 |
+
|
| 13 |
+
- [`format`](https://date-fns.org/docs/format)
|
| 14 |
+
- [`formatDistance`](https://date-fns.org/docs/formatDistance)
|
| 15 |
+
- [`formatDistanceStrict`](https://date-fns.org/docs/formatDistanceStrict)
|
| 16 |
+
- [`formatRelative`](https://date-fns.org/docs/formatRelative)
|
| 17 |
+
|
| 18 |
+
To use a locale, you need to require it and then pass
|
| 19 |
+
as an option to a function:
|
| 20 |
+
|
| 21 |
+
```js
|
| 22 |
+
import { formatDistance } from "date-fns";
|
| 23 |
+
// Require Esperanto locale
|
| 24 |
+
import { eo } from "date-fns/locale";
|
| 25 |
+
|
| 26 |
+
const result = formatDistance(
|
| 27 |
+
new Date(2016, 7, 1),
|
| 28 |
+
new Date(2015, 0, 1),
|
| 29 |
+
{ locale: eo }, // Pass the locale as an option
|
| 30 |
+
);
|
| 31 |
+
//=> 'pli ol 1 jaro'
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
It might seem complicated to require and pass locales as options,
|
| 35 |
+
but unlike Moment.js which bloats your build with all the locales
|
| 36 |
+
by default date-fns forces developer to manually require locales when needed.
|
| 37 |
+
To make API simple, we encourage you to write tiny wrappers and use those
|
| 38 |
+
instead of original functions:
|
| 39 |
+
|
| 40 |
+
```js
|
| 41 |
+
// app/_lib/format.js
|
| 42 |
+
|
| 43 |
+
import { format } from "date-fns";
|
| 44 |
+
import { enGB, eo, ru } from "date-fns/locale";
|
| 45 |
+
|
| 46 |
+
const locales = { enGB, eo, ru };
|
| 47 |
+
|
| 48 |
+
// by providing a default string of 'PP' or any of its variants for `formatStr`
|
| 49 |
+
// it will format dates in whichever way is appropriate to the locale
|
| 50 |
+
export default function (date, formatStr = "PP") {
|
| 51 |
+
return format(date, formatStr, {
|
| 52 |
+
locale: locales[window.__localeId__], // or global.__localeId__
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Later:
|
| 57 |
+
|
| 58 |
+
import format from "app/_lib/format";
|
| 59 |
+
|
| 60 |
+
window.__localeId__ = "enGB";
|
| 61 |
+
format(friday13, "EEEE d");
|
| 62 |
+
//=> 'Friday 13'
|
| 63 |
+
|
| 64 |
+
window.__localeId__ = "eo";
|
| 65 |
+
format(friday13, "EEEE d");
|
| 66 |
+
//=> 'vendredo 13'
|
| 67 |
+
|
| 68 |
+
// If the format string is omitted, it will take the default for the locale.
|
| 69 |
+
window.__localeId__ = "enGB";
|
| 70 |
+
format(friday13);
|
| 71 |
+
//=> Jul 13, 2019
|
| 72 |
+
|
| 73 |
+
window.__localeId__ = "eo";
|
| 74 |
+
format(friday13);
|
| 75 |
+
//=> 2019-jul-13
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Adding New Language
|
| 79 |
+
|
| 80 |
+
At the moment there is no definitive guide, so if you feel brave enough,
|
| 81 |
+
use this quick guide:
|
| 82 |
+
|
| 83 |
+
- First of all, [create an issue](https://github.com/date-fns/date-fns/issues/new?title=XXX%20language%20support)
|
| 84 |
+
so you won't overlap with others.
|
| 85 |
+
- A detailed explanation of how to [add a new locale](https://github.com/date-fns/date-fns/blob/master/docs/i18nContributionGuide.md#adding-a-new-locale).
|
| 86 |
+
- Use [English locale](https://github.com/date-fns/date-fns/tree/master/src/locale/en-US)
|
| 87 |
+
as the basis and then incrementally adjust the tests and the code.
|
| 88 |
+
- Directions on [adding a locale with the same language as another locale](https://github.com/date-fns/date-fns/blob/master/docs/i18nContributionGuide.md#creating-a-locale-with-the-same-language-as-another-locale).
|
| 89 |
+
- If you have questions or need guidance, leave a comment in the issue.
|
| 90 |
+
|
| 91 |
+
Thank you for your support!
|
node_modules/date-fns/docs/i18nContributionGuide.md
ADDED
|
@@ -0,0 +1,1059 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# I18n Contribution Guide
|
| 2 |
+
|
| 3 |
+
## Table of Contents
|
| 4 |
+
|
| 5 |
+
- [Adding a new locale](#adding-a-new-locale)
|
| 6 |
+
- [Choosing a directory name for a locale](#choosing-a-directory-name-for-a-locale)
|
| 7 |
+
|
| 8 |
+
- [index.js](#index.js)
|
| 9 |
+
|
| 10 |
+
- [localize](#localize)
|
| 11 |
+
- [localize.ordinalNumber](#localize.ordinalnumber)
|
| 12 |
+
|
| 13 |
+
- [localize.era and using buildLocalizeFn function](#localize.era-and-using-buildlocalizefn-function)
|
| 14 |
+
|
| 15 |
+
- [Formatting localizers](#formatting-localizers)
|
| 16 |
+
|
| 17 |
+
- [localize.quarter](#localize.quarter)
|
| 18 |
+
|
| 19 |
+
- [localize.month](#localize.month)
|
| 20 |
+
|
| 21 |
+
- [localize.day](#localize.day)
|
| 22 |
+
|
| 23 |
+
- [localize.dayPeriod](#localize.dayperiod)
|
| 24 |
+
|
| 25 |
+
- [formatLong](#formatlong)
|
| 26 |
+
- [formatLong.dateFormats](#formatlong.dateformats)
|
| 27 |
+
|
| 28 |
+
- [formatLong.timeFormats](#formatlong.timeformats)
|
| 29 |
+
|
| 30 |
+
- [formatLong.dateTimeFormats](#formatlong.datetimeformats)
|
| 31 |
+
|
| 32 |
+
- [formatRelative](#formatrelative)
|
| 33 |
+
|
| 34 |
+
- [match](#match)
|
| 35 |
+
|
| 36 |
+
- [formatDistance](#formatdistance)
|
| 37 |
+
|
| 38 |
+
- [Tests](#tests)
|
| 39 |
+
|
| 40 |
+
- [Creating a locale with the same language as another locale](#creating-a-locale-with-the-same-language-as-another-locale)
|
| 41 |
+
|
| 42 |
+
## Adding a new locale
|
| 43 |
+
|
| 44 |
+
To add a new locale:
|
| 45 |
+
|
| 46 |
+
- [Choose a directory name for it](#choosing-a-directory-name-for-a-locale).
|
| 47 |
+
|
| 48 |
+
- Copy the content of an existing locale (e.g. `en-US`) into the newly created directory.
|
| 49 |
+
|
| 50 |
+
- Replace the values in the content with yours file-by-file.
|
| 51 |
+
Use [CLDR data](https://www.unicode.org/cldr/charts/32/summary/root.html)
|
| 52 |
+
as a point of reference which values to choose.
|
| 53 |
+
|
| 54 |
+
All locales contain a number of properties:
|
| 55 |
+
|
| 56 |
+
- [`formatDistance`](#formatdistance) — distance localizer function used by `formatDistance` and `formatDistanceStrict`.
|
| 57 |
+
- [`formatLong`](#formatlong) — contains long date localizer functions used by `format` and `formatRelative`.
|
| 58 |
+
- [`formatRelative`](#formatrelative) — relative date localizer function used by `formatRelative`.
|
| 59 |
+
- [`localize`](#localize) — contains functions, which localize the various date values. Required by `format` and `formatRelative`.
|
| 60 |
+
- [`match`](#match) — contains functions to parse date values. Required by `parse`.
|
| 61 |
+
- [`options`](#indexjs) — contains the index of the first day of the week for functions such as `startOfWeek`,
|
| 62 |
+
and the value which determines the first week of the year
|
| 63 |
+
for functions like `setWeek`.
|
| 64 |
+
|
| 65 |
+
### Choosing a directory name for a locale
|
| 66 |
+
|
| 67 |
+
Use the four letter code for the directory name (e.g. `en-GB`),
|
| 68 |
+
|
| 69 |
+
Use the two/three letter code:
|
| 70 |
+
|
| 71 |
+
- if the language code and the country code are the same (e.g. `pt` instead of `pt-PT`).
|
| 72 |
+
|
| 73 |
+
- if the language is used in only one country (e.g. `fil` instead of `fil-PH`).
|
| 74 |
+
|
| 75 |
+
- if all countries who use the language
|
| 76 |
+
also use the same regional standards: the first day of the week,
|
| 77 |
+
the week numbering (see: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system),
|
| 78 |
+
calendar date format (see: https://en.wikipedia.org/wiki/Calendar_date)
|
| 79 |
+
and date representation (see: https://en.wikipedia.org/wiki/Date_and_time_representation_by_country
|
| 80 |
+
and: https://en.wikipedia.org/wiki/Date_format_by_country)
|
| 81 |
+
(e.g. `ca` instead of `ca-ES` and `ca-AD`).
|
| 82 |
+
|
| 83 |
+
### index.js
|
| 84 |
+
|
| 85 |
+
Locale's `index.js` is where all the properties of the locale are combined in a single file,
|
| 86 |
+
documented in JSDoc format.
|
| 87 |
+
|
| 88 |
+
```javascript
|
| 89 |
+
import formatDistance from "./_lib/formatDistance/index.js";
|
| 90 |
+
import formatLong from "./_lib/formatLong/index.js";
|
| 91 |
+
import formatRelative from "./_lib/formatRelative/index.js";
|
| 92 |
+
import localize from "./_lib/localize/index.js";
|
| 93 |
+
import match from "./_lib/match/index.js";
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* @type {Locale}
|
| 97 |
+
* @category Locales
|
| 98 |
+
*
|
| 99 |
+
* // Name of the locale.
|
| 100 |
+
* // Inside the parentheses - name of the country - if the locale uses the four letter code, e.g. en-US, fr-CA or pt-BR.
|
| 101 |
+
* @summary English locale (United States).
|
| 102 |
+
*
|
| 103 |
+
* // Name of the language (used by https://date-fns.org/ website)
|
| 104 |
+
* @language English
|
| 105 |
+
*
|
| 106 |
+
* // ISO 639-2 code. See the list here:
|
| 107 |
+
* // https://www.loc.gov/standards/iso639-2/php/code_list.php
|
| 108 |
+
* // Used by https://date-fns.org/ to detect the list of the countries that uses the language.
|
| 109 |
+
* @iso-639-2 eng
|
| 110 |
+
*
|
| 111 |
+
* // Authors of the locale (including anyone who corrected or fixed the locale)
|
| 112 |
+
* @author Sasha Koss [@kossnocorp]{@link https://github.com/kossnocorp}
|
| 113 |
+
* @author Lesha Koss [@leshakoss]{@link https://github.com/leshakoss}
|
| 114 |
+
*/
|
| 115 |
+
var locale = {
|
| 116 |
+
code: "en",
|
| 117 |
+
formatDistance: formatDistance,
|
| 118 |
+
formatLong: formatLong,
|
| 119 |
+
formatRelative: formatRelative,
|
| 120 |
+
localize: localize,
|
| 121 |
+
match: match,
|
| 122 |
+
options: {
|
| 123 |
+
// Index of the first day of the week.
|
| 124 |
+
// Sunday is 0, Monday is 1, Saturday is 6.
|
| 125 |
+
weekStartsOn: 0,
|
| 126 |
+
|
| 127 |
+
// Nth of January which is always in the first week of the year. See:
|
| 128 |
+
// https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
|
| 129 |
+
// http://www.pjh2.de/datetime/weeknumber/wnd.php?l=en
|
| 130 |
+
firstWeekContainsDate: 1,
|
| 131 |
+
},
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
export default locale;
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
### localize
|
| 138 |
+
|
| 139 |
+
Put this object in `_lib/localize/index.js` inside your locale directory.
|
| 140 |
+
Contains a number of functions for used by `format`:
|
| 141 |
+
|
| 142 |
+
```js
|
| 143 |
+
var localize = {
|
| 144 |
+
ordinalNumber,
|
| 145 |
+
era,
|
| 146 |
+
quarter,
|
| 147 |
+
month,
|
| 148 |
+
day,
|
| 149 |
+
dayPeriod,
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
export default localize;
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
#### localize.ordinalNumber
|
| 156 |
+
|
| 157 |
+
Function that takes a numeric argument and returns a string with ordinal number:
|
| 158 |
+
|
| 159 |
+
```js
|
| 160 |
+
// In `en-US` locale:
|
| 161 |
+
function ordinalNumber(dirtyNumber, dirtyOptions) {
|
| 162 |
+
var number = Number(dirtyNumber);
|
| 163 |
+
|
| 164 |
+
var rem100 = number % 100;
|
| 165 |
+
if (rem100 > 20 || rem100 < 10) {
|
| 166 |
+
switch (rem100 % 10) {
|
| 167 |
+
case 1:
|
| 168 |
+
return number + "st";
|
| 169 |
+
case 2:
|
| 170 |
+
return number + "nd";
|
| 171 |
+
case 3:
|
| 172 |
+
return number + "rd";
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
return number + "th";
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
var localize = {
|
| 179 |
+
ordinalNumber: ordinalNumber,
|
| 180 |
+
// ...
|
| 181 |
+
};
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
If the form of the ordinal number depends on the grammatical case (or other grammatical structures),
|
| 185 |
+
use `options.unit` argument which could be one of the values 'year', 'quarter', 'month', 'week',
|
| 186 |
+
'date', 'dayOfYear', 'day', 'hour', 'minute' or 'second':
|
| 187 |
+
|
| 188 |
+
```js
|
| 189 |
+
// In `ru` locale:
|
| 190 |
+
function ordinalNumber(dirtyNumber, dirtyOptions) {
|
| 191 |
+
var options = dirtyOptions || {};
|
| 192 |
+
var unit = String(options.unit);
|
| 193 |
+
var suffix;
|
| 194 |
+
|
| 195 |
+
if (unit === "date") {
|
| 196 |
+
suffix = "-е";
|
| 197 |
+
} else if (unit === "week" || unit === "minute" || unit === "second") {
|
| 198 |
+
suffix = "-я";
|
| 199 |
+
} else {
|
| 200 |
+
suffix = "-й";
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
return dirtyNumber + suffix;
|
| 204 |
+
}
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
#### localize.era and using buildLocalizeFn function
|
| 208 |
+
|
| 209 |
+
Localizes a numeric era. Takes either 0 or 1 as the first argument.
|
| 210 |
+
As with many of the `localize` functions, they can be generated by built-in
|
| 211 |
+
`buildLocalizeFn` function.
|
| 212 |
+
|
| 213 |
+
From the CLDR chart, use ['Date & Time'/'Gregorian'/'Eras'](https://www.unicode.org/cldr/charts/32/summary/en.html#1771) values.
|
| 214 |
+
|
| 215 |
+
```js
|
| 216 |
+
// In `en-US` locale:
|
| 217 |
+
import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js";
|
| 218 |
+
|
| 219 |
+
var eraValues = {
|
| 220 |
+
narrow: ["B", "A"],
|
| 221 |
+
abbreviated: ["BC", "AD"],
|
| 222 |
+
wide: ["Before Christ", "Anno Domini"],
|
| 223 |
+
};
|
| 224 |
+
|
| 225 |
+
var localize = {
|
| 226 |
+
// ...
|
| 227 |
+
era: buildLocalizeFn({
|
| 228 |
+
values: eraValues,
|
| 229 |
+
defaultWidth: "wide",
|
| 230 |
+
}),
|
| 231 |
+
// ...
|
| 232 |
+
};
|
| 233 |
+
|
| 234 |
+
export default localize;
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
General usage of the function:
|
| 238 |
+
|
| 239 |
+
```js
|
| 240 |
+
var result = locale.localize.era(1, { width: "abbreviated" });
|
| 241 |
+
//=> 'AD'
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
If `width` is not provided or the `values` object does not contain values for the provided width,
|
| 245 |
+
`defaultWidth` will be used. `defaultWidth` should indicate the longest form of the localized value.
|
| 246 |
+
The same is true for all other `localize` functions.
|
| 247 |
+
`width` for `localize.era` function could be either 'narrow', 'abbreviated' or 'wide'.
|
| 248 |
+
|
| 249 |
+
```js
|
| 250 |
+
var result = locale.localize.era(1, { width: "foobar" });
|
| 251 |
+
//=> 'Anno Domini'
|
| 252 |
+
```
|
| 253 |
+
|
| 254 |
+
#### Formatting localizers
|
| 255 |
+
|
| 256 |
+
For some languages, there is a difference between "stand-alone" localizers and "formatting" localizers.
|
| 257 |
+
"Stand-alone" means that the resulting value should make grammatical sense without context.
|
| 258 |
+
"Formatting" means that the resulting value should be decided using the grammar rules of the language
|
| 259 |
+
as if the value was a part of a date.
|
| 260 |
+
For example, for languages with grammatical cases, the stand-alone month could be in the nominative case ("January"),
|
| 261 |
+
and the formatting month could decline as a part of the phrase "1st of January".
|
| 262 |
+
In this case, use parameters `formattingValues` and `defaultFormattingWidth` of `buildLocalizeFn` function.
|
| 263 |
+
|
| 264 |
+
Any localizer could be stand-alone and formatting.
|
| 265 |
+
Check the CLDR chart for the unit to see if stand-alone and formatting values are different for a certain unit.
|
| 266 |
+
If there's no difference (usually it happens in languages without grammatical cases),
|
| 267 |
+
parameters `formattingValues` and `defaultFormattingWidth` are not needed.
|
| 268 |
+
|
| 269 |
+
In this example, in Russian language a stand-alone month is in the nominative case ("январь"),
|
| 270 |
+
and formatting month is in the genitive case ("января" as in "1-е января"). Notice the different endings:
|
| 271 |
+
|
| 272 |
+
```js
|
| 273 |
+
// In `ru` locale:
|
| 274 |
+
var monthValues = {
|
| 275 |
+
narrow: ["Я", "Ф", "М", "А", "М", "И", "И", "А", "С", "О", "Н", "Д"],
|
| 276 |
+
abbreviated: [
|
| 277 |
+
"янв.",
|
| 278 |
+
"фев.",
|
| 279 |
+
"март",
|
| 280 |
+
"апр.",
|
| 281 |
+
"май",
|
| 282 |
+
"июнь",
|
| 283 |
+
"июль",
|
| 284 |
+
"авг.",
|
| 285 |
+
"сент.",
|
| 286 |
+
"окт.",
|
| 287 |
+
"нояб.",
|
| 288 |
+
"дек.",
|
| 289 |
+
],
|
| 290 |
+
wide: [
|
| 291 |
+
"январь",
|
| 292 |
+
"февраль",
|
| 293 |
+
"март",
|
| 294 |
+
"апрель",
|
| 295 |
+
"май",
|
| 296 |
+
"июнь",
|
| 297 |
+
"июль",
|
| 298 |
+
"август",
|
| 299 |
+
"сентябрь",
|
| 300 |
+
"октябрь",
|
| 301 |
+
"ноябрь",
|
| 302 |
+
"декабрь",
|
| 303 |
+
],
|
| 304 |
+
};
|
| 305 |
+
var formattingMonthValues = {
|
| 306 |
+
narrow: ["Я", "Ф", "М", "А", "М", "И", "И", "А", "С", "О", "Н", "Д"],
|
| 307 |
+
abbreviated: [
|
| 308 |
+
"янв.",
|
| 309 |
+
"фев.",
|
| 310 |
+
"мар.",
|
| 311 |
+
"апр.",
|
| 312 |
+
"мая",
|
| 313 |
+
"июн.",
|
| 314 |
+
"июл.",
|
| 315 |
+
"авг.",
|
| 316 |
+
"сент.",
|
| 317 |
+
"окт.",
|
| 318 |
+
"нояб.",
|
| 319 |
+
"дек.",
|
| 320 |
+
],
|
| 321 |
+
wide: [
|
| 322 |
+
"января",
|
| 323 |
+
"февраля",
|
| 324 |
+
"марта",
|
| 325 |
+
"апреля",
|
| 326 |
+
"мая",
|
| 327 |
+
"июня",
|
| 328 |
+
"июля",
|
| 329 |
+
"августа",
|
| 330 |
+
"сентября",
|
| 331 |
+
"октября",
|
| 332 |
+
"ноября",
|
| 333 |
+
"декабря",
|
| 334 |
+
],
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
var localize = {
|
| 338 |
+
// ...
|
| 339 |
+
month: buildLocalizeFn({
|
| 340 |
+
values: monthValues,
|
| 341 |
+
defaultWidth: "wide",
|
| 342 |
+
formattingValues: formattingMonthValues,
|
| 343 |
+
defaultFormattingWidth: "wide",
|
| 344 |
+
}),
|
| 345 |
+
// ...
|
| 346 |
+
};
|
| 347 |
+
|
| 348 |
+
export default localize;
|
| 349 |
+
```
|
| 350 |
+
|
| 351 |
+
#### localize.quarter
|
| 352 |
+
|
| 353 |
+
Localizes a quarter. Takes 1, 2, 3 or 4 as the first argument.
|
| 354 |
+
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
| 355 |
+
From the CLDR chart, use ['Date & Time'/'Gregorian'/'Quarters'](https://www.unicode.org/cldr/charts/32/summary/en.html#1781) values.
|
| 356 |
+
|
| 357 |
+
```js
|
| 358 |
+
// In `en-US` locale:
|
| 359 |
+
import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js";
|
| 360 |
+
|
| 361 |
+
var quarterValues = {
|
| 362 |
+
narrow: ["1", "2", "3", "4"],
|
| 363 |
+
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
|
| 364 |
+
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
|
| 365 |
+
};
|
| 366 |
+
|
| 367 |
+
var localize = {
|
| 368 |
+
// ...
|
| 369 |
+
quarter: buildLocalizeFn({
|
| 370 |
+
values: quarterValues,
|
| 371 |
+
defaultWidth: "wide",
|
| 372 |
+
argumentCallback: function (quarter) {
|
| 373 |
+
return Number(quarter) - 1;
|
| 374 |
+
},
|
| 375 |
+
}),
|
| 376 |
+
// ...
|
| 377 |
+
};
|
| 378 |
+
|
| 379 |
+
export default localize;
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
Note the usage of `argumentCallback` here. It converts the value passed into `localize.quarter` function
|
| 383 |
+
(one of 1, 2, 3 or 4) into the index of the values array inside `quarterValues` (one of 0, 1, 2 or 3).
|
| 384 |
+
|
| 385 |
+
#### localize.month
|
| 386 |
+
|
| 387 |
+
Localizes a month. Takes numbers between 0 (for January) and 11 (for December).
|
| 388 |
+
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
| 389 |
+
From the CLDR chart, use ['Date & Time'/'Gregorian'/'Months'](https://www.unicode.org/cldr/charts/32/summary/en.html#1793) values.
|
| 390 |
+
|
| 391 |
+
```js
|
| 392 |
+
// In `en-US` locale:
|
| 393 |
+
import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js";
|
| 394 |
+
|
| 395 |
+
var monthValues = {
|
| 396 |
+
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
|
| 397 |
+
abbreviated: [
|
| 398 |
+
"Jan",
|
| 399 |
+
"Feb",
|
| 400 |
+
"Mar",
|
| 401 |
+
"Apr",
|
| 402 |
+
"May",
|
| 403 |
+
"Jun",
|
| 404 |
+
"Jul",
|
| 405 |
+
"Aug",
|
| 406 |
+
"Sep",
|
| 407 |
+
"Oct",
|
| 408 |
+
"Nov",
|
| 409 |
+
"Dec",
|
| 410 |
+
],
|
| 411 |
+
wide: [
|
| 412 |
+
"January",
|
| 413 |
+
"February",
|
| 414 |
+
"March",
|
| 415 |
+
"April",
|
| 416 |
+
"May",
|
| 417 |
+
"June",
|
| 418 |
+
"July",
|
| 419 |
+
"August",
|
| 420 |
+
"September",
|
| 421 |
+
"October",
|
| 422 |
+
"November",
|
| 423 |
+
"December",
|
| 424 |
+
],
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
var localize = {
|
| 428 |
+
// ...
|
| 429 |
+
month: buildLocalizeFn({
|
| 430 |
+
values: monthValues,
|
| 431 |
+
defaultWidth: "wide",
|
| 432 |
+
}),
|
| 433 |
+
// ...
|
| 434 |
+
};
|
| 435 |
+
|
| 436 |
+
export default localize;
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
**NOTE**: in English, the names of days of the week and months are capitalized.
|
| 440 |
+
Check if the same is true for the language you're working on.
|
| 441 |
+
Generally, formatted dates should look like they are in the middle of a sentence,
|
| 442 |
+
e.g. in Spanish language the weekdays and months should be in the lowercase:
|
| 443 |
+
|
| 444 |
+
```js
|
| 445 |
+
// In `es` locale:
|
| 446 |
+
var monthValues = {
|
| 447 |
+
narrow: ["E", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
|
| 448 |
+
abbreviated: [
|
| 449 |
+
"ene.",
|
| 450 |
+
"feb.",
|
| 451 |
+
"mar.",
|
| 452 |
+
"abr.",
|
| 453 |
+
"may.",
|
| 454 |
+
"jun.",
|
| 455 |
+
"jul.",
|
| 456 |
+
"ago.",
|
| 457 |
+
"sep.",
|
| 458 |
+
"oct.",
|
| 459 |
+
"nov.",
|
| 460 |
+
"dic.",
|
| 461 |
+
],
|
| 462 |
+
wide: [
|
| 463 |
+
"enero",
|
| 464 |
+
"febrero",
|
| 465 |
+
"marzo",
|
| 466 |
+
"abril",
|
| 467 |
+
"mayo",
|
| 468 |
+
"junio",
|
| 469 |
+
"julio",
|
| 470 |
+
"agosto",
|
| 471 |
+
"septiembre",
|
| 472 |
+
"octubre",
|
| 473 |
+
"noviembre",
|
| 474 |
+
"diciembre",
|
| 475 |
+
],
|
| 476 |
+
};
|
| 477 |
+
```
|
| 478 |
+
|
| 479 |
+
`monthValues.narrow` are usually capitalized in every language. Check the CLDR chart for your language.
|
| 480 |
+
|
| 481 |
+
#### localize.day
|
| 482 |
+
|
| 483 |
+
Localizes a week day. Takes numbers between 0 (for Sunday) and 6 (for Saturday).
|
| 484 |
+
`width` could be either 'narrow', 'short', 'abbreviated' or 'wide'.
|
| 485 |
+
From the CLDR chart, use ['Date & Time'/'Gregorian'/'Days'](https://www.unicode.org/cldr/charts/32/summary/en.html#1829) values.
|
| 486 |
+
|
| 487 |
+
```js
|
| 488 |
+
// In `en-US` locale:
|
| 489 |
+
import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js";
|
| 490 |
+
|
| 491 |
+
var dayValues = {
|
| 492 |
+
narrow: ["S", "M", "T", "W", "T", "F", "S"],
|
| 493 |
+
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
| 494 |
+
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
| 495 |
+
wide: [
|
| 496 |
+
"Sunday",
|
| 497 |
+
"Monday",
|
| 498 |
+
"Tuesday",
|
| 499 |
+
"Wednesday",
|
| 500 |
+
"Thursday",
|
| 501 |
+
"Friday",
|
| 502 |
+
"Saturday",
|
| 503 |
+
],
|
| 504 |
+
};
|
| 505 |
+
|
| 506 |
+
var localize = {
|
| 507 |
+
// ...
|
| 508 |
+
day: buildLocalizeFn({
|
| 509 |
+
values: dayValues,
|
| 510 |
+
defaultWidth: "wide",
|
| 511 |
+
}),
|
| 512 |
+
// ...
|
| 513 |
+
};
|
| 514 |
+
|
| 515 |
+
export default localize;
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
**NOTE**: the rules of capitalization from `localize.month` are also true for `localize.day`.
|
| 519 |
+
|
| 520 |
+
#### localize.dayPeriod
|
| 521 |
+
|
| 522 |
+
Localizes a certain day period.
|
| 523 |
+
Could take one of these strings as the argument: 'am', 'pm', 'midnight', 'noon', 'morning', 'afternoon', 'evening', 'night'.
|
| 524 |
+
`width` could be either 'narrow', 'abbreviated' or 'wide'.
|
| 525 |
+
From the CLDR chart, use ['Date & Time'/'Gregorian'/'Day periods'](https://www.unicode.org/cldr/charts/32/summary/en.html#1857) values.
|
| 526 |
+
|
| 527 |
+
```js
|
| 528 |
+
// In `en-US` locale:
|
| 529 |
+
import buildLocalizeFn from "../../../_lib/buildLocalizeFn/index.js";
|
| 530 |
+
|
| 531 |
+
var dayPeriodValues = {
|
| 532 |
+
narrow: {
|
| 533 |
+
am: "a",
|
| 534 |
+
pm: "p",
|
| 535 |
+
midnight: "mi",
|
| 536 |
+
noon: "n",
|
| 537 |
+
morning: "in the morning",
|
| 538 |
+
afternoon: "in the afternoon",
|
| 539 |
+
evening: "in the evening",
|
| 540 |
+
night: "at night",
|
| 541 |
+
},
|
| 542 |
+
abbreviated: {
|
| 543 |
+
am: "AM",
|
| 544 |
+
pm: "PM",
|
| 545 |
+
midnight: "midnight",
|
| 546 |
+
noon: "noon",
|
| 547 |
+
morning: "in the morning",
|
| 548 |
+
afternoon: "in the afternoon",
|
| 549 |
+
evening: "in the evening",
|
| 550 |
+
night: "at night",
|
| 551 |
+
},
|
| 552 |
+
wide: {
|
| 553 |
+
am: "a.m.",
|
| 554 |
+
pm: "p.m.",
|
| 555 |
+
midnight: "midnight",
|
| 556 |
+
noon: "noon",
|
| 557 |
+
morning: "in the morning",
|
| 558 |
+
afternoon: "in the afternoon",
|
| 559 |
+
evening: "in the evening",
|
| 560 |
+
night: "at night",
|
| 561 |
+
},
|
| 562 |
+
};
|
| 563 |
+
|
| 564 |
+
var localize = {
|
| 565 |
+
// ...
|
| 566 |
+
dayPeriod: buildLocalizeFn({
|
| 567 |
+
values: dayPeriodValues,
|
| 568 |
+
defaultWidth: "wide",
|
| 569 |
+
}),
|
| 570 |
+
};
|
| 571 |
+
|
| 572 |
+
export default localize;
|
| 573 |
+
```
|
| 574 |
+
|
| 575 |
+
### formatLong
|
| 576 |
+
|
| 577 |
+
Put this object in `_lib/formatLong/index.js` inside your locale directory.
|
| 578 |
+
Locale date formats written in `format` token string format.
|
| 579 |
+
See the list of tokens: https://date-fns.org/docs/format
|
| 580 |
+
Use https://en.wikipedia.org/wiki/Date_format_by_country and CLDR chart as the reference.
|
| 581 |
+
|
| 582 |
+
#### formatLong.dateFormats
|
| 583 |
+
|
| 584 |
+
Use ['Date & Time'/'Gregorian'/'Formats - Standard - Date Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1901) values
|
| 585 |
+
from the CLDR chart as a reference.
|
| 586 |
+
|
| 587 |
+
```js
|
| 588 |
+
// In `en-US` locale
|
| 589 |
+
import buildFormatLongFn from "../../../_lib/buildFormatLongFn/index.js";
|
| 590 |
+
|
| 591 |
+
var dateFormats = {
|
| 592 |
+
full: "EEEE, MMMM do, y",
|
| 593 |
+
long: "MMMM do, y",
|
| 594 |
+
medium: "MMM d, y",
|
| 595 |
+
short: "MM/dd/yyyy",
|
| 596 |
+
};
|
| 597 |
+
|
| 598 |
+
var formatLong = {
|
| 599 |
+
date: buildFormatLongFn({
|
| 600 |
+
formats: dateFormats,
|
| 601 |
+
defaultWidth: "full",
|
| 602 |
+
}),
|
| 603 |
+
// ...
|
| 604 |
+
};
|
| 605 |
+
|
| 606 |
+
export default formatLong;
|
| 607 |
+
```
|
| 608 |
+
|
| 609 |
+
`dateFormats.long` usually contains the longest form of writing the year, the month, and the day of the month.
|
| 610 |
+
Use ordinal day of the month ('do' token) where applicable (date-fns, unlike CLDR supports ordinal numbers).
|
| 611 |
+
|
| 612 |
+
`dateFormats.full` contains the same but with the day of the week.
|
| 613 |
+
|
| 614 |
+
`dateFormats.medium` contains the same values as `dateFormats.long`, but with short form of month and non-ordinal day.
|
| 615 |
+
|
| 616 |
+
`dateFormats.short` usually contains a strictly numerical form of the date.
|
| 617 |
+
Pay attention to the order of units (big-, little- or middle-endian)
|
| 618 |
+
|
| 619 |
+
#### formatLong.timeFormats
|
| 620 |
+
|
| 621 |
+
Use ['Date & Time'/'Gregorian'/'Formats - Standard - Time Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1906) values
|
| 622 |
+
from the CLDR chart as a reference.
|
| 623 |
+
|
| 624 |
+
Use some variation of 'h:mm aa' for 12-hour clock locales or 'H:mm' for 24-hour clock locales. Use the local time separator.
|
| 625 |
+
|
| 626 |
+
```js
|
| 627 |
+
// In `en-US` locale
|
| 628 |
+
import buildFormatLongFn from "../../../_lib/buildFormatLongFn/index.js";
|
| 629 |
+
|
| 630 |
+
var timeFormats = {
|
| 631 |
+
full: "h:mm:ss a zzzz",
|
| 632 |
+
long: "h:mm:ss a z",
|
| 633 |
+
medium: "h:mm:ss a",
|
| 634 |
+
short: "h:mm a",
|
| 635 |
+
};
|
| 636 |
+
|
| 637 |
+
var formatLong = {
|
| 638 |
+
// ...
|
| 639 |
+
time: buildFormatLongFn({
|
| 640 |
+
formats: timeFormats,
|
| 641 |
+
defaultWidth: "full",
|
| 642 |
+
}),
|
| 643 |
+
// ...
|
| 644 |
+
};
|
| 645 |
+
|
| 646 |
+
export default formatLong;
|
| 647 |
+
```
|
| 648 |
+
|
| 649 |
+
#### formatLong.dateTimeFormats
|
| 650 |
+
|
| 651 |
+
Use
|
| 652 |
+
['Date & Time'/'Gregorian'/'Formats - Standard - Date & Time Combination Formats'](https://www.unicode.org/cldr/charts/32/summary/en.html#1910)
|
| 653 |
+
values from the CLDR chart.
|
| 654 |
+
|
| 655 |
+
```js
|
| 656 |
+
// In `en-US` locale
|
| 657 |
+
import buildFormatLongFn from "../../../_lib/buildFormatLongFn/index.js";
|
| 658 |
+
|
| 659 |
+
var dateTimeFormats = {
|
| 660 |
+
full: "{{date}} 'at' {{time}}",
|
| 661 |
+
long: "{{date}} 'at' {{time}}",
|
| 662 |
+
medium: "{{date}}, {{time}}",
|
| 663 |
+
short: "{{date}}, {{time}}",
|
| 664 |
+
};
|
| 665 |
+
|
| 666 |
+
var formatLong = {
|
| 667 |
+
// ...
|
| 668 |
+
dateTime: buildFormatLongFn({
|
| 669 |
+
formats: dateTimeFormats,
|
| 670 |
+
defaultWidth: "full",
|
| 671 |
+
}),
|
| 672 |
+
};
|
| 673 |
+
|
| 674 |
+
export default formatLong;
|
| 675 |
+
```
|
| 676 |
+
|
| 677 |
+
'{{date}}' and '{{time}}' from the strings will be replaced with the date and time respectively.
|
| 678 |
+
|
| 679 |
+
### formatRelative
|
| 680 |
+
|
| 681 |
+
Put this function in `_lib/formatRelative/index.js` inside your locale directory.
|
| 682 |
+
Relative date formats written in `format` token string format.
|
| 683 |
+
See the list of tokens: https://date-fns.org/docs/format.
|
| 684 |
+
Has to process `lastWeek`, `yesterday`, `today`, `tomorrow`, `nextWeek` and `other` tokens.
|
| 685 |
+
|
| 686 |
+
```javascript
|
| 687 |
+
// In `en-US` locale
|
| 688 |
+
var formatRelativeLocale = {
|
| 689 |
+
lastWeek: "'last' eeee 'at' p",
|
| 690 |
+
yesterday: "'yesterday at' p",
|
| 691 |
+
today: "'today at' p",
|
| 692 |
+
tomorrow: "'tomorrow at' p",
|
| 693 |
+
nextWeek: "eeee 'at' p",
|
| 694 |
+
other: "P",
|
| 695 |
+
};
|
| 696 |
+
|
| 697 |
+
export default function formatRelative(token, date, baseDate, options) {
|
| 698 |
+
return formatRelativeLocale[token];
|
| 699 |
+
}
|
| 700 |
+
```
|
| 701 |
+
|
| 702 |
+
You can use `date` and `baseDate` supplied to the function for the difficult situations
|
| 703 |
+
(e.g. grammatical genders and cases of the days of the week).
|
| 704 |
+
Example is below. Note the different grammatical case for weekdays (accusative instead of nominative)
|
| 705 |
+
and declension of word "прошлый" which depends on the grammatical gender of the weekday:
|
| 706 |
+
|
| 707 |
+
```javascript
|
| 708 |
+
// In `ru` locale
|
| 709 |
+
var accusativeWeekdays = [
|
| 710 |
+
"воскресенье",
|
| 711 |
+
"понедельник",
|
| 712 |
+
"вторник",
|
| 713 |
+
"среду",
|
| 714 |
+
"четверг",
|
| 715 |
+
"пятницу",
|
| 716 |
+
"субботу",
|
| 717 |
+
];
|
| 718 |
+
|
| 719 |
+
function lastWeek(day) {
|
| 720 |
+
var weekday = accusativeWeekdays[day];
|
| 721 |
+
|
| 722 |
+
switch (day) {
|
| 723 |
+
case 0:
|
| 724 |
+
return "'в прошлое " + weekday + " в' p";
|
| 725 |
+
case 1:
|
| 726 |
+
case 2:
|
| 727 |
+
case 4:
|
| 728 |
+
return "'в прошлый " + weekday + " в' p";
|
| 729 |
+
case 3:
|
| 730 |
+
case 5:
|
| 731 |
+
case 6:
|
| 732 |
+
return "'в прошлую " + weekday + " в' p";
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
function thisWeek(day) {
|
| 737 |
+
// ...
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
function nextWeek(day) {
|
| 741 |
+
// ...
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
var formatRelativeLocale = {
|
| 745 |
+
lastWeek: function (date, baseDate, options) {
|
| 746 |
+
var day = date.getDay();
|
| 747 |
+
if (isSameUTCWeek(date, baseDate, options)) {
|
| 748 |
+
return thisWeek(day);
|
| 749 |
+
} else {
|
| 750 |
+
return lastWeek(day);
|
| 751 |
+
}
|
| 752 |
+
},
|
| 753 |
+
yesterday: "'вчера в' p",
|
| 754 |
+
today: "'сегодня в' p",
|
| 755 |
+
tomorrow: "'завтра в' p",
|
| 756 |
+
nextWeek: function (date, baseDate, options) {
|
| 757 |
+
var day = date.getDay();
|
| 758 |
+
if (isSameUTCWeek(date, baseDate, options)) {
|
| 759 |
+
return thisWeek(day);
|
| 760 |
+
} else {
|
| 761 |
+
return nextWeek(day);
|
| 762 |
+
}
|
| 763 |
+
},
|
| 764 |
+
other: "P",
|
| 765 |
+
};
|
| 766 |
+
|
| 767 |
+
export default function formatRelative(token, date, baseDate, options) {
|
| 768 |
+
var format = formatRelativeLocale[token];
|
| 769 |
+
|
| 770 |
+
if (typeof format === "function") {
|
| 771 |
+
return format(date, baseDate, options);
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
return format;
|
| 775 |
+
}
|
| 776 |
+
```
|
| 777 |
+
|
| 778 |
+
### match
|
| 779 |
+
|
| 780 |
+
Put this object in `_lib/match/index.js` inside your locale directory.
|
| 781 |
+
Contains the functions used by `parse` to parse a localized value:
|
| 782 |
+
|
| 783 |
+
```js
|
| 784 |
+
// In `en-US` locale:
|
| 785 |
+
import buildMatchPatternFn from "../../../_lib/buildMatchPatternFn/index.js";
|
| 786 |
+
import buildMatchFn from "../../../_lib/buildMatchFn/index.js";
|
| 787 |
+
|
| 788 |
+
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
| 789 |
+
var parseOrdinalNumberPattern = /\d+/i;
|
| 790 |
+
|
| 791 |
+
var matchEraPatterns = {
|
| 792 |
+
narrow: /^(b|a)/i,
|
| 793 |
+
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
| 794 |
+
wide: /^(before christ|before common era|anno domini|common era)/i,
|
| 795 |
+
};
|
| 796 |
+
var parseEraPatterns = {
|
| 797 |
+
any: [/^b/i, /^(a|c)/i],
|
| 798 |
+
};
|
| 799 |
+
|
| 800 |
+
var matchQuarterPatterns = {
|
| 801 |
+
narrow: /^[1234]/i,
|
| 802 |
+
abbreviated: /^q[1234]/i,
|
| 803 |
+
wide: /^[1234](th|st|nd|rd)? quarter/i,
|
| 804 |
+
};
|
| 805 |
+
var parseQuarterPatterns = {
|
| 806 |
+
any: [/1/i, /2/i, /3/i, /4/i],
|
| 807 |
+
};
|
| 808 |
+
|
| 809 |
+
var matchMonthPatterns = {
|
| 810 |
+
narrow: /^[jfmasond]/i,
|
| 811 |
+
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
| 812 |
+
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i,
|
| 813 |
+
};
|
| 814 |
+
var parseMonthPatterns = {
|
| 815 |
+
narrow: [
|
| 816 |
+
/^j/i,
|
| 817 |
+
/^f/i,
|
| 818 |
+
/^m/i,
|
| 819 |
+
/^a/i,
|
| 820 |
+
/^m/i,
|
| 821 |
+
/^j/i,
|
| 822 |
+
/^j/i,
|
| 823 |
+
/^a/i,
|
| 824 |
+
/^s/i,
|
| 825 |
+
/^o/i,
|
| 826 |
+
/^n/i,
|
| 827 |
+
/^d/i,
|
| 828 |
+
],
|
| 829 |
+
any: [
|
| 830 |
+
/^ja/i,
|
| 831 |
+
/^f/i,
|
| 832 |
+
/^mar/i,
|
| 833 |
+
/^ap/i,
|
| 834 |
+
/^may/i,
|
| 835 |
+
/^jun/i,
|
| 836 |
+
/^jul/i,
|
| 837 |
+
/^au/i,
|
| 838 |
+
/^s/i,
|
| 839 |
+
/^o/i,
|
| 840 |
+
/^n/i,
|
| 841 |
+
/^d/i,
|
| 842 |
+
],
|
| 843 |
+
};
|
| 844 |
+
|
| 845 |
+
var matchDayPatterns = {
|
| 846 |
+
narrow: /^[smtwf]/i,
|
| 847 |
+
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
| 848 |
+
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
| 849 |
+
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i,
|
| 850 |
+
};
|
| 851 |
+
var parseDayPatterns = {
|
| 852 |
+
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
| 853 |
+
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
|
| 854 |
+
};
|
| 855 |
+
|
| 856 |
+
var matchDayPeriodPatterns = {
|
| 857 |
+
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
| 858 |
+
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i,
|
| 859 |
+
};
|
| 860 |
+
var parseDayPeriodPatterns = {
|
| 861 |
+
any: {
|
| 862 |
+
am: /^a/i,
|
| 863 |
+
pm: /^p/i,
|
| 864 |
+
midnight: /^mi/i,
|
| 865 |
+
noon: /^no/i,
|
| 866 |
+
morning: /morning/i,
|
| 867 |
+
afternoon: /afternoon/i,
|
| 868 |
+
evening: /evening/i,
|
| 869 |
+
night: /night/i,
|
| 870 |
+
},
|
| 871 |
+
};
|
| 872 |
+
|
| 873 |
+
var match = {
|
| 874 |
+
ordinalNumber: buildMatchPatternFn({
|
| 875 |
+
matchPattern: matchOrdinalNumberPattern,
|
| 876 |
+
parsePattern: parseOrdinalNumberPattern,
|
| 877 |
+
valueCallback: function (value) {
|
| 878 |
+
return parseInt(value, 10);
|
| 879 |
+
},
|
| 880 |
+
}),
|
| 881 |
+
|
| 882 |
+
era: buildMatchFn({
|
| 883 |
+
matchPatterns: matchEraPatterns,
|
| 884 |
+
defaultMatchWidth: "wide",
|
| 885 |
+
parsePatterns: parseEraPatterns,
|
| 886 |
+
defaultParseWidth: "any",
|
| 887 |
+
}),
|
| 888 |
+
|
| 889 |
+
quarter: buildMatchFn({
|
| 890 |
+
matchPatterns: matchQuarterPatterns,
|
| 891 |
+
defaultMatchWidth: "wide",
|
| 892 |
+
parsePatterns: parseQuarterPatterns,
|
| 893 |
+
defaultParseWidth: "any",
|
| 894 |
+
valueCallback: function (index) {
|
| 895 |
+
return index + 1;
|
| 896 |
+
},
|
| 897 |
+
}),
|
| 898 |
+
|
| 899 |
+
month: buildMatchFn({
|
| 900 |
+
matchPatterns: matchMonthPatterns,
|
| 901 |
+
defaultMatchWidth: "wide",
|
| 902 |
+
parsePatterns: parseMonthPatterns,
|
| 903 |
+
defaultParseWidth: "any",
|
| 904 |
+
}),
|
| 905 |
+
|
| 906 |
+
day: buildMatchFn({
|
| 907 |
+
matchPatterns: matchDayPatterns,
|
| 908 |
+
defaultMatchWidth: "wide",
|
| 909 |
+
parsePatterns: parseDayPatterns,
|
| 910 |
+
defaultParseWidth: "any",
|
| 911 |
+
}),
|
| 912 |
+
|
| 913 |
+
dayPeriod: buildMatchFn({
|
| 914 |
+
matchPatterns: matchDayPeriodPatterns,
|
| 915 |
+
defaultMatchWidth: "any",
|
| 916 |
+
parsePatterns: parseDayPeriodPatterns,
|
| 917 |
+
defaultParseWidth: "any",
|
| 918 |
+
}),
|
| 919 |
+
};
|
| 920 |
+
|
| 921 |
+
export default match;
|
| 922 |
+
```
|
| 923 |
+
|
| 924 |
+
These functions mirror those in `localize`.
|
| 925 |
+
|
| 926 |
+
For `matchPatterns` the patterns should match the whole meaningful word for the parsed value
|
| 927 |
+
(which will be cut from the string in the process of parsing).
|
| 928 |
+
`parsePatterns` contains patterns to detect one of the values from the result of `matchPatterns`
|
| 929 |
+
Note that the patterns for `parsePatterns` don't necessary contain the whole word:
|
| 930 |
+
|
| 931 |
+
```javascript
|
| 932 |
+
// In `en-US` locale:
|
| 933 |
+
var parseDayPatterns = {
|
| 934 |
+
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
| 935 |
+
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i],
|
| 936 |
+
};
|
| 937 |
+
```
|
| 938 |
+
|
| 939 |
+
but only the bare minimum to parse the value.
|
| 940 |
+
|
| 941 |
+
Also note that all patterns have "case-insensitive" flags
|
| 942 |
+
to match as much arbitrary user input as possible. For the same reason, try to match
|
| 943 |
+
any variation of diacritical marks:
|
| 944 |
+
|
| 945 |
+
```javascript
|
| 946 |
+
// In `eo` locale:
|
| 947 |
+
var matchDayPatterns = {
|
| 948 |
+
narrow: /^[dlmĵjvs]/i,
|
| 949 |
+
short: /^(di|lu|ma|me|(ĵ|jx|jh|j)a|ve|sa)/i,
|
| 950 |
+
abbreviated: /^(dim|lun|mar|mer|(ĵ|jx|jh|j)a(ŭ|ux|uh|u)|ven|sab)/i,
|
| 951 |
+
wide: /^(diman(ĉ|cx|ch|c)o|lundo|mardo|merkredo|(ĵ|jx|jh|j)a(ŭ|ux|uh|u)do|vendredo|sabato)/i,
|
| 952 |
+
};
|
| 953 |
+
var parseDayPatterns = {
|
| 954 |
+
narrow: [/^d/i, /^l/i, /^m/i, /^m/i, /^(j|ĵ)/i, /^v/i, /^s/i],
|
| 955 |
+
any: [/^d/i, /^l/i, /^ma/i, /^me/i, /^(j|ĵ)/i, /^v/i, /^s/i],
|
| 956 |
+
};
|
| 957 |
+
```
|
| 958 |
+
|
| 959 |
+
Here, for the word "dimanĉo" the functions will match also "dimancxo", "dimancho"
|
| 960 |
+
and even grammatically incorrect "dimanco".
|
| 961 |
+
|
| 962 |
+
Try to match any possible way of writing the word. Don't forget the grammatical cases:
|
| 963 |
+
|
| 964 |
+
```javascript
|
| 965 |
+
// In `ru` locale:
|
| 966 |
+
var matchMonthPatterns = {
|
| 967 |
+
narrow: /^[яфмаисонд]/i,
|
| 968 |
+
abbreviated:
|
| 969 |
+
/^(янв|фев|март?|апр|ма[йя]|июн[ья]?|июл[ья]?|авг|сент?|окт|нояб?|дек)/i,
|
| 970 |
+
wide: /^(январ[ья]|феврал[ья]|марта?|апрел[ья]|ма[йя]|июн[ья]|июл[ья]|августа?|сентябр[ья]|октябр[ья]|октябр[ья]|ноябр[ья]|декабр[ья])/i,
|
| 971 |
+
};
|
| 972 |
+
```
|
| 973 |
+
|
| 974 |
+
and variations of short weekdays and months:
|
| 975 |
+
|
| 976 |
+
```javascript
|
| 977 |
+
// In `ru` locale:
|
| 978 |
+
var matchDayPatterns = {
|
| 979 |
+
narrow: /^[впсч]/i,
|
| 980 |
+
short: /^(вс|во|пн|по|вт|ср|чт|че|пт|пя|сб|су)\.?/i,
|
| 981 |
+
abbreviated: /^(вск|вос|пнд|пон|втр|вто|срд|сре|чтв|чет|птн|пят|суб).?/i,
|
| 982 |
+
wide: /^(воскресень[ея]|понедельника?|вторника?|сред[аы]|четверга?|пятниц[аы]|суббот[аы])/i,
|
| 983 |
+
};
|
| 984 |
+
```
|
| 985 |
+
|
| 986 |
+
(here, the `abbreviated` pattern will match both `вск` and `вос` as the short of `воскресенье` {Sunday})
|
| 987 |
+
|
| 988 |
+
In `match.ordinalNumber` match ordinal numbers as well as non-ordinal numbers:
|
| 989 |
+
|
| 990 |
+
```javascript
|
| 991 |
+
// In `en-US` locale:
|
| 992 |
+
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
| 993 |
+
```
|
| 994 |
+
|
| 995 |
+
Don't forget the grammatical genders:
|
| 996 |
+
|
| 997 |
+
```javascript
|
| 998 |
+
// In `ru` locale:
|
| 999 |
+
var matchOrdinalNumberPattern = /^(\d+)(-?(е|я|й|ое|ье|ая|ья|ый|ой|ий|ый))?/i;
|
| 1000 |
+
```
|
| 1001 |
+
|
| 1002 |
+
### formatDistance
|
| 1003 |
+
|
| 1004 |
+
`formatDistance` property of locale is a function which takes three arguments:
|
| 1005 |
+
token passed by date-fns' `formatDistance` function (e.g. 'lessThanXMinutes'),
|
| 1006 |
+
a number of units to be displayed by the function
|
| 1007 |
+
(e.g. `locale.formatDistance('lessThanXMinutes', 5)` would display localized 'less than 5 minutes')
|
| 1008 |
+
and object with options.
|
| 1009 |
+
|
| 1010 |
+
Your best guess is to copy `formatDistance` property from another locale and change the values.
|
| 1011 |
+
|
| 1012 |
+
### Tests
|
| 1013 |
+
|
| 1014 |
+
To test locales we use snapshots. See [`en-US` snapshot](https://github.com/date-fns/date-fns/blob/master/src/locale/en-US/snapshot.md) for an example.
|
| 1015 |
+
|
| 1016 |
+
To generate snapshots, run `pnpm run locale-snapshots`. The snapshot for the locale
|
| 1017 |
+
you're working on will appear in the root locale directory (e.g. `src/locales/ru/snapshot.md`).
|
| 1018 |
+
|
| 1019 |
+
Once you are done with the locale, generate the snapshot and review the output values.
|
| 1020 |
+
|
| 1021 |
+
## Creating a locale with the same language as another locale
|
| 1022 |
+
|
| 1023 |
+
Import the locale properties already implemented for the language,
|
| 1024 |
+
but replace unique properties.
|
| 1025 |
+
|
| 1026 |
+
```javascript
|
| 1027 |
+
// Same as en-US
|
| 1028 |
+
import formatDistance from "../en-US/_lib/formatDistance/index.js";
|
| 1029 |
+
import formatRelative from "../en-US/_lib/formatRelative/index.js";
|
| 1030 |
+
import localize from "../en-US/_lib/localize/index.js";
|
| 1031 |
+
import match from "../en-US/_lib/match/index.js";
|
| 1032 |
+
|
| 1033 |
+
// Unique for en-GB
|
| 1034 |
+
import formatLong from "./_lib/formatLong/index.js";
|
| 1035 |
+
|
| 1036 |
+
/**
|
| 1037 |
+
* @type {Locale}
|
| 1038 |
+
* @category Locales
|
| 1039 |
+
* @summary English locale (United Kingdom).
|
| 1040 |
+
* @language English
|
| 1041 |
+
* @iso-639-2 eng
|
| 1042 |
+
* @author John Doe [@example]{@link https://github.com/example}
|
| 1043 |
+
*/
|
| 1044 |
+
var locale = {
|
| 1045 |
+
formatDistance: formatDistance,
|
| 1046 |
+
formatLong: formatLong,
|
| 1047 |
+
formatRelative: formatRelative,
|
| 1048 |
+
localize: localize,
|
| 1049 |
+
match: match,
|
| 1050 |
+
|
| 1051 |
+
// Unique for en-GB
|
| 1052 |
+
options: {
|
| 1053 |
+
weekStartsOn: 1,
|
| 1054 |
+
firstWeekContainsDate: 4,
|
| 1055 |
+
},
|
| 1056 |
+
};
|
| 1057 |
+
|
| 1058 |
+
export default locale;
|
| 1059 |
+
```
|