public static OrgDelay parse(String str) { OrgDelay delay = new OrgDelay(); Matcher m = OrgPatterns.TIME_DELAY_P.matcher(str); if (m.find()) { if (m.groupCount() == 3) { delay.setTypeFromString(m.group(1)); delay.setValue(m.group(2)); delay.setUnit(m.group(3)); } else { throw new IllegalArgumentException("Expected 3 groups (got " + m.groupCount() + ") when matching time delay " + str + " against " + OrgPatterns.TIME_DELAY_P); } } else { throw new IllegalArgumentException("Failed matching time delay " + str + " against " + OrgPatterns.TIME_DELAY_P); } return delay; }
delay = OrgDelay.parse(m.group(0));
@Test public void testDelayOnlyWithTime() { OrgDateTime time = OrgDateTime.parse("<2009-10-17 13:15 -2d>"); Assert.assertFalse(time.hasRepeater()); Assert.assertTrue(time.hasDelay()); Assert.assertEquals(OrgDelay.Type.ALL, time.getDelay().getType()); Assert.assertEquals(2, time.getDelay().getValue()); Assert.assertEquals(OrgDelay.Unit.DAY, time.getDelay().getUnit()); }
@Test public void testDelayOnlyWithWeekday() { OrgDateTime time = OrgDateTime.parse("<2009-10-17 Wed -2d>"); Assert.assertFalse(time.hasRepeater()); Assert.assertTrue(time.hasDelay()); Assert.assertEquals(OrgDelay.Type.ALL, time.getDelay().getType()); Assert.assertEquals(2, time.getDelay().getValue()); Assert.assertEquals(OrgDelay.Unit.DAY, time.getDelay().getUnit()); }
@Test public void testDelayFirstOccurrence() { OrgDateTime time = OrgDateTime.parse("<2009-10-17 13:15 +1m --2d>"); Assert.assertTrue(time.hasRepeater()); Assert.assertTrue(time.hasDelay()); Assert.assertEquals(OrgDelay.Type.FIRST_ONLY, time.getDelay().getType()); Assert.assertEquals(2, time.getDelay().getValue()); Assert.assertEquals(OrgDelay.Unit.DAY, time.getDelay().getUnit()); }