1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const constants_1 = require("../../nl/constants");
|
4 | const pattern_1 = require("../../../utils/pattern");
|
5 | const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
6 | const weeks_1 = require("../../../calculation/weeks");
|
7 | const PATTERN = new RegExp("(?:(?:\\,|\\(|\\()\\s*)?" +
|
8 | "(?:op\\s*?)?" +
|
9 | "(?:(deze|vorige|volgende)\\s*(?:week\\s*)?)?" +
|
10 | `(${pattern_1.matchAnyPattern(constants_1.WEEKDAY_DICTIONARY)})` +
|
11 | "(?=\\W|$)", "i");
|
12 | const PREFIX_GROUP = 1;
|
13 | const WEEKDAY_GROUP = 2;
|
14 | const POSTFIX_GROUP = 3;
|
15 | class NLWeekdayParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
16 | innerPattern() {
|
17 | return PATTERN;
|
18 | }
|
19 | innerExtract(context, match) {
|
20 | const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
21 | const offset = constants_1.WEEKDAY_DICTIONARY[dayOfWeek];
|
22 | const prefix = match[PREFIX_GROUP];
|
23 | const postfix = match[POSTFIX_GROUP];
|
24 | let modifierWord = prefix || postfix;
|
25 | modifierWord = modifierWord || "";
|
26 | modifierWord = modifierWord.toLowerCase();
|
27 | let modifier = null;
|
28 | if (modifierWord == "vorige") {
|
29 | modifier = "last";
|
30 | }
|
31 | else if (modifierWord == "volgende") {
|
32 | modifier = "next";
|
33 | }
|
34 | else if (modifierWord == "deze") {
|
35 | modifier = "this";
|
36 | }
|
37 | const date = weeks_1.toDayJSWeekday(context.refDate, offset, modifier);
|
38 | return context
|
39 | .createParsingComponents()
|
40 | .assign("weekday", offset)
|
41 | .imply("day", date.date())
|
42 | .imply("month", date.month() + 1)
|
43 | .imply("year", date.year());
|
44 | }
|
45 | }
|
46 | exports.default = NLWeekdayParser;
|