30 lines
720 B
JavaScript
30 lines
720 B
JavaScript
|
import { numericPatterns } from "../constants.mjs";
|
||
|
import { Parser } from "../Parser.mjs";
|
||
|
import { parseNDigits, parseNumericPattern } from "../utils.mjs";
|
||
|
|
||
|
export class SecondParser extends Parser {
|
||
|
priority = 50;
|
||
|
|
||
|
parse(dateString, token, match) {
|
||
|
switch (token) {
|
||
|
case "s":
|
||
|
return parseNumericPattern(numericPatterns.second, dateString);
|
||
|
case "so":
|
||
|
return match.ordinalNumber(dateString, { unit: "second" });
|
||
|
default:
|
||
|
return parseNDigits(token.length, dateString);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
validate(_date, value) {
|
||
|
return value >= 0 && value <= 59;
|
||
|
}
|
||
|
|
||
|
set(date, _flags, value) {
|
||
|
date.setSeconds(value, 0);
|
||
|
return date;
|
||
|
}
|
||
|
|
||
|
incompatibleTokens = ["t", "T"];
|
||
|
}
|