From d468b8f3a8f9c61c55a98850cdfcd0583ffde95c Mon Sep 17 00:00:00 2001 From: simonpoole Date: Fri, 15 Mar 2024 14:45:50 +0100 Subject: [PATCH] Add year in if it exists when fudging missing months Fixes https://github.com/simonpoole/OpeningHoursParser/issues/88 --- .../ch/poole/openinghoursparser/OpeningHoursParser.jj | 8 ++++++-- test-data/oh.txt-result | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/poole/openinghoursparser/OpeningHoursParser.jj b/src/main/java/ch/poole/openinghoursparser/OpeningHoursParser.jj index b6e74bb..35a39cc 100644 --- a/src/main/java/ch/poole/openinghoursparser/OpeningHoursParser.jj +++ b/src/main/java/ch/poole/openinghoursparser/OpeningHoursParser.jj @@ -1114,6 +1114,7 @@ List < DateRange > date_selector() : { DateRange mdr, mdr1; Month lastMonth = null; + int lastYear = YearRange.UNDEFINED_YEAR; List < DateRange > result = new ArrayList < DateRange > (); } { @@ -1129,7 +1130,7 @@ List < DateRange > date_selector() : < COMMA > mdr1 = date_range() { DateWithOffset dwo = mdr1.getStartDate(); - // if the month is missing in the start date patch it up here + // if the month and maybe the year is missing in the start date patch it up here // in strict mode we will never get to this point if (dwo.getVarDate() == null) { @@ -1142,6 +1143,7 @@ List < DateRange > date_selector() : { DateWithOffset first = mdr.getStartDate(); lastMonth = first.getMonth(); + lastYear = first.getYear(); if (lastMonth == null) { // fail, can't fudge the month @@ -1149,10 +1151,12 @@ List < DateRange > date_selector() : } } dwo.setMonth(lastMonth); + dwo.setYear(lastYear); } - else if (dwo.getMonth() != null) + else { lastMonth = dwo.getMonth(); + lastYear = dwo.getYear(); } } result.add(mdr1); diff --git a/test-data/oh.txt-result b/test-data/oh.txt-result index a32b73a..a117d66 100644 --- a/test-data/oh.txt-result +++ b/test-data/oh.txt-result @@ -156254,7 +156254,7 @@ 0 Tu-We,Fr 08:30-18:00; Th 08:30-20:00; Sa 08:00-14:00 0 Tu-We,Fr 08:30-18:00; Th 12:00-20:00; Sa 08:00-13:00 0 Tu,We,Fr 08:30-18:30; Th 08:30-19:00; Sa 08:00-13:00 -0 Tu,We,Fr 08:30-20:30; Sa 08:30-14:00; Su "8:30-14 ? check website"; Mo,Th closed; 2015 Jun 29-Sep 13 off; 2015 Sep 26-27 off; 2015 Oct 17-18,Oct 31 off; 2015 Nov 29 off +0 Tu,We,Fr 08:30-20:30; Sa 08:30-14:00; Su "8:30-14 ? check website"; Mo,Th closed; 2015 Jun 29-Sep 13 off; 2015 Sep 26-27 off; 2015 Oct 17-18,2015 Oct 31 off; 2015 Nov 29 off 0 Tu,We,Fr 08:45-12:00,13:30-18:00; Th 09:30-12:00,13:30-18:00; Sa 08:45-12:00 0 Tu,We,Fr 08:45-12:00,13:45-18:00; Th 08:45-12:00,14:30-18:00; Sa 08:30-12:30 0 Tu,We,Fr 08:45-12:15,13:30-17:40; Th 09:45-12:15,13:30-17:40; Sa 08:45-12:10; Su,Mo off