Search in sources :

Example 6 with Time

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

the class CronJobSimpleExpressionBuilderTest method testBuild.

@Test
public void testBuild() {
    CronJobSimpleExpressionBuilder builder = new CronJobSimpleExpressionBuilder(new Time(10, 25));
    assertEquals("0 25 10 * * ?", builder.build());
}
Also used : Time(org.motechproject.commons.date.model.Time) Test(org.junit.Test)

Example 7 with Time

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

the class TestEventListener method shouldScheduleInterveningDayOfWeekJob.

@Test
public void shouldScheduleInterveningDayOfWeekJob() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
        newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), true));
        List<DateTime> fireTimes = getFireTimes("test_event-job_id");
        assertEquals(asList(newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with Time

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

the class WeeklyCronJobExpressionBuilderTest method shouldBuildCronExpressionForAParticularDayAndTime.

@Test
public void shouldBuildCronExpressionForAParticularDayAndTime() {
    WeeklyCronJobExpressionBuilder weeklyCronJobExpressionBuilder = new WeeklyCronJobExpressionBuilder(DayOfWeek.Monday);
    Assert.assertEquals("0 30 10 ? * 2", weeklyCronJobExpressionBuilder.withTime(new Time(10, 30)).build());
}
Also used : Time(org.motechproject.commons.date.model.Time) Test(org.junit.Test)

Example 9 with Time

use of org.motechproject.commons.date.model.Time 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 10 with Time

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

the class TypeHelperTest method shouldParseStrings.

@Test
public void shouldParseStrings() {
    final DateTime dt = DateUtil.now();
    final DateTime dt2 = new DateTime(2009, 6, 7, 12, 11, 0, 0, DateTimeZone.forOffsetHours(1));
    final LocalDate ld = DateUtil.now().toLocalDate();
    final LocalDate ld2 = new LocalDate(2000, 8, 22);
    final LocalDateTime ldt = LocalDateTime.now();
    final LocalDateTime ldt2 = LocalDateTime.of(2015, 9, 1, 10, 15);
    final java.time.LocalDate jld = java.time.LocalDate.now();
    final java.time.LocalDate jld2 = java.time.LocalDate.of(1991, 5, 1);
    assertEquals(3, TypeHelper.parse(3, Integer.class));
    assertEquals("test", TypeHelper.parse("test", String.class));
    assertEquals(new Time(16, 4), TypeHelper.parse("16:04", Time.class));
    assertEquals(dt, TypeHelper.parse(dt.toString(), DateTime.class));
    assertEquals(dt.toDate(), TypeHelper.parse(dt.toString(), Date.class));
    assertEquals(DateUtil.setTimeZoneUTC(dt2), DateUtil.setTimeZoneUTC((DateTime) TypeHelper.parse("2009-06-07 12:11 +01:00", DateTime.class)));
    assertEquals(dt2.toDate(), TypeHelper.parse("2009-06-07 12:11 +01:00", Date.class));
    assertEquals(asList("one", "2", "three"), TypeHelper.parse("one\n2\nthree", List.class));
    assertEquals(true, TypeHelper.parse("true", Boolean.class));
    assertEquals(ld, TypeHelper.parse(ld, LocalDate.class));
    assertEquals(ld, TypeHelper.parse(ld.toString(), LocalDate.class));
    assertEquals(ld2, TypeHelper.parse("2000-08-22", LocalDate.class));
    // TODO: do not send such values from the UI
    assertEquals(ld2, TypeHelper.parse("2000-08-22T23:00:00.000Z", LocalDate.class));
    // java.time types cases
    assertEquals(jld, TypeHelper.parse(jld, java.time.LocalDate.class));
    assertEquals(jld, TypeHelper.parse(jld.toString(), java.time.LocalDate.class));
    assertEquals(jld2, TypeHelper.parse("1991-05-01", java.time.LocalDate.class));
    assertEquals(ldt, TypeHelper.parse(ldt, java.time.LocalDateTime.class));
    assertEquals(ldt, TypeHelper.parse(ldt.toString(), java.time.LocalDateTime.class));
    assertTrue(ldt2.equals(TypeHelper.parse("2015-09-01 10:15 ".concat(findServerOffset()), java.time.LocalDateTime.class)));
}
Also used : LocalDateTime(java.time.LocalDateTime) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) LocalDate(org.joda.time.LocalDate) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

Time (org.motechproject.commons.date.model.Time)16 DateTime (org.joda.time.DateTime)12 Test (org.junit.Test)10 LocalDateTime (java.time.LocalDateTime)6 LocalDate (org.joda.time.LocalDate)6 MotechEvent (org.motechproject.event.MotechEvent)5 Date (java.util.Date)4 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)4 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)4 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)3 DayOfWeek (org.motechproject.commons.date.model.DayOfWeek)2 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1