date-fns
Version:
Modern JavaScript date utility library
21 lines (15 loc) • 493 B
JavaScript
import { Parser } from "../Parser.js";
import { mapValue, parseNDigits } from "../utils.js";
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"];
}