UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const constants_1 = require("../constants");
4const years_1 = require("../../../calculation/years");
5const pattern_1 = require("../../../utils/pattern");
6const constants_2 = require("../constants");
7const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
8const 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");
14const MONTH_NAME_GROUP = 1;
15const YEAR_GROUP = 2;
16class 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}
37exports.default = NLMonthNameParser;