Files
klz-cables.com/.pnpm-store/v10/files/29/11ebeb2e52f6967859cb424cb61e71bb0d427863a2e353552fe2a4a6dbb95031975ba10ebb804cda2fa3a13f23ceaeea78dfacd296109126c13adeeba05820
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

93 lines
2.8 KiB
Plaintext

"use strict";
exports.formatRelative = formatRelative;
var _index = require("./_lib/defaultLocale.cjs");
var _index2 = require("./_lib/defaultOptions.cjs");
var _index3 = require("./_lib/normalizeDates.cjs");
var _index4 = require("./differenceInCalendarDays.cjs");
var _index5 = require("./format.cjs");
/**
* The {@link formatRelative} function options.
*/
/**
* @name formatRelative
* @category Common Helpers
* @summary Represent the date in words relative to the given base date.
*
* @description
* Represent the date in words relative to the given base date.
*
* | Distance to the base date | Result |
* |---------------------------|---------------------------|
* | Previous 6 days | last Sunday at 04:30 AM |
* | Last day | yesterday at 04:30 AM |
* | Same day | today at 04:30 AM |
* | Next day | tomorrow at 04:30 AM |
* | Next 6 days | Sunday at 04:30 AM |
* | Other | 12/31/2017 |
*
* @param date - The date to format
* @param baseDate - The date to compare with
* @param options - An object with options
*
* @returns The date in words
*
* @throws `date` must not be Invalid Date
* @throws `baseDate` must not be Invalid Date
* @throws `options.locale` must contain `localize` property
* @throws `options.locale` must contain `formatLong` property
* @throws `options.locale` must contain `formatRelative` property
*
* @example
* // Represent the date of 6 days ago in words relative to the given base date. In this example, today is Wednesday
* const result = formatRelative(subDays(new Date(), 6), new Date())
* //=> "last Thursday at 12:45 AM"
*/
function formatRelative(date, baseDate, options) {
const [date_, baseDate_] = (0, _index3.normalizeDates)(
options?.in,
date,
baseDate,
);
const defaultOptions = (0, _index2.getDefaultOptions)();
const locale =
options?.locale ?? defaultOptions.locale ?? _index.defaultLocale;
const weekStartsOn =
options?.weekStartsOn ??
options?.locale?.options?.weekStartsOn ??
defaultOptions.weekStartsOn ??
defaultOptions.locale?.options?.weekStartsOn ??
0;
const diff = (0, _index4.differenceInCalendarDays)(date_, baseDate_);
if (isNaN(diff)) {
throw new RangeError("Invalid time value");
}
let token;
if (diff < -6) {
token = "other";
} else if (diff < -1) {
token = "lastWeek";
} else if (diff < 0) {
token = "yesterday";
} else if (diff < 1) {
token = "today";
} else if (diff < 2) {
token = "tomorrow";
} else if (diff < 7) {
token = "nextWeek";
} else {
token = "other";
}
const formatStr = locale.formatRelative(token, date_, baseDate_, {
locale,
weekStartsOn,
});
return (0, _index5.format)(date_, formatStr, { locale, weekStartsOn });
}