registration
This commit is contained in:
75
frontend/style/node_modules/date-fns/formatDistance.js
generated
vendored
75
frontend/style/node_modules/date-fns/formatDistance.js
generated
vendored
@@ -1,14 +1,11 @@
|
||||
"use strict";
|
||||
exports.formatDistance = formatDistance;
|
||||
var _index = require("./compareAsc.js");
|
||||
var _index2 = require("./constants.js");
|
||||
var _index3 = require("./differenceInMonths.js");
|
||||
var _index4 = require("./differenceInSeconds.js");
|
||||
var _index5 = require("./toDate.js");
|
||||
|
||||
var _index6 = require("./_lib/defaultLocale.js");
|
||||
var _index7 = require("./_lib/defaultOptions.js");
|
||||
var _index8 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
|
||||
import { defaultLocale } from "./_lib/defaultLocale.js";
|
||||
import { getDefaultOptions } from "./_lib/defaultOptions.js";
|
||||
import { getTimezoneOffsetInMilliseconds } from "./_lib/getTimezoneOffsetInMilliseconds.js";
|
||||
import { normalizeDates } from "./_lib/normalizeDates.js";
|
||||
import { compareAsc } from "./compareAsc.js";
|
||||
import { minutesInDay, minutesInMonth } from "./constants.js";
|
||||
import { differenceInMonths } from "./differenceInMonths.js";
|
||||
import { differenceInSeconds } from "./differenceInSeconds.js";
|
||||
|
||||
/**
|
||||
* The {@link formatDistance} function options.
|
||||
@@ -51,10 +48,8 @@ var _index8 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
|
||||
* | 40 secs ... 60 secs | less than a minute |
|
||||
* | 60 secs ... 90 secs | 1 minute |
|
||||
*
|
||||
* @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
|
||||
@@ -94,38 +89,29 @@ var _index8 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
|
||||
* })
|
||||
* //=> 'pli ol 1 jaro'
|
||||
*/
|
||||
|
||||
function formatDistance(date, baseDate, options) {
|
||||
const defaultOptions = (0, _index7.getDefaultOptions)();
|
||||
const locale =
|
||||
options?.locale ?? defaultOptions.locale ?? _index6.defaultLocale;
|
||||
export function formatDistance(laterDate, earlierDate, options) {
|
||||
const defaultOptions = getDefaultOptions();
|
||||
const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale;
|
||||
const minutesInAlmostTwoDays = 2520;
|
||||
|
||||
const comparison = (0, _index.compareAsc)(date, baseDate);
|
||||
const comparison = compareAsc(laterDate, earlierDate);
|
||||
|
||||
if (isNaN(comparison)) {
|
||||
throw new RangeError("Invalid time value");
|
||||
}
|
||||
if (isNaN(comparison)) throw new RangeError("Invalid time value");
|
||||
|
||||
const localizeOptions = Object.assign({}, options, {
|
||||
addSuffix: options?.addSuffix,
|
||||
comparison: comparison,
|
||||
});
|
||||
|
||||
let dateLeft;
|
||||
let dateRight;
|
||||
if (comparison > 0) {
|
||||
dateLeft = (0, _index5.toDate)(baseDate);
|
||||
dateRight = (0, _index5.toDate)(date);
|
||||
} else {
|
||||
dateLeft = (0, _index5.toDate)(date);
|
||||
dateRight = (0, _index5.toDate)(baseDate);
|
||||
}
|
||||
const [laterDate_, earlierDate_] = normalizeDates(
|
||||
options?.in,
|
||||
...(comparison > 0 ? [earlierDate, laterDate] : [laterDate, earlierDate]),
|
||||
);
|
||||
|
||||
const seconds = (0, _index4.differenceInSeconds)(dateRight, dateLeft);
|
||||
const seconds = differenceInSeconds(earlierDate_, laterDate_);
|
||||
const offsetInSeconds =
|
||||
((0, _index8.getTimezoneOffsetInMilliseconds)(dateRight) -
|
||||
(0, _index8.getTimezoneOffsetInMilliseconds)(dateLeft)) /
|
||||
(getTimezoneOffsetInMilliseconds(earlierDate_) -
|
||||
getTimezoneOffsetInMilliseconds(laterDate_)) /
|
||||
1000;
|
||||
const minutes = Math.round((seconds - offsetInSeconds) / 60);
|
||||
let months;
|
||||
@@ -163,7 +149,7 @@ function formatDistance(date, baseDate, options) {
|
||||
return locale.formatDistance("aboutXHours", 1, localizeOptions);
|
||||
|
||||
// 1.5 hrs up to 24 hrs
|
||||
} else if (minutes < _index2.minutesInDay) {
|
||||
} else if (minutes < minutesInDay) {
|
||||
const hours = Math.round(minutes / 60);
|
||||
return locale.formatDistance("aboutXHours", hours, localizeOptions);
|
||||
|
||||
@@ -172,21 +158,21 @@ function formatDistance(date, baseDate, options) {
|
||||
return locale.formatDistance("xDays", 1, localizeOptions);
|
||||
|
||||
// 1.75 days up to 30 days
|
||||
} else if (minutes < _index2.minutesInMonth) {
|
||||
const days = Math.round(minutes / _index2.minutesInDay);
|
||||
} else if (minutes < minutesInMonth) {
|
||||
const days = Math.round(minutes / minutesInDay);
|
||||
return locale.formatDistance("xDays", days, localizeOptions);
|
||||
|
||||
// 1 month up to 2 months
|
||||
} else if (minutes < _index2.minutesInMonth * 2) {
|
||||
months = Math.round(minutes / _index2.minutesInMonth);
|
||||
} else if (minutes < minutesInMonth * 2) {
|
||||
months = Math.round(minutes / minutesInMonth);
|
||||
return locale.formatDistance("aboutXMonths", months, localizeOptions);
|
||||
}
|
||||
|
||||
months = (0, _index3.differenceInMonths)(dateRight, dateLeft);
|
||||
months = differenceInMonths(earlierDate_, laterDate_);
|
||||
|
||||
// 2 months up to 12 months
|
||||
if (months < 12) {
|
||||
const nearestMonth = Math.round(minutes / _index2.minutesInMonth);
|
||||
const nearestMonth = Math.round(minutes / minutesInMonth);
|
||||
return locale.formatDistance("xMonths", nearestMonth, localizeOptions);
|
||||
|
||||
// 1 year up to max Date
|
||||
@@ -208,3 +194,6 @@ function formatDistance(date, baseDate, options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for modularized imports:
|
||||
export default formatDistance;
|
||||
|
||||
Reference in New Issue
Block a user