1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const constants_1 = require("../constants");
|
4 | const years_1 = require("../../../calculation/years");
|
5 | const pattern_1 = require("../../../utils/pattern");
|
6 | const constants_2 = require("../constants");
|
7 | const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
8 | const PATTERN = new RegExp(`(${pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY)})` +
|
9 | `\\s*` +
|
10 | `(?:` +
|
11 | `[,-]?\\s*(${constants_2.YEAR_PATTERN})?` +
|
12 | ")?" +
|
13 | "(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)", "i");
|
14 | const MONTH_NAME_GROUP = 1;
|
15 | const YEAR_GROUP = 2;
|
16 | class NLMonthNameParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
17 | innerPattern() {
|
18 | return PATTERN;
|
19 | }
|
20 | innerExtract(context, match) {
|
21 | const components = context.createParsingComponents();
|
22 | components.imply("day", 1);
|
23 | const monthName = match[MONTH_NAME_GROUP];
|
24 | const month = constants_1.MONTH_DICTIONARY[monthName.toLowerCase()];
|
25 | components.assign("month", month);
|
26 | if (match[YEAR_GROUP]) {
|
27 | const year = constants_2.parseYear(match[YEAR_GROUP]);
|
28 | components.assign("year", year);
|
29 | }
|
30 | else {
|
31 | const year = years_1.findYearClosestToRef(context.refDate, 1, month);
|
32 | components.imply("year", year);
|
33 | }
|
34 | return components;
|
35 | }
|
36 | }
|
37 | exports.default = NLMonthNameParser;
|