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
35 lines
874 B
Plaintext
35 lines
874 B
Plaintext
import { numericPatterns } from "../constants.mjs";
|
|
import { Parser } from "../Parser.mjs";
|
|
import { parseNDigits, parseNumericPattern } from "../utils.mjs";
|
|
|
|
export class Hour0To11Parser extends Parser {
|
|
priority = 70;
|
|
|
|
parse(dateString, token, match) {
|
|
switch (token) {
|
|
case "K":
|
|
return parseNumericPattern(numericPatterns.hour11h, dateString);
|
|
case "Ko":
|
|
return match.ordinalNumber(dateString, { unit: "hour" });
|
|
default:
|
|
return parseNDigits(token.length, dateString);
|
|
}
|
|
}
|
|
|
|
validate(_date, value) {
|
|
return value >= 0 && value <= 11;
|
|
}
|
|
|
|
set(date, _flags, value) {
|
|
const isPM = date.getHours() >= 12;
|
|
if (isPM && value < 12) {
|
|
date.setHours(value + 12, 0, 0, 0);
|
|
} else {
|
|
date.setHours(value, 0, 0, 0);
|
|
}
|
|
return date;
|
|
}
|
|
|
|
incompatibleTokens = ["h", "H", "k", "t", "T"];
|
|
}
|