Files
klz-cables.com/.pnpm-store/v10/files/c2/4a028616242366cecc83ee2c2b76db2f52ae238c34f0fd4f59b8ad4f5957529c1d7bfa617348146bc21a781fee96e961ad70aacdbab49a742f3a86346c7380
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

61 lines
1.8 KiB
Plaintext

import { Parser } from "../Parser.mjs";
import { mapValue, normalizeTwoDigitYear, parseNDigits } from "../utils.mjs";
// From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
// | Year | y | yy | yyy | yyyy | yyyyy |
// |----------|-------|----|-------|-------|-------|
// | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
// | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
// | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
// | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
// | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
export class YearParser extends Parser {
priority = 130;
incompatibleTokens = ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"];
parse(dateString, token, match) {
const valueCallback = (year) => ({
year,
isTwoDigitYear: token === "yy",
});
switch (token) {
case "y":
return mapValue(parseNDigits(4, dateString), valueCallback);
case "yo":
return mapValue(
match.ordinalNumber(dateString, {
unit: "year",
}),
valueCallback,
);
default:
return mapValue(parseNDigits(token.length, dateString), valueCallback);
}
}
validate(_date, value) {
return value.isTwoDigitYear || value.year > 0;
}
set(date, flags, value) {
const currentYear = date.getFullYear();
if (value.isTwoDigitYear) {
const normalizedTwoDigitYear = normalizeTwoDigitYear(
value.year,
currentYear,
);
date.setFullYear(normalizedTwoDigitYear, 0, 1);
date.setHours(0, 0, 0, 0);
return date;
}
const year =
!("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
date.setFullYear(year, 0, 1);
date.setHours(0, 0, 0, 0);
return date;
}
}