1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const years_1 = require("../../../calculation/years");
|
4 | const constants_1 = require("../constants");
|
5 | const constants_2 = require("../constants");
|
6 | const constants_3 = require("../constants");
|
7 | const pattern_1 = require("../../../utils/pattern");
|
8 | const AbstractParserWithWordBoundary_1 = require("../../../common/parsers/AbstractParserWithWordBoundary");
|
9 | const PATTERN = new RegExp("(?:on\\s*?)?" +
|
10 | `(${constants_2.ORDINAL_NUMBER_PATTERN})` +
|
11 | "(?:\\s*" +
|
12 | "(?:tot|\\-|\\–|until|through|till|\\s)\\s*" +
|
13 | `(${constants_2.ORDINAL_NUMBER_PATTERN})` +
|
14 | ")?" +
|
15 | "(?:-|/|\\s*(?:of)?\\s*)" +
|
16 | "(" +
|
17 | pattern_1.matchAnyPattern(constants_1.MONTH_DICTIONARY) +
|
18 | ")" +
|
19 | "(?:" +
|
20 | "(?:-|/|,?\\s*)" +
|
21 | `(${constants_3.YEAR_PATTERN}(?![^\\s]\\d))` +
|
22 | ")?" +
|
23 | "(?=\\W|$)", "i");
|
24 | const MONTH_NAME_GROUP = 3;
|
25 | const DATE_GROUP = 1;
|
26 | const DATE_TO_GROUP = 2;
|
27 | const YEAR_GROUP = 4;
|
28 | class NLMonthNameMiddleEndianParser extends AbstractParserWithWordBoundary_1.AbstractParserWithWordBoundaryChecking {
|
29 | innerPattern() {
|
30 | return PATTERN;
|
31 | }
|
32 | innerExtract(context, match) {
|
33 | const month = constants_1.MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()];
|
34 | const day = constants_2.parseOrdinalNumberPattern(match[DATE_GROUP]);
|
35 | if (day > 31) {
|
36 | match.index = match.index + match[DATE_GROUP].length;
|
37 | return null;
|
38 | }
|
39 | const components = context.createParsingComponents({
|
40 | day: day,
|
41 | month: month,
|
42 | });
|
43 | if (match[YEAR_GROUP]) {
|
44 | const year = constants_3.parseYear(match[YEAR_GROUP]);
|
45 | components.assign("year", year);
|
46 | }
|
47 | else {
|
48 | const year = years_1.findYearClosestToRef(context.refDate, day, month);
|
49 | components.imply("year", year);
|
50 | }
|
51 | if (!match[DATE_TO_GROUP]) {
|
52 | return components;
|
53 | }
|
54 | const endDate = constants_2.parseOrdinalNumberPattern(match[DATE_TO_GROUP]);
|
55 | const result = context.createParsingResult(match.index, match[0]);
|
56 | result.start = components;
|
57 | result.end = components.clone();
|
58 | result.end.assign("day", endDate);
|
59 | return result;
|
60 | }
|
61 | }
|
62 | exports.default = NLMonthNameMiddleEndianParser;
|