LocalWeekParser.mjs
983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { setWeek } from "../../../setWeek.mjs";
import { startOfWeek } from "../../../startOfWeek.mjs";
import { numericPatterns } from "../constants.mjs";
import { Parser } from "../Parser.mjs";
import { parseNDigits, parseNumericPattern } from "../utils.mjs";
// Local week of year
export class LocalWeekParser extends Parser {
priority = 100;
parse(dateString, token, match) {
switch (token) {
case "w":
return parseNumericPattern(numericPatterns.week, dateString);
case "wo":
return match.ordinalNumber(dateString, { unit: "week" });
default:
return parseNDigits(token.length, dateString);
}
}
validate(_date, value) {
return value >= 1 && value <= 53;
}
set(date, _flags, value, options) {
return startOfWeek(setWeek(date, value, options), options);
}
incompatibleTokens = [
"y",
"R",
"u",
"q",
"Q",
"M",
"L",
"I",
"d",
"D",
"i",
"t",
"T",
];
}