diff --git a/src/locales/nl/parsers/NLRelativeDateFormatParser.ts b/src/locales/nl/parsers/NLRelativeDateFormatParser.ts index 37ec0ac6..7b690acc 100644 --- a/src/locales/nl/parsers/NLRelativeDateFormatParser.ts +++ b/src/locales/nl/parsers/NLRelativeDateFormatParser.ts @@ -6,8 +6,8 @@ import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/ import { matchAnyPattern } from "../../../utils/pattern"; const PATTERN = new RegExp( - `(dit|deze|komende|volgend|volgende|afgelopen|vorige)\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})(?=\\s*)` + - "(?=\\W|$)", + `(dit|deze|(?:aan)?komend|volgend|afgelopen|vorig)e?\\s*(${matchAnyPattern(TIME_UNIT_DICTIONARY)})(?=\\s*)` + + "(?=\\W|$)", "i" ); @@ -24,13 +24,13 @@ export default class NLRelativeDateFormatParser extends AbstractParserWithWordBo const unitWord = match[RELATIVE_WORD_GROUP].toLowerCase(); const timeunit = TIME_UNIT_DICTIONARY[unitWord]; - if (modifier == "volgend" || modifier == "volgende" || modifier == "komende") { + if (modifier == "volgend" || modifier == "komend" || modifier == "aankomend") { const timeUnits = {}; timeUnits[timeunit] = 1; return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); } - if (modifier == "afgelopen" || modifier == "vorige") { + if (modifier == "afgelopen" || modifier == "vorig") { const timeUnits = {}; timeUnits[timeunit] = -1; return ParsingComponents.createRelativeFromReference(context.reference, timeUnits); diff --git a/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts b/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts index f7039537..c4440c19 100644 --- a/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts +++ b/src/locales/nl/parsers/NLTimeUnitCasualRelativeFormatParser.ts @@ -4,7 +4,10 @@ import { ParsingComponents } from "../../../results"; import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary"; import { reverseTimeUnits } from "../../../utils/timeunits"; -const PATTERN = new RegExp(`(deze|vorige|afgelopen|komende|over|\\+|-)\\s*(${TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); +const PATTERN = new RegExp(`(dit|deze|vorig|afgelopen|(?:aan)?komend|over|\\+|-)e?\\s*(${TIME_UNITS_PATTERN})(?=\\W|$)`, "i"); + +const PREFIX_WORD_GROUP = 1; +const TIME_UNIT_WORD_GROUP = 2; export default class NLTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundaryChecking { innerPattern(): RegExp { @@ -12,10 +15,10 @@ export default class NLTimeUnitCasualRelativeFormatParser extends AbstractParser } innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents { - const prefix = match[1].toLowerCase(); - let timeUnits = parseTimeUnits(match[2]); + const prefix = match[PREFIX_WORD_GROUP].toLowerCase(); + let timeUnits = parseTimeUnits(match[TIME_UNIT_WORD_GROUP]); switch (prefix) { - case "vorige": + case "vorig": case "afgelopen": case "-": timeUnits = reverseTimeUnits(timeUnits); diff --git a/test/nl/nl_relative.test.ts b/test/nl/nl_relative.test.ts index 8b65d769..0553c229 100644 --- a/test/nl/nl_relative.test.ts +++ b/test/nl/nl_relative.test.ts @@ -71,7 +71,7 @@ test("Test - Past relative expressions", () => { test("Test - Future relative expressions", () => { // next hour - testSingleCase(chrono.nl, "komende uur", new Date(2016, 10 - 1, 1, 12), (result, text) => { + testSingleCase(chrono.nl, "komend uur", new Date(2016, 10 - 1, 1, 12), (result, text) => { expect(result.text).toBe(text); expect(result.start.get("year")).toBe(2016); expect(result.start.get("month")).toBe(10); @@ -111,6 +111,20 @@ test("Test - Future relative expressions", () => { expect(result.start.isCertain("hour")).toBe(false); }); + // next month + testSingleCase(chrono.nl, "aankomende maand", new Date(2016, 10 - 1, 1, 12), (result, text) => { + expect(result.text).toBe(text); + expect(result.start.get("year")).toBe(2016); + expect(result.start.get("month")).toBe(11); + expect(result.start.get("day")).toBe(1); + expect(result.start.get("hour")).toBe(12); + + expect(result.start.isCertain("year")).toBe(true); + expect(result.start.isCertain("month")).toBe(true); + expect(result.start.isCertain("day")).toBe(false); + expect(result.start.isCertain("hour")).toBe(false); + }); + // next year testSingleCase(chrono.nl, "volgend jaar", new Date(2020, 11 - 1, 22, 12, 11, 32, 6), (result, text) => { expect(result.text).toBe(text); @@ -137,7 +151,7 @@ test("Test - Relative date components' certainty", () => { const refDate = new Date(2016, 10 - 1, 7, 12); // next hour - testSingleCase(chrono.nl, "komende uur", refDate, (result, text) => { + testSingleCase(chrono.nl, "komend uur", refDate, (result, text) => { expect(result.text).toBe(text); expect(result.start.get("year")).toBe(2016); expect(result.start.get("month")).toBe(10);