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

20 lines
494 B
JavaScript
Raw Normal View History

2024-05-14 14:54:12 +00:00
import { Parser } from "../Parser.mjs";
import { mapValue, parseNDigits } from "../utils.mjs";
export class FractionOfSecondParser extends Parser {
priority = 30;
parse(dateString, token) {
const valueCallback = (value) =>
Math.trunc(value * Math.pow(10, -token.length + 3));
return mapValue(parseNDigits(token.length, dateString), valueCallback);
}
set(date, _flags, value) {
date.setMilliseconds(value);
return date;
}
incompatibleTokens = ["t", "T"];
}