registration

This commit is contained in:
User
2025-02-02 16:08:03 +03:00
parent 7f6495eb4d
commit 78afbaed71
6334 changed files with 196774 additions and 165754 deletions

View File

@@ -1,13 +1,15 @@
"use strict";
exports.formatDistanceStrict = formatDistanceStrict;
var _index = require("./_lib/defaultLocale.js");
var _index2 = require("./_lib/defaultOptions.js");
var _index3 = require("./_lib/getRoundingMethod.js");
var _index4 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
var _index5 = require("./compareAsc.js");
var _index6 = require("./constants.js");
var _index7 = require("./toDate.js");
import { defaultLocale } from "./_lib/defaultLocale.js";
import { getDefaultOptions } from "./_lib/defaultOptions.js";
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
import { getTimezoneOffsetInMilliseconds } from "./_lib/getTimezoneOffsetInMilliseconds.js";
import { normalizeDates } from "./_lib/normalizeDates.js";
import { compareAsc } from "./compareAsc.js";
import {
millisecondsInMinute,
minutesInDay,
minutesInMonth,
minutesInYear,
} from "./constants.js";
/**
* The {@link formatDistanceStrict} function options.
@@ -36,10 +38,8 @@ var _index7 = require("./toDate.js");
* | 1 ... 11 months | [1..11] months |
* | 1 ... N years | [1..N] years |
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The date
* @param baseDate - The date to compare with
* @param laterDate - The date
* @param earlierDate - The date to compare with
* @param options - An object with options
*
* @returns The distance in words
@@ -97,12 +97,11 @@ var _index7 = require("./toDate.js");
* //=> '1 jaro'
*/
function formatDistanceStrict(date, baseDate, options) {
const defaultOptions = (0, _index2.getDefaultOptions)();
const locale =
options?.locale ?? defaultOptions.locale ?? _index.defaultLocale;
export function formatDistanceStrict(laterDate, earlierDate, options) {
const defaultOptions = getDefaultOptions();
const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale;
const comparison = (0, _index5.compareAsc)(date, baseDate);
const comparison = compareAsc(laterDate, earlierDate);
if (isNaN(comparison)) {
throw new RangeError("Invalid time value");
@@ -113,31 +112,24 @@ function formatDistanceStrict(date, baseDate, options) {
comparison: comparison,
});
let dateLeft;
let dateRight;
if (comparison > 0) {
dateLeft = (0, _index7.toDate)(baseDate);
dateRight = (0, _index7.toDate)(date);
} else {
dateLeft = (0, _index7.toDate)(date);
dateRight = (0, _index7.toDate)(baseDate);
}
const roundingMethod = (0, _index3.getRoundingMethod)(
options?.roundingMethod ?? "round",
const [laterDate_, earlierDate_] = normalizeDates(
options?.in,
...(comparison > 0 ? [earlierDate, laterDate] : [laterDate, earlierDate]),
);
const milliseconds = dateRight.getTime() - dateLeft.getTime();
const minutes = milliseconds / _index6.millisecondsInMinute;
const roundingMethod = getRoundingMethod(options?.roundingMethod ?? "round");
const milliseconds = earlierDate_.getTime() - laterDate_.getTime();
const minutes = milliseconds / millisecondsInMinute;
const timezoneOffset =
(0, _index4.getTimezoneOffsetInMilliseconds)(dateRight) -
(0, _index4.getTimezoneOffsetInMilliseconds)(dateLeft);
getTimezoneOffsetInMilliseconds(earlierDate_) -
getTimezoneOffsetInMilliseconds(laterDate_);
// Use DST-normalized difference in minutes for years, months and days;
// use regular difference in minutes for hours, minutes and seconds.
const dstNormalizedMinutes =
(milliseconds - timezoneOffset) / _index6.millisecondsInMinute;
(milliseconds - timezoneOffset) / millisecondsInMinute;
const defaultUnit = options?.unit;
let unit;
@@ -146,11 +138,11 @@ function formatDistanceStrict(date, baseDate, options) {
unit = "second";
} else if (minutes < 60) {
unit = "minute";
} else if (minutes < _index6.minutesInDay) {
} else if (minutes < minutesInDay) {
unit = "hour";
} else if (dstNormalizedMinutes < _index6.minutesInMonth) {
} else if (dstNormalizedMinutes < minutesInMonth) {
unit = "day";
} else if (dstNormalizedMinutes < _index6.minutesInYear) {
} else if (dstNormalizedMinutes < minutesInYear) {
unit = "month";
} else {
unit = "year";
@@ -176,21 +168,22 @@ function formatDistanceStrict(date, baseDate, options) {
// 1 up to 30 days
} else if (unit === "day") {
const days = roundingMethod(dstNormalizedMinutes / _index6.minutesInDay);
const days = roundingMethod(dstNormalizedMinutes / minutesInDay);
return locale.formatDistance("xDays", days, localizeOptions);
// 1 up to 12 months
} else if (unit === "month") {
const months = roundingMethod(
dstNormalizedMinutes / _index6.minutesInMonth,
);
const months = roundingMethod(dstNormalizedMinutes / minutesInMonth);
return months === 12 && defaultUnit !== "month"
? locale.formatDistance("xYears", 1, localizeOptions)
: locale.formatDistance("xMonths", months, localizeOptions);
// 1 year up to max Date
} else {
const years = roundingMethod(dstNormalizedMinutes / _index6.minutesInYear);
const years = roundingMethod(dstNormalizedMinutes / minutesInYear);
return locale.formatDistance("xYears", years, localizeOptions);
}
}
// Fallback for modularized imports:
export default formatDistanceStrict;