diff --git a/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/base_date.py b/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/base_date.py index 443854c2d1..2e61aced6f 100644 --- a/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/base_date.py +++ b/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/base_date.py @@ -1417,8 +1417,13 @@ def parse_number_with_month(self, source: str, reference: datetime) -> DateTimeP if match: month = self.config.month_of_year.get(match.group()) day = num - suffix = trimmed_source[match.end():] - prefix = trimmed_source[0: match.start()] + + prefix_end = min(ers[0].start, match.start()) + prefix = trimmed_source[0:prefix_end] + + suffix_start = max(ers[0].start + ers[0].length, match.end()) + suffix = trimmed_source[suffix_start:] + year = self._get_year_in_affix(suffix, False) if year == Constants.INVALID_YEAR and self.config.check_both_before_after: @@ -1472,7 +1477,7 @@ def parse_number_with_month(self, source: str, reference: datetime) -> DateTimeP future_date = future_date.replace(year=future_date.year+1) if past_date >= reference: - past_date = past_date.replace(year=past_date.year+1) + past_date = past_date.replace(year=past_date.year-1) else: result.timex = DateTimeFormatUtil.luis_date(year, month, day) diff --git a/Specs/DateTime/English/DateExtractor.json b/Specs/DateTime/English/DateExtractor.json index 7195b9bb60..073809860a 100644 --- a/Specs/DateTime/English/DateExtractor.json +++ b/Specs/DateTime/English/DateExtractor.json @@ -745,6 +745,110 @@ } ] }, + { + "Input": "I'll go back on April first 2021.", + "NotSupported": "javascript", + "Results": [ + { + "Text": "April first 2021", + "Type": "date", + "Start": 16, + "Length": 16 + } + ] + }, + { + "Input": "I'll go back Jun third 2023", + "NotSupported": "javascript", + "Results": [ + { + "Text": "Jun third 2023", + "Type": "date", + "Start": 13, + "Length": 14 + } + ] + }, + { + "Input": "I'll go back September the second 2025.", + "NotSupported": "javascript", + "Results": [ + { + "Text": "September the second 2025", + "Type": "date", + "Start": 13, + "Length": 25 + } + ] + }, + { + "Input": "I'll go back March one 2020", + "NotSupported": "javascript", + "Results": [ + { + "Text": "March one 2020", + "Type": "date", + "Start": 13, + "Length": 14 + } + ] + }, + { + "Input": "I'll go back Aug twelve 2024.", + "NotSupported": "javascript", + "Results": [ + { + "Text": "Aug twelve 2024", + "Type": "date", + "Start": 13, + "Length": 15 + } + ] + }, + { + "Input": "I'll go back February twenty fifth", + "Results": [ + { + "Text": "February twenty fifth", + "Type": "date", + "Start": 13, + "Length": 21 + } + ] + }, + { + "Input": "I'll go back on Nov the twelfth.", + "Results": [ + { + "Text": "Nov the twelfth", + "Type": "date", + "Start": 16, + "Length": 15 + } + ] + }, + { + "Input": "I'll go back January thirty one", + "Results": [ + { + "Text": "January thirty one", + "Type": "date", + "Start": 13, + "Length": 18 + } + ] + }, + { + "Input": "I'll go back Oct twenty three.", + "Results": [ + { + "Text": "Oct twenty three", + "Type": "date", + "Start": 13, + "Length": 16 + } + ] + }, { "Input": "i went back two months ago", "Results": [ diff --git a/Specs/DateTime/English/DateParser.json b/Specs/DateTime/English/DateParser.json index e3b3bf72ff..73fbc81a52 100644 --- a/Specs/DateTime/English/DateParser.json +++ b/Specs/DateTime/English/DateParser.json @@ -728,6 +728,218 @@ } ] }, + { + "Input": "I'll go back on April first 2021.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "April first 2021", + "Type": "date", + "Value": { + "Timex": "2021-04-01", + "FutureResolution": { + "date": "2021-04-01" + }, + "PastResolution": { + "date": "2021-04-01" + } + }, + "Start": 16, + "Length": 16 + } + ] + }, + { + "Input": "I'll go back Jun third 2023", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "Jun third 2023", + "Type": "date", + "Value": { + "Timex": "2023-06-03", + "FutureResolution": { + "date": "2023-06-03" + }, + "PastResolution": { + "date": "2023-06-03" + } + }, + "Start": 13, + "Length": 14 + } + ] + }, + { + "Input": "I'll go back September the second 2025.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "September the second 2025", + "Type": "date", + "Value": { + "Timex": "2025-09-02", + "FutureResolution": { + "date": "2025-09-02" + }, + "PastResolution": { + "date": "2025-09-02" + } + }, + "Start": 13, + "Length": 25 + } + ] + }, + { + "Input": "I'll go back March one 2020", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "March one 2020", + "Type": "date", + "Value": { + "Timex": "2020-03-01", + "FutureResolution": { + "date": "2020-03-01" + }, + "PastResolution": { + "date": "2020-03-01" + } + }, + "Start": 13, + "Length": 14 + } + ] + }, + { + "Input": "I'll go back Aug twelve 2024.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "Aug twelve 2024", + "Type": "date", + "Value": { + "Timex": "2024-08-12", + "FutureResolution": { + "date": "2024-08-12" + }, + "PastResolution": { + "date": "2024-08-12" + } + }, + "Start": 13, + "Length": 15 + } + ] + }, + { + "Input": "I'll go back February twenty fifth", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "February twenty fifth", + "Type": "date", + "Value": { + "Timex": "XXXX-02-25", + "FutureResolution": { + "date": "2024-02-25" + }, + "PastResolution": { + "date": "2023-02-25" + } + }, + "Start": 13, + "Length": 21 + } + ] + }, + { + "Input": "I'll go back on Nov the twelfth.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "Nov the twelfth", + "Type": "date", + "Value": { + "Timex": "XXXX-11-12", + "FutureResolution": { + "date": "2023-11-12" + }, + "PastResolution": { + "date": "2022-11-12" + } + }, + "Start": 16, + "Length": 15 + } + ] + }, + { + "Input": "I'll go back January thirty one", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "January thirty one", + "Type": "date", + "Value": { + "Timex": "XXXX-01-31", + "FutureResolution": { + "date": "2024-01-31" + }, + "PastResolution": { + "date": "2023-01-31" + } + }, + "Start": 13, + "Length": 18 + } + ] + }, + { + "Input": "I'll go back Oct twenty three.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "Oct twenty three", + "Type": "date", + "Value": { + "Timex": "XXXX-10-23", + "FutureResolution": { + "date": "2023-10-23" + }, + "PastResolution": { + "date": "2022-10-23" + } + }, + "Start": 13, + "Length": 16 + } + ] + }, { "Input": "I'll go back on Friday", "Context": { diff --git a/Specs/DateTime/English/DateTimeModel.json b/Specs/DateTime/English/DateTimeModel.json index 804b5c2033..c4aa8d3d79 100644 --- a/Specs/DateTime/English/DateTimeModel.json +++ b/Specs/DateTime/English/DateTimeModel.json @@ -228,6 +228,238 @@ } ] }, + { + "Input": "I'll go back on April first 2021.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "april first 2021", + "Start": 16, + "End": 31, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "2021-04-01", + "type": "date", + "value": "2021-04-01" + } + ] + } + } + ] + }, + { + "Input": "I'll go back Jun third 2023", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "jun third 2023", + "Start": 13, + "End": 26, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "2023-06-03", + "type": "date", + "value": "2023-06-03" + } + ] + } + } + ] + }, + { + "Input": "I'll go back September the second 2025.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "september the second 2025", + "Start": 13, + "End": 37, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "2025-09-02", + "type": "date", + "value": "2025-09-02" + } + ] + } + } + ] + }, + { + "Input": "I'll go back March one 2020", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "march one 2020", + "TypeName": "datetimeV2.date", + "Start": 13, + "End": 26, + "Resolution": { + "values": [ + { + "timex": "2020-03-01", + "type": "date", + "value": "2020-03-01" + } + ] + } + } + ] + }, + { + "Input": "I'll go back Aug twelve 2024.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "NotSupported": "javascript", + "Results": [ + { + "Text": "aug twelve 2024", + "TypeName": "datetimeV2.date", + "Start": 13, + "End": 27, + "Resolution": { + "values": [ + { + "timex": "2024-08-12", + "type": "date", + "value": "2024-08-12" + } + ] + } + } + ] + }, + { + "Input": "I'll go back February twenty fifth", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "february twenty fifth", + "Start": 13, + "End": 33, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "XXXX-02-25", + "type": "date", + "value": "2023-02-25" + }, + { + "timex": "XXXX-02-25", + "type": "date", + "value": "2024-02-25" + } + ] + } + } + ] + }, + { + "Input": "I'll go back on Nov the twelfth.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "nov the twelfth", + "Start": 16, + "End": 30, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "XXXX-11-12", + "type": "date", + "value": "2022-11-12" + }, + { + "timex": "XXXX-11-12", + "type": "date", + "value": "2023-11-12" + } + ] + } + } + ] + }, + { + "Input": "I'll go back January thirty one", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "january thirty one", + "Start": 13, + "End": 30, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "XXXX-01-31", + "type": "date", + "value": "2023-01-31" + }, + { + "timex": "XXXX-01-31", + "type": "date", + "value": "2024-01-31" + } + ] + } + } + ] + }, + { + "Input": "I'll go back Oct twenty three.", + "Context": { + "ReferenceDateTime": "2023-04-25T00:00:00" + }, + "Results": [ + { + "Text": "oct twenty three", + "Start": 13, + "End": 28, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "XXXX-10-23", + "type": "date", + "value": "2022-10-23" + }, + { + "timex": "XXXX-10-23", + "type": "date", + "value": "2023-10-23" + } + ] + } + } + ] + }, { "Input": "I'll go back today", "Context": { @@ -21691,7 +21923,7 @@ "Context": { "ReferenceDateTime": "2018-01-07T00:00:00" }, - "NotSupported": "javascript, python", + "NotSupported": "javascript", "Results": [ { "Text": "april of 1987", @@ -21716,7 +21948,7 @@ "Context": { "ReferenceDateTime": "2018-01-07T00:00:00" }, - "NotSupported": "javascript, python", + "NotSupported": "javascript", "Results": [ { "Text": "april of 87",