private void shiftByInterval(Calendar cal) { switch (getUnit()) { case HOUR: cal.add(Calendar.HOUR_OF_DAY, getValue()); break; case DAY: cal.add(Calendar.DATE, getValue()); break; case WEEK: cal.add(Calendar.WEEK_OF_YEAR, getValue()); break; case MONTH: cal.add(Calendar.MONTH, getValue()); break; case YEAR: cal.add(Calendar.YEAR, getValue()); break; } }
public static OrgRepeater parse(String str) { OrgRepeater repeater = new OrgRepeater(); Matcher m = OrgPatterns.REPEATER.matcher(str); if (m.find()) { if (m.groupCount() == 7) { repeater.setTypeFromString(m.group(2)); repeater.setValue(m.group(3)); repeater.setUnit(m.group(4)); if (! OrgStringUtils.isEmpty(m.group(6))) { repeater.habitDeadline = new OrgInterval(); repeater.habitDeadline.setValue(m.group(6)); repeater.habitDeadline.setUnit(m.group(7)); } } else { throw new IllegalArgumentException("Expected 7 groups (got " + m.groupCount() + ") when matching repeater " + str + " against " + OrgPatterns.REPEATER); } } else { throw new IllegalArgumentException("Failed matching repeater " + str + " against " + OrgPatterns.REPEATER); } return repeater; }
repeater = OrgRepeater.parse(m.group(1));
case CUMULATE: shiftByInterval(cal); break; shiftByInterval(cal); } while (! cal.after(now)); if (getUnit() == Unit.HOUR) { cal.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY)); shiftByInterval(cal); break;
@Test public void testRepeaterWithoutWeekDay() { OrgDateTime time = OrgDateTime.parse("<2009-10-17 13:15 .+2d/4d>"); Assert.assertTrue(time.isActive()); Assert.assertTrue(time.hasTime()); Assert.assertTrue(time.hasRepeater()); Assert.assertEquals(2, time.getRepeater().getValue()); Assert.assertEquals(OrgRepeater.Type.RESTART, time.getRepeater().getType()); Assert.assertEquals(OrgRepeater.Unit.DAY, time.getRepeater().getUnit()); Assert.assertTrue(time.getRepeater().hasHabitDeadline()); }
@Test public void testRepeaterEvery() { OrgDateTime time = OrgDateTime.parse("<2014-05-26 +4w>"); Assert.assertEquals(4, time.getRepeater().getValue()); Assert.assertEquals(OrgRepeater.Type.CUMULATE, time.getRepeater().getType()); Assert.assertEquals(OrgRepeater.Unit.WEEK, time.getRepeater().getUnit()); }
@Test public void testRepeaterWithHabitDeadline() { OrgDateTime time = OrgDateTime.parse("<2009-10-17 Sat 13:15 .+2d/4d>"); Assert.assertTrue(time.isActive()); Assert.assertTrue(time.hasTime()); Assert.assertEquals(13, time.getCalendar().get(Calendar.HOUR_OF_DAY)); Assert.assertTrue(time.hasRepeater()); Assert.assertEquals(2, time.getRepeater().getValue()); Assert.assertEquals(OrgRepeater.Type.RESTART, time.getRepeater().getType()); Assert.assertEquals(OrgRepeater.Unit.DAY, time.getRepeater().getUnit()); Assert.assertTrue(time.getRepeater().hasHabitDeadline()); Assert.assertEquals(OrgRepeater.Unit.DAY, time.getRepeater().getHabitDeadline().getUnit()); Assert.assertEquals(4, time.getRepeater().getHabitDeadline().getValue()); }
@Test public void testRepeaterInFuture() { OrgDateTime time = OrgDateTime.parse("<2014-05-26 ++4w>"); Assert.assertEquals(4, time.getRepeater().getValue()); Assert.assertEquals(OrgRepeater.Type.CATCH_UP, time.getRepeater().getType()); Assert.assertEquals(OrgRepeater.Unit.WEEK, time.getRepeater().getUnit()); }
@Test public void testRepeaterInAfterToday() { OrgDateTime time = OrgDateTime.parse("<2014-05-26 .+4w>"); Assert.assertEquals(4, time.getRepeater().getValue()); Assert.assertEquals(OrgRepeater.Type.RESTART, time.getRepeater().getType()); Assert.assertEquals(OrgRepeater.Unit.WEEK, time.getRepeater().getUnit()); }
if (!useRepeater || !orgDateTime.hasRepeater() || orgDateTime.getRepeater().getValue() == 0) { if (!time.isBefore(fromTime) && (beforeTime == null || time.isBefore(beforeTime))) { result.add(time); Period intervalPeriod = gap.toPeriod(OrgDateTimeUtils.getPeriodType(repeater.getUnit())); int units = intervalPeriod.getValue(0); int repeatTimes = units / repeater.getValue(); int addUnits = repeater.getValue() * (repeatTimes + 1); curr = time.withFieldAdded(OrgDateTimeUtils.getDurationFieldType(repeater.getUnit()), addUnits); OrgDateTimeUtils.getDurationFieldType(repeater.getUnit()), repeater.getValue() );