@Test public void testParseSingleDateRangeOneDayOnlyIncludingPh() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Su, PH"); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 26))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 27))); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 28))); }
@Test public void testToString() throws ParseException { DateRange instance = DateRangeParser.parseDateRange("Mar-Oct"); assertEquals( "yearless:true, dayOnly:false, reverse:false, from:1970-03-01T00:00:00Z, to:1970-10-31T23:59:59Z", instance.toString()); }
@Test public void testParseReverseDateRange() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("2014 Aug 14-2015 Mar 10"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 13))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 14))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.MARCH, 10))); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.MARCH, 11))); }
@Test public void testParseSimpleDateRangeWithoutYearAndDay2() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Mar-Sep"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.FEBRUARY, 25))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.MARCH, 1))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 30))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.NOVEMBER, 1))); }
@Test public void testParseSimpleDateRangeWithoutYearAndDay() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Jul-Aug"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.JUNE, 9))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.JULY, 10))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 12))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 14))); }
@Test public void testParseSingleDateRangeWithoutYearAndDay() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Sep"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 31))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 1))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 30))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.OCTOBER, 1))); }
@Test public void testParseSimpleDateRangeWithoutYear() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Aug 10-Aug 14"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 9))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 10))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 12))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 14))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 15))); }
@Test public void testParseReverseDateRangeWithoutYearAndDay_645() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Aug 10-Jan"); assertFalse(dateRange.isInRange(getCalendar(2016, Calendar.AUGUST, 9))); assertTrue(dateRange.isInRange(getCalendar(2016, Calendar.AUGUST, 10))); assertTrue(dateRange.isInRange(getCalendar(2016, Calendar.JANUARY, 1))); assertTrue(dateRange.isInRange(getCalendar(2016, Calendar.JANUARY, 20))); assertTrue(dateRange.isInRange(getCalendar(2016, Calendar.JANUARY, 31))); assertFalse(dateRange.isInRange(getCalendar(2016, Calendar.FEBRUARY, 1))); }
@Test public void testParseSingleDateRangeDayOnly() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Mo-Fr"); assertTrue(dateRange.dayOnly); assertFalse(dateRange.reverse); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 20))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 21))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 25))); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 26))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 28))); }
@Test public void testParseReverseDateRangeDayOnly() throws ParseException { // This is reverse since Su=7 and Mo=1 // Note: If we use Locale.Germany or Locale.UK for calendar creation // then cal.set(DAY_OF_WEEK, 7) results in a "time in millis" after Saturday leading to // reverse=false DateRange dateRange = DateRangeParser.parseDateRange("Sa-Su"); assertTrue(dateRange.dayOnly); assertTrue(dateRange.reverse); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 25))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 26))); assertTrue(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 27))); assertFalse(dateRange.isInRange(getCalendar(2015, Calendar.DECEMBER, 28))); }
@Test public void testParseReverseDateRangeWithoutYear() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Aug 14-Aug 10"); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.JANUARY, 9))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 9))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 10))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 12))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 14))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 15))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 15))); }
@Test public void testParseReverseDateRangeWithoutYearAndDay() throws ParseException { DateRange dateRange = DateRangeParser.parseDateRange("Sep-Mar"); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.AUGUST, 31))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.SEPTEMBER, 1))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.DECEMBER, 24))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.JANUARY, 24))); assertTrue(dateRange.isInRange(getCalendar(2014, Calendar.MARCH, 31))); assertFalse(dateRange.isInRange(getCalendar(2014, Calendar.APRIL, 1))); }