chrono-node 2.7.8 → 2.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/locales/en/parsers/ENCasualDateParser.js +4 -1
- package/dist/cjs/locales/en/parsers/ENCasualDateParser.js.map +1 -1
- package/dist/cjs/locales/it/constants.d.ts +28 -0
- package/dist/cjs/locales/it/constants.js +165 -0
- package/dist/cjs/locales/it/constants.js.map +1 -0
- package/dist/cjs/locales/it/index.d.ts +9 -0
- package/dist/cjs/locales/it/index.js +66 -0
- package/dist/cjs/locales/it/index.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITCasualDateParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITCasualDateParser.js +65 -0
- package/dist/cjs/locales/it/parsers/ITCasualDateParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITCasualTimeParser.d.ts +6 -0
- package/dist/cjs/locales/it/parsers/ITCasualTimeParser.js +47 -0
- package/dist/cjs/locales/it/parsers/ITCasualTimeParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.d.ts +10 -0
- package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.js +35 -0
- package/dist/cjs/locales/it/parsers/ITCasualYearMonthDayParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.js +57 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameLittleEndianParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.d.ts +6 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.js +59 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameMiddleEndianParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameParser.d.ts +6 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameParser.js +43 -0
- package/dist/cjs/locales/it/parsers/ITMonthNameParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.js +57 -0
- package/dist/cjs/locales/it/parsers/ITRelativeDateFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.js +18 -0
- package/dist/cjs/locales/it/parsers/ITSlashMonthFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.d.ts +10 -0
- package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.js +50 -0
- package/dist/cjs/locales/it/parsers/ITTimeExpressionParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.d.ts +9 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.js +24 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitAgoFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js +26 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.d.ts +9 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.js +23 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitLaterFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.js +19 -0
- package/dist/cjs/locales/it/parsers/ITTimeUnitWithinFormatParser.js.map +1 -0
- package/dist/cjs/locales/it/parsers/ITWeekdayParser.d.ts +7 -0
- package/dist/cjs/locales/it/parsers/ITWeekdayParser.js +43 -0
- package/dist/cjs/locales/it/parsers/ITWeekdayParser.js.map +1 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.d.ts +4 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.js +13 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateRangeRefiner.js.map +1 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.d.ts +4 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.js +13 -0
- package/dist/cjs/locales/it/refiners/ITMergeDateTimeRefiner.js.map +1 -0
- package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.d.ts +7 -0
- package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.js +36 -0
- package/dist/cjs/locales/it/refiners/ITMergeRelativeDateRefiner.js.map +1 -0
- package/dist/cjs/locales/ja/parsers/JPCasualDateParser.js +4 -4
- package/dist/cjs/locales/ja/refiners/JPMergeDateRangeRefiner.js +1 -1
- package/dist/cjs/locales/ja/refiners/JPMergeDateRangeRefiner.js.map +1 -1
- package/dist/esm/locales/en/parsers/ENCasualDateParser.js +4 -1
- package/dist/esm/locales/en/parsers/ENCasualDateParser.js.map +1 -1
- package/dist/esm/locales/it/constants.d.ts +28 -0
- package/dist/esm/locales/it/constants.js +200 -0
- package/dist/esm/locales/it/constants.js.map +1 -0
- package/dist/esm/locales/it/index.d.ts +9 -0
- package/dist/esm/locales/it/index.js +56 -0
- package/dist/esm/locales/it/index.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITCasualDateParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITCasualDateParser.js +40 -0
- package/dist/esm/locales/it/parsers/ITCasualDateParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITCasualTimeParser.d.ts +6 -0
- package/dist/esm/locales/it/parsers/ITCasualTimeParser.js +41 -0
- package/dist/esm/locales/it/parsers/ITCasualTimeParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.d.ts +10 -0
- package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.js +32 -0
- package/dist/esm/locales/it/parsers/ITCasualYearMonthDayParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.js +54 -0
- package/dist/esm/locales/it/parsers/ITMonthNameLittleEndianParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.d.ts +6 -0
- package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.js +56 -0
- package/dist/esm/locales/it/parsers/ITMonthNameMiddleEndianParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITMonthNameParser.d.ts +6 -0
- package/dist/esm/locales/it/parsers/ITMonthNameParser.js +40 -0
- package/dist/esm/locales/it/parsers/ITMonthNameParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.js +51 -0
- package/dist/esm/locales/it/parsers/ITRelativeDateFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.js +15 -0
- package/dist/esm/locales/it/parsers/ITSlashMonthFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITTimeExpressionParser.d.ts +10 -0
- package/dist/esm/locales/it/parsers/ITTimeExpressionParser.js +47 -0
- package/dist/esm/locales/it/parsers/ITTimeExpressionParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.d.ts +9 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.js +21 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitAgoFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js +23 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.d.ts +9 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.js +20 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitLaterFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.js +16 -0
- package/dist/esm/locales/it/parsers/ITTimeUnitWithinFormatParser.js.map +1 -0
- package/dist/esm/locales/it/parsers/ITWeekdayParser.d.ts +7 -0
- package/dist/esm/locales/it/parsers/ITWeekdayParser.js +40 -0
- package/dist/esm/locales/it/parsers/ITWeekdayParser.js.map +1 -0
- package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.d.ts +4 -0
- package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.js +7 -0
- package/dist/esm/locales/it/refiners/ITMergeDateRangeRefiner.js.map +1 -0
- package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.d.ts +4 -0
- package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.js +7 -0
- package/dist/esm/locales/it/refiners/ITMergeDateTimeRefiner.js.map +1 -0
- package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.d.ts +7 -0
- package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.js +33 -0
- package/dist/esm/locales/it/refiners/ITMergeRelativeDateRefiner.js.map +1 -0
- package/dist/esm/locales/ja/parsers/JPCasualDateParser.js +4 -4
- package/dist/esm/locales/ja/refiners/JPMergeDateRangeRefiner.js +1 -1
- package/dist/esm/locales/ja/refiners/JPMergeDateRangeRefiner.js.map +1 -1
- package/package.json +1 -1
- package/src/locales/en/parsers/ENCasualDateParser.ts +5 -1
- package/src/locales/it/constants.ts +230 -0
- package/src/locales/it/index.ts +99 -0
- package/src/locales/it/parsers/ITCasualDateParser.ts +53 -0
- package/src/locales/it/parsers/ITCasualTimeParser.ts +50 -0
- package/src/locales/it/parsers/ITCasualYearMonthDayParser.ts +49 -0
- package/src/locales/it/parsers/ITMonthNameLittleEndianParser.ts +69 -0
- package/src/locales/it/parsers/ITMonthNameMiddleEndianParser.ts +78 -0
- package/src/locales/it/parsers/ITMonthNameParser.ts +62 -0
- package/src/locales/it/parsers/ITRelativeDateFormatParser.ts +71 -0
- package/src/locales/it/parsers/ITSlashMonthFormatParser.ts +26 -0
- package/src/locales/it/parsers/ITTimeExpressionParser.ts +55 -0
- package/src/locales/it/parsers/ITTimeUnitAgoFormatParser.ts +25 -0
- package/src/locales/it/parsers/ITTimeUnitCasualRelativeFormatParser.ts +30 -0
- package/src/locales/it/parsers/ITTimeUnitLaterFormatParser.ts +27 -0
- package/src/locales/it/parsers/ITTimeUnitWithinFormatParser.ts +26 -0
- package/src/locales/it/parsers/ITWeekdayParser.ts +47 -0
- package/src/locales/it/refiners/ITMergeDateRangeRefiner.ts +17 -0
- package/src/locales/it/refiners/ITMergeDateTimeRefiner.ts +13 -0
- package/src/locales/it/refiners/ITMergeRelativeDateRefiner.ts +58 -0
- package/src/locales/ja/parsers/JPCasualDateParser.ts +4 -4
- package/src/locales/ja/refiners/JPMergeDateRangeRefiner.ts +1 -1
- package/test/ja/ja_casual.test.ts +8 -0
- package/test/ja/ja_standard.test.ts +19 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FULL_MONTH_NAME_DICTIONARY, MONTH_DICTIONARY } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { findYearClosestToRef } from "../../../calculation/years";
|
|
4
|
+
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
|
+
import { YEAR_PATTERN, parseYear } from "../constants";
|
|
6
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
7
|
+
|
|
8
|
+
const PATTERN = new RegExp(
|
|
9
|
+
`((?:in)\\s*)?` +
|
|
10
|
+
`(${matchAnyPattern(MONTH_DICTIONARY)})` +
|
|
11
|
+
`\\s*` +
|
|
12
|
+
`(?:` +
|
|
13
|
+
`[,-]?\\s*(${YEAR_PATTERN})?` +
|
|
14
|
+
")?" +
|
|
15
|
+
"(?=[^\\s\\w]|\\s+[^0-9]|\\s+$|$)",
|
|
16
|
+
"i"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const PREFIX_GROUP = 1;
|
|
20
|
+
const MONTH_NAME_GROUP = 2;
|
|
21
|
+
const YEAR_GROUP = 3;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The parser for parsing month name and year.
|
|
25
|
+
* - January, 2012
|
|
26
|
+
* - January 2012
|
|
27
|
+
* - January
|
|
28
|
+
* (in) Jan
|
|
29
|
+
*/
|
|
30
|
+
export default class ENMonthNameParser extends AbstractParserWithWordBoundaryChecking {
|
|
31
|
+
innerPattern(): RegExp {
|
|
32
|
+
return PATTERN;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray) {
|
|
36
|
+
const monthName = match[MONTH_NAME_GROUP].toLowerCase();
|
|
37
|
+
|
|
38
|
+
// skip some unlikely words "jan", "mar", ..
|
|
39
|
+
if (match[0].length <= 3 && !FULL_MONTH_NAME_DICTIONARY[monthName]) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = context.createParsingResult(
|
|
44
|
+
match.index + (match[PREFIX_GROUP] || "").length,
|
|
45
|
+
match.index + match[0].length
|
|
46
|
+
);
|
|
47
|
+
result.start.imply("day", 1);
|
|
48
|
+
|
|
49
|
+
const month = MONTH_DICTIONARY[monthName];
|
|
50
|
+
result.start.assign("month", month);
|
|
51
|
+
|
|
52
|
+
if (match[YEAR_GROUP]) {
|
|
53
|
+
const year = parseYear(match[YEAR_GROUP]);
|
|
54
|
+
result.start.assign("year", year);
|
|
55
|
+
} else {
|
|
56
|
+
const year = findYearClosestToRef(context.refDate, 1, month);
|
|
57
|
+
result.start.imply("year", year);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TIME_UNIT_DICTIONARY } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import dayjs from "dayjs";
|
|
5
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
+
import { matchAnyPattern } from "../../../utils/pattern";
|
|
7
|
+
|
|
8
|
+
const PATTERN = new RegExp(
|
|
9
|
+
`(questo|ultimo|scorso|prossimo|dopo\\s*questo|questa|ultima|scorsa|prossima\\s*questa)\\s*(${matchAnyPattern(
|
|
10
|
+
TIME_UNIT_DICTIONARY
|
|
11
|
+
)})(?=\\s*)` + "(?=\\W|$)",
|
|
12
|
+
"i"
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const MODIFIER_WORD_GROUP = 1;
|
|
16
|
+
const RELATIVE_WORD_GROUP = 2;
|
|
17
|
+
|
|
18
|
+
export default class ENRelativeDateFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
19
|
+
innerPattern(): RegExp {
|
|
20
|
+
return PATTERN;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
24
|
+
const modifier = match[MODIFIER_WORD_GROUP].toLowerCase();
|
|
25
|
+
const unitWord = match[RELATIVE_WORD_GROUP].toLowerCase();
|
|
26
|
+
const timeunit = TIME_UNIT_DICTIONARY[unitWord];
|
|
27
|
+
|
|
28
|
+
if (modifier == "prossimo" || modifier.startsWith("dopo")) {
|
|
29
|
+
const timeUnits = {};
|
|
30
|
+
timeUnits[timeunit] = 1;
|
|
31
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (modifier == "prima" || modifier == "precedente") {
|
|
35
|
+
const timeUnits = {};
|
|
36
|
+
timeUnits[timeunit] = -1;
|
|
37
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const components = context.createParsingComponents();
|
|
41
|
+
let date = dayjs(context.reference.instant);
|
|
42
|
+
|
|
43
|
+
// This week
|
|
44
|
+
if (unitWord.match(/settimana/i)) {
|
|
45
|
+
date = date.add(-date.get("d"), "d");
|
|
46
|
+
components.imply("day", date.date());
|
|
47
|
+
components.imply("month", date.month() + 1);
|
|
48
|
+
components.imply("year", date.year());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// This month
|
|
52
|
+
else if (unitWord.match(/mese/i)) {
|
|
53
|
+
date = date.add(-date.date() + 1, "d");
|
|
54
|
+
components.imply("day", date.date());
|
|
55
|
+
components.assign("year", date.year());
|
|
56
|
+
components.assign("month", date.month() + 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// This year
|
|
60
|
+
else if (unitWord.match(/anno/i)) {
|
|
61
|
+
date = date.add(-date.date() + 1, "d");
|
|
62
|
+
date = date.add(-date.month(), "month");
|
|
63
|
+
|
|
64
|
+
components.imply("day", date.date());
|
|
65
|
+
components.imply("month", date.month() + 1);
|
|
66
|
+
components.assign("year", date.year());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return components;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
4
|
+
|
|
5
|
+
const PATTERN = new RegExp("([0-9]|0[1-9]|1[012])/([0-9]{4})" + "", "i");
|
|
6
|
+
|
|
7
|
+
const MONTH_GROUP = 1;
|
|
8
|
+
const YEAR_GROUP = 2;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Month/Year date format with slash "/" (also "-" and ".") between numbers
|
|
12
|
+
* - 11/05
|
|
13
|
+
* - 06/2005
|
|
14
|
+
*/
|
|
15
|
+
export default class ENSlashMonthFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
16
|
+
innerPattern(): RegExp {
|
|
17
|
+
return PATTERN;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
21
|
+
const year = parseInt(match[YEAR_GROUP]);
|
|
22
|
+
const month = parseInt(match[MONTH_GROUP]);
|
|
23
|
+
|
|
24
|
+
return context.createParsingComponents().imply("day", 1).assign("month", month).assign("year", year);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { Meridiem } from "../../../index";
|
|
4
|
+
import { AbstractTimeExpressionParser } from "../../../common/parsers/AbstractTimeExpressionParser";
|
|
5
|
+
|
|
6
|
+
export default class ENTimeExpressionParser extends AbstractTimeExpressionParser {
|
|
7
|
+
constructor(strictMode) {
|
|
8
|
+
super(strictMode);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
followingPhase(): string {
|
|
12
|
+
return "\\s*(?:\\-|\\–|\\~|\\〜|to|\\?)\\s*";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
primaryPrefix(): string {
|
|
16
|
+
return "(?:(?:alle|dalle)\\s*)??";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
primarySuffix(): string {
|
|
20
|
+
return "(?:\\s*(?:o\\W*in punto|alle\\s*sera|in\\s*del\\s*(?:mattina|pomeriggio)))?(?!/)(?=\\W|$)";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): null | ParsingComponents {
|
|
24
|
+
const components = super.extractPrimaryTimeComponents(context, match);
|
|
25
|
+
if (components) {
|
|
26
|
+
if (match[0].endsWith("sera")) {
|
|
27
|
+
const hour = components.get("hour");
|
|
28
|
+
if (hour >= 6 && hour < 12) {
|
|
29
|
+
components.assign("hour", components.get("hour") + 12);
|
|
30
|
+
components.assign("meridiem", Meridiem.PM);
|
|
31
|
+
} else if (hour < 6) {
|
|
32
|
+
components.assign("meridiem", Meridiem.AM);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (match[0].endsWith("pomeriggio")) {
|
|
37
|
+
components.assign("meridiem", Meridiem.PM);
|
|
38
|
+
const hour = components.get("hour");
|
|
39
|
+
if (hour >= 0 && hour <= 6) {
|
|
40
|
+
components.assign("hour", components.get("hour") + 12);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (match[0].endsWith("mattina")) {
|
|
45
|
+
components.assign("meridiem", Meridiem.AM);
|
|
46
|
+
const hour = components.get("hour");
|
|
47
|
+
if (hour < 12) {
|
|
48
|
+
components.assign("hour", components.get("hour"));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return components;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { parseTimeUnits, TIME_UNITS_PATTERN } from "../constants";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
import { reverseTimeUnits } from "../../../utils/timeunits";
|
|
6
|
+
|
|
7
|
+
const PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}(?:fa|prima|precedente)(?=(?:\\W|$))`, "i");
|
|
8
|
+
const STRICT_PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}fa(?=(?:\\W|$))`, "i");
|
|
9
|
+
|
|
10
|
+
export default class ENTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
11
|
+
constructor(private strictMode: boolean) {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
innerPattern(): RegExp {
|
|
16
|
+
return this.strictMode ? STRICT_PATTERN : PATTERN;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray) {
|
|
20
|
+
const timeUnits = parseTimeUnits(match[1]);
|
|
21
|
+
const outputTimeUnits = reverseTimeUnits(timeUnits);
|
|
22
|
+
|
|
23
|
+
return ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TIME_UNITS_PATTERN, parseTimeUnits } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
import { reverseTimeUnits } from "../../../utils/timeunits";
|
|
6
|
+
|
|
7
|
+
const PATTERN = new RegExp(
|
|
8
|
+
`(questo|ultimo|passato|prossimo|dopo|questa|ultima|passata|prossima|\\+|-)\\s*(${TIME_UNITS_PATTERN})(?=\\W|$)`,
|
|
9
|
+
"i"
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export default class ENTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
13
|
+
innerPattern(): RegExp {
|
|
14
|
+
return PATTERN;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
18
|
+
const prefix = match[1].toLowerCase();
|
|
19
|
+
let timeUnits = parseTimeUnits(match[2]);
|
|
20
|
+
switch (prefix) {
|
|
21
|
+
case "last":
|
|
22
|
+
case "past":
|
|
23
|
+
case "-":
|
|
24
|
+
timeUnits = reverseTimeUnits(timeUnits);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { parseTimeUnits, TIME_UNITS_PATTERN } from "../constants";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
|
|
6
|
+
const PATTERN = new RegExp(
|
|
7
|
+
`(${TIME_UNITS_PATTERN})\\s{0,5}(?:dopo|più tardi|da adesso|avanti|oltre|a seguire)` + "(?=(?:\\W|$))",
|
|
8
|
+
"i"
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const STRICT_PATTERN = new RegExp("" + "(" + TIME_UNITS_PATTERN + ")" + "(dopo|più tardi)" + "(?=(?:\\W|$))", "i");
|
|
12
|
+
const GROUP_NUM_TIMEUNITS = 1;
|
|
13
|
+
|
|
14
|
+
export default class ENTimeUnitLaterFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
15
|
+
constructor(private strictMode: boolean) {
|
|
16
|
+
super();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
innerPattern(): RegExp {
|
|
20
|
+
return this.strictMode ? STRICT_PATTERN : PATTERN;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray) {
|
|
24
|
+
const fragments = parseTimeUnits(match[GROUP_NUM_TIMEUNITS]);
|
|
25
|
+
return ParsingComponents.createRelativeFromReference(context.reference, fragments);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TIME_UNITS_PATTERN, parseTimeUnits } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
|
|
6
|
+
const PATTERN_WITH_PREFIX = new RegExp(
|
|
7
|
+
`(?:within|in|for)\\s*` +
|
|
8
|
+
`(?:(?:più o meno|intorno|approssimativamente|verso|verso le)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})(?=\\W|$)`,
|
|
9
|
+
"i"
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const PATTERN_WITHOUT_PREFIX = new RegExp(
|
|
13
|
+
`(?:(?:più o meno|intorno|approssimativamente|verso|verso le)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})(?=\\W|$)`,
|
|
14
|
+
"i"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export default class ENTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
18
|
+
innerPattern(context: ParsingContext): RegExp {
|
|
19
|
+
return context.option.forwardDate ? PATTERN_WITHOUT_PREFIX : PATTERN_WITH_PREFIX;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
23
|
+
const timeUnits = parseTimeUnits(match[1]);
|
|
24
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { WEEKDAY_DICTIONARY } from "../constants";
|
|
4
|
+
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
|
+
|
|
8
|
+
const PATTERN = new RegExp(
|
|
9
|
+
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
10
|
+
"(?:il\\s*?)?" +
|
|
11
|
+
"(?:(questa|l'ultima|scorsa|prossima)\\s*)?" +
|
|
12
|
+
`(${matchAnyPattern(WEEKDAY_DICTIONARY)})` +
|
|
13
|
+
"(?:\\s*(?:\\,|\\)|\\)))?" +
|
|
14
|
+
"(?:\\s*(questa|l'ultima|scorsa|prossima)\\s*settimana)?" +
|
|
15
|
+
"(?=\\W|$)",
|
|
16
|
+
"i"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const PREFIX_GROUP = 1;
|
|
20
|
+
const WEEKDAY_GROUP = 2;
|
|
21
|
+
const POSTFIX_GROUP = 3;
|
|
22
|
+
|
|
23
|
+
export default class ITWeekdayParser extends AbstractParserWithWordBoundaryChecking {
|
|
24
|
+
innerPattern(): RegExp {
|
|
25
|
+
return PATTERN;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
29
|
+
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
30
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
31
|
+
const prefix = match[PREFIX_GROUP];
|
|
32
|
+
const postfix = match[POSTFIX_GROUP];
|
|
33
|
+
let modifierWord = prefix || postfix;
|
|
34
|
+
modifierWord = modifierWord || "";
|
|
35
|
+
modifierWord = modifierWord.toLowerCase();
|
|
36
|
+
|
|
37
|
+
let modifier = null;
|
|
38
|
+
if (modifierWord == "ultima" || modifierWord == "scorsa") {
|
|
39
|
+
modifier = "ultima";
|
|
40
|
+
} else if (modifierWord == "prossima") {
|
|
41
|
+
modifier = "prossima";
|
|
42
|
+
} else if (modifierWord == "questa") {
|
|
43
|
+
modifier = "questa";
|
|
44
|
+
}
|
|
45
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import AbstractMergeDateRangeRefiner from "../../../common/refiners/AbstractMergeDateRangeRefiner";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Merging before and after results (see. AbstractMergeDateRangeRefiner)
|
|
9
|
+
* This implementation should provide English connecting phases
|
|
10
|
+
* - 2020-02-13 [to] 2020-02-13
|
|
11
|
+
* - Wednesday [-] Friday
|
|
12
|
+
*/
|
|
13
|
+
export default class ENMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner {
|
|
14
|
+
patternBetween(): RegExp {
|
|
15
|
+
return /^\s*(to|-)\s*$/i;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AbstractMergeDateTimeRefiner from "../../../common/refiners/AbstractMergeDateTimeRefiner";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merging date-only result and time-only result (see. AbstractMergeDateTimeRefiner).
|
|
5
|
+
* This implementation should provide English connecting phases
|
|
6
|
+
* - 2020-02-13 [at] 6pm
|
|
7
|
+
* - Tomorrow [after] 7am
|
|
8
|
+
*/
|
|
9
|
+
export default class ENMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner {
|
|
10
|
+
patternBetween(): RegExp {
|
|
11
|
+
return new RegExp("^\\s*(T|alle|dopo|prima|il|di|del|delle|,|-)?\\s*$");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MergingRefiner } from "../../../common/abstractRefiners";
|
|
2
|
+
import { ParsingComponents, ParsingResult, ReferenceWithTimezone } from "../../../results";
|
|
3
|
+
import { parseTimeUnits } from "../constants";
|
|
4
|
+
import { reverseTimeUnits } from "../../../utils/timeunits";
|
|
5
|
+
|
|
6
|
+
function hasImpliedEarlierReferenceDate(result: ParsingResult): boolean {
|
|
7
|
+
return result.text.match(/\s+(prima|dal)$/i) != null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function hasImpliedLaterReferenceDate(result: ParsingResult): boolean {
|
|
11
|
+
return result.text.match(/\s+(dopo|dal|fino)$/i) != null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Merges an absolute date with a relative date.
|
|
16
|
+
* - 2 weeks before 2020-02-13
|
|
17
|
+
* - 2 days after next Friday
|
|
18
|
+
*/
|
|
19
|
+
export default class ENMergeRelativeDateRefiner extends MergingRefiner {
|
|
20
|
+
patternBetween(): RegExp {
|
|
21
|
+
return /^\s*$/i;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
shouldMergeResults(textBetween: string, currentResult: ParsingResult, nextResult: ParsingResult): boolean {
|
|
25
|
+
// Dates need to be next to each other to get merged
|
|
26
|
+
if (!textBetween.match(this.patternBetween())) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check if any relative tokens were swallowed by the first date.
|
|
31
|
+
// E.g. [<relative_date1> from] [<date2>]
|
|
32
|
+
if (!hasImpliedEarlierReferenceDate(currentResult) && !hasImpliedLaterReferenceDate(currentResult)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// make sure that <date2> implies an absolute date
|
|
37
|
+
return !!nextResult.start.get("day") && !!nextResult.start.get("month") && !!nextResult.start.get("year");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
mergeResults(textBetween: string, currentResult: ParsingResult, nextResult: ParsingResult): ParsingResult {
|
|
41
|
+
let timeUnits = parseTimeUnits(currentResult.text);
|
|
42
|
+
if (hasImpliedEarlierReferenceDate(currentResult)) {
|
|
43
|
+
timeUnits = reverseTimeUnits(timeUnits);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const components = ParsingComponents.createRelativeFromReference(
|
|
47
|
+
new ReferenceWithTimezone(nextResult.start.date()),
|
|
48
|
+
timeUnits
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return new ParsingResult(
|
|
52
|
+
nextResult.reference,
|
|
53
|
+
currentResult.index,
|
|
54
|
+
`${currentResult.text}${textBetween}${nextResult.text}`,
|
|
55
|
+
components
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -3,14 +3,14 @@ import dayjs from "dayjs";
|
|
|
3
3
|
import { Meridiem } from "../../../types";
|
|
4
4
|
import * as references from "../../../common/casualReferences";
|
|
5
5
|
|
|
6
|
-
const PATTERN =
|
|
6
|
+
const PATTERN = /今日|きょう|本日|ほんじつ|昨日|きのう|明日|あした|今夜|こんや|今夕|こんゆう|今晩|こんばん|今朝|けさ/i;
|
|
7
7
|
|
|
8
8
|
function normalizeTextToKanji(text: string) {
|
|
9
9
|
switch (text) {
|
|
10
10
|
case "きょう":
|
|
11
11
|
return "今日";
|
|
12
|
-
case "
|
|
13
|
-
return "
|
|
12
|
+
case "ほんじつ":
|
|
13
|
+
return "本日";
|
|
14
14
|
case "きのう":
|
|
15
15
|
return "昨日";
|
|
16
16
|
case "あした":
|
|
@@ -46,8 +46,8 @@ export default class JPCasualDateParser implements Parser {
|
|
|
46
46
|
case "明日":
|
|
47
47
|
return references.tomorrow(context.reference);
|
|
48
48
|
|
|
49
|
+
case "本日":
|
|
49
50
|
case "今日":
|
|
50
|
-
case "当日":
|
|
51
51
|
return references.today(context.reference);
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -8,6 +8,6 @@ import AbstractMergeDateRangeRefiner from "../../../common/refiners/AbstractMerg
|
|
|
8
8
|
*/
|
|
9
9
|
export default class JPMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner {
|
|
10
10
|
patternBetween(): RegExp {
|
|
11
|
-
return /^\s*(
|
|
11
|
+
return /^\s*(から|ー|-|~|~)\s*$/i;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -10,6 +10,14 @@ test("Test - Single Expression", function () {
|
|
|
10
10
|
expect(result.text).toBe("きょう");
|
|
11
11
|
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12));
|
|
12
12
|
});
|
|
13
|
+
testSingleCase(chrono.ja, "本日はお日柄もよく", new Date(2012, 8 - 1, 10, 12), (result) => {
|
|
14
|
+
expect(result.text).toBe("本日");
|
|
15
|
+
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12));
|
|
16
|
+
});
|
|
17
|
+
testSingleCase(chrono.ja, "ほんじつはお日柄もよく", new Date(2012, 8 - 1, 10, 12), (result) => {
|
|
18
|
+
expect(result.text).toBe("ほんじつ");
|
|
19
|
+
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12));
|
|
20
|
+
});
|
|
13
21
|
|
|
14
22
|
testSingleCase(chrono.ja, "昨日の全国観測値ランキング", new Date(2012, 8 - 1, 10, 12), (result) => {
|
|
15
23
|
expect(result.text).toBe("昨日");
|
|
@@ -213,4 +213,23 @@ test("Test - Range Expression", function () {
|
|
|
213
213
|
|
|
214
214
|
expect(result.end).toBeDate(new Date(2014, 1 - 1, 7, 12));
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
testSingleCase(chrono.ja, "2013年12月26日 ~ 2014年1月7日", new Date(2012, 8 - 1, 10), (result) => {
|
|
218
|
+
expect(result.index).toBe(0);
|
|
219
|
+
expect(result.text).toBe("2013年12月26日 ~ 2014年1月7日");
|
|
220
|
+
|
|
221
|
+
expect(result.start).not.toBeNull();
|
|
222
|
+
expect(result.start.get("year")).toBe(2013);
|
|
223
|
+
expect(result.start.get("month")).toBe(12);
|
|
224
|
+
expect(result.start.get("day")).toBe(26);
|
|
225
|
+
|
|
226
|
+
expect(result.start).toBeDate(new Date(2013, 12 - 1, 26, 12));
|
|
227
|
+
|
|
228
|
+
expect(result.end).not.toBeNull();
|
|
229
|
+
expect(result.end.get("year")).toBe(2014);
|
|
230
|
+
expect(result.end.get("month")).toBe(1);
|
|
231
|
+
expect(result.end.get("day")).toBe(7);
|
|
232
|
+
|
|
233
|
+
expect(result.end).toBeDate(new Date(2014, 1 - 1, 7, 12));
|
|
234
|
+
});
|
|
216
235
|
});
|