Search in sources :

Example 1 with DayOfWeek

use of org.motechproject.commons.date.model.DayOfWeek in project motech by motech.

the class DateUtilTest method shouldGetNextApplicableDateAfterGivenDateBasedOnApplicableWeekDays.

@Test
public void shouldGetNextApplicableDateAfterGivenDateBasedOnApplicableWeekDays() {
    DateTime oct1Sat2011 = new DateTime(2011, 10, 1, 0, 0);
    DateTime oct2Sun2011 = new DateTime(2011, 10, 2, 2, 0);
    DateTime oct3Mon2011 = new DateTime(2011, 10, 3, 0, 0);
    DateTime oct4Tue2011 = new DateTime(2011, 10, 4, 5, 0);
    DateTime oct6Thu2011 = new DateTime(2011, 10, 6, 3, 0);
    List<DayOfWeek> applicableDays = asList(Monday, Wednesday, DayOfWeek.Friday);
    assertThat(nextApplicableWeekDay(oct1Sat2011, applicableDays), is(oct1Sat2011.dayOfYear().addToCopy(2)));
    assertThat(nextApplicableWeekDay(oct2Sun2011, applicableDays), is(oct2Sun2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDay(oct3Mon2011, applicableDays), is(oct3Mon2011.dayOfYear().addToCopy(2)));
    assertThat(nextApplicableWeekDay(oct4Tue2011, applicableDays), is(oct4Tue2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDay(oct6Thu2011, applicableDays), is(oct6Thu2011.dayOfYear().addToCopy(1)));
    DateTime oct7Fri2011 = new DateTime(2011, 10, 7, 0, 1);
    DateTime oct8Sat2011 = new DateTime(2011, 10, 8, 0, 3);
    DateTime oct9Sun2011 = new DateTime(2011, 10, 9, 0, 4);
    DateTime oct10Mon2011 = new DateTime(2011, 10, 10, 5, 5);
    applicableDays = asList(DayOfWeek.Sunday, DayOfWeek.Saturday);
    assertThat(nextApplicableWeekDay(oct6Thu2011, applicableDays), is(oct6Thu2011.dayOfYear().addToCopy(2)));
    assertThat(nextApplicableWeekDay(oct7Fri2011, applicableDays), is(oct7Fri2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDay(oct8Sat2011, applicableDays), is(oct8Sat2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDay(oct9Sun2011, applicableDays), is(oct9Sun2011.dayOfYear().addToCopy(6)));
    assertThat(nextApplicableWeekDay(oct10Mon2011, applicableDays), is(oct10Mon2011.dayOfYear().addToCopy(5)));
    DateTime feb25Sat2012 = new DateTime(2012, 2, 25, 0, 5);
    applicableDays = asList(DayOfWeek.Saturday);
    DateTime actualMar3Sat2012 = feb25Sat2012.dayOfYear().addToCopy(7);
    assertNotSame(feb25Sat2012, actualMar3Sat2012);
    assertThat(nextApplicableWeekDay(feb25Sat2012, applicableDays), is(actualMar3Sat2012));
}
Also used : DayOfWeek(org.motechproject.commons.date.model.DayOfWeek) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with DayOfWeek

use of org.motechproject.commons.date.model.DayOfWeek in project motech by motech.

the class CronExpressionUtilTest method shouldParseValidCronExpression.

@Test
public void shouldParseValidCronExpression() {
    String expression = "0 25 13 ? * 1,2,3,4,7";
    Time expectedTime = new Time(13, 25);
    List<DayOfWeek> expectedDaysOfWeek = prepareExpectedDaysOfWeek();
    CronExpressionUtil util = new CronExpressionUtil(expression);
    assertThat(util.getTime(), equalTo(expectedTime));
    assertThat(util.getDaysOfWeek(), equalTo(expectedDaysOfWeek));
}
Also used : DayOfWeek(org.motechproject.commons.date.model.DayOfWeek) Time(org.motechproject.commons.date.model.Time) Test(org.junit.Test)

Example 3 with DayOfWeek

use of org.motechproject.commons.date.model.DayOfWeek in project motech by motech.

the class MotechSchedulerActionProxyServiceImpl method scheduleDayOfWeekJob.

@Override
public void scheduleDayOfWeekJob(String subject, Map<Object, Object> parameters, DateTime start, DateTime end, List<Object> days, DateTime time, Boolean ignorePastFiresAtStart) {
    MotechEvent motechEvent = new MotechEvent(subject, createMotechEventParameters(parameters));
    Time jobTime = new Time(time.getHourOfDay(), time.getMinuteOfHour());
    List<DayOfWeek> jobDayOfWeeks = createDayOfWeeks(days);
    DayOfWeekSchedulableJob job = new DayOfWeekSchedulableJob(motechEvent, start, end != null ? end : null, jobDayOfWeeks, jobTime, ignorePastFiresAtStart);
    scheduler.scheduleDayOfWeekJob(job);
}
Also used : DayOfWeek(org.motechproject.commons.date.model.DayOfWeek) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) MotechEvent(org.motechproject.event.MotechEvent)

Example 4 with DayOfWeek

use of org.motechproject.commons.date.model.DayOfWeek in project motech by motech.

the class DateUtilTest method shouldGetNextApplicableDateIncludingFromDateBasedOnApplicableWeekDays.

@Test
public void shouldGetNextApplicableDateIncludingFromDateBasedOnApplicableWeekDays() {
    DateTime oct1Sat2011 = new DateTime(2011, 10, 1, 0, 0);
    DateTime oct2Sun2011 = new DateTime(2011, 10, 2, 2, 0);
    DateTime oct3Mon2011 = new DateTime(2011, 10, 3, 0, 0);
    DateTime oct4Tue2011 = new DateTime(2011, 10, 4, 5, 0);
    DateTime oct6Thu2011 = new DateTime(2011, 10, 6, 3, 0);
    List<DayOfWeek> applicableDays = asList(Monday, Wednesday, DayOfWeek.Friday);
    assertThat(nextApplicableWeekDayIncludingFromDate(oct1Sat2011, applicableDays), is(oct1Sat2011.dayOfYear().addToCopy(2)));
    assertThat(nextApplicableWeekDayIncludingFromDate(oct2Sun2011, applicableDays), is(oct2Sun2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDayIncludingFromDate(oct3Mon2011, applicableDays), is(oct3Mon2011));
    assertThat(nextApplicableWeekDayIncludingFromDate(oct4Tue2011, applicableDays), is(oct4Tue2011.dayOfYear().addToCopy(1)));
    assertThat(nextApplicableWeekDayIncludingFromDate(oct6Thu2011, applicableDays), is(oct6Thu2011.dayOfYear().addToCopy(1)));
}
Also used : DayOfWeek(org.motechproject.commons.date.model.DayOfWeek) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DayOfWeek (org.motechproject.commons.date.model.DayOfWeek)4 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 Time (org.motechproject.commons.date.model.Time)2 MotechEvent (org.motechproject.event.MotechEvent)1 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)1