timepiece/node_modules/date-fns/parse/_lib/parsers/Hour0to23Parser.mjs

30 lines
751 B
JavaScript

import { numericPatterns } from "../constants.mjs";
import { Parser } from "../Parser.mjs";
import { parseNDigits, parseNumericPattern } from "../utils.mjs";
export class Hour0to23Parser extends Parser {
priority = 70;
parse(dateString, token, match) {
switch (token) {
case "H":
return parseNumericPattern(numericPatterns.hour23h, dateString);
case "Ho":
return match.ordinalNumber(dateString, { unit: "hour" });
default:
return parseNDigits(token.length, dateString);
}
}
validate(_date, value) {
return value >= 0 && value <= 23;
}
set(date, _flags, value) {
date.setHours(value, 0, 0, 0);
return date;
}
incompatibleTokens = ["a", "b", "h", "K", "k", "t", "T"];
}