Search in sources :

Example 11 with Time

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

the class TypeHelperTest method shouldParseDateToDate.

@Test
public void shouldParseDateToDate() {
    Date date = new Date();
    DateTime dateTime = new DateTime(date);
    LocalDate localDate = dateTime.toLocalDate();
    Time time = new Time(dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
    assertEquals(dateTime, TypeHelper.parse(dateTime, DateTime.class));
    assertEquals(date, TypeHelper.parse(dateTime, Date.class));
    assertEquals(localDate, TypeHelper.parse(dateTime, LocalDate.class));
    assertEquals(time, TypeHelper.parse(dateTime, Time.class));
    assertEquals(dateTime, TypeHelper.parse(date, DateTime.class));
    assertEquals(date, TypeHelper.parse(date, Date.class));
    assertEquals(localDate, TypeHelper.parse(date, LocalDate.class));
    assertEquals(time, TypeHelper.parse(date, Time.class));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with Time

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

the class TypeHelperTest method shouldReturnCorrectInstances.

@Test
public void shouldReturnCorrectInstances() {
    final DateTime dt = DateUtil.now();
    assertEquals(new Time(10, 10), TypeHelper.parse(new Time(10, 10), Time.class));
    assertEquals(dt, TypeHelper.parse(dt, DateTime.class));
    assertEquals(dt.toDate(), TypeHelper.parse(dt.toDate(), Date.class));
    assertEquals(11, TypeHelper.parse(11, Integer.class));
    assertEquals(asList(1, 2), TypeHelper.parse(asList(1, 2), List.class));
}
Also used : 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) 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)

Example 13 with Time

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

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

the class MotechSchedulerServiceImpl method scheduleDayOfWeekJob.

private void scheduleDayOfWeekJob(DayOfWeekSchedulableJob job, boolean update) {
    logObjectIfNotNull(job);
    validateDayOfWeekSchedulableJob(job);
    MotechEvent motechEvent = job.getMotechEvent();
    Time time = job.getTime();
    CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.atHourAndMinuteOnGivenDaysOfWeek(time.getHour(), time.getMinute(), job.getCronDays().toArray(new Integer[job.getCronDays().size()]));
    CronTriggerImpl cronTrigger = (CronTriggerImpl) cronScheduleBuilder.build();
    CronSchedulableJob cronSchedulableJob = new CronSchedulableJob(motechEvent, cronTrigger.getCronExpression(), job.getStartDate(), job.getEndDate(), job.isIgnorePastFiresAtStart(), job.isUiDefined());
    scheduleCronJob(cronSchedulableJob, true, update);
}
Also used : CronScheduleBuilder(org.quartz.CronScheduleBuilder) SchedulableJobValidator.validateCronSchedulableJob(org.motechproject.scheduler.validation.SchedulableJobValidator.validateCronSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) MotechEvent(org.motechproject.event.MotechEvent)

Example 15 with Time

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

the class EntityBuilderTest method shouldBuildAnEntityWithFieldsWithDefaultValues.

@Test
public void shouldBuildAnEntityWithFieldsWithDefaultValues() throws Exception {
    final Date date = new Date();
    final DateTime dateTime = DateUtil.now();
    final LocalDate localDate = DateUtil.now().plusYears(1).toLocalDate();
    final LocalDateTime javaLocalDateTime = LocalDateTime.now().plusDays(1);
    final java.time.LocalDate javaLocalDate = java.time.LocalDate.now().plusDays(1);
    fields.addAll(asList(fieldDtoWithDefVal("count", Integer.class, 1), fieldDtoWithDefVal("time", Time.class, new Time(10, 10)), fieldDtoWithDefVal("str", String.class, "defStr"), fieldDtoWithDefVal("dec", Double.class, 3.1), fieldDtoWithDefVal("bool", Boolean.class, true), fieldDtoWithDefVal("date", Date.class, date), fieldDtoWithDefVal("dt", DateTime.class, dateTime), fieldDtoWithDefVal("ld", LocalDate.class, localDate), fieldDtoWithDefVal("locale", Locale.class, Locale.CANADA_FRENCH), fieldDtoWithDefVal("jd", java.time.LocalDate.class, javaLocalDate), fieldDtoWithDefVal("jdt", LocalDateTime.class, javaLocalDateTime)));
    Class<?> clazz = buildClass();
    assertNotNull(clazz);
    assertField(clazz, "count", Integer.class, 1);
    assertField(clazz, "time", Time.class, new Time(10, 10));
    assertField(clazz, "str", String.class, "defStr");
    assertField(clazz, "dec", Double.class, 3.1);
    assertField(clazz, "bool", Boolean.class, true);
    assertField(clazz, "date", Date.class, date);
    assertField(clazz, "dt", DateTime.class, dateTime);
    assertField(clazz, "ld", LocalDate.class, localDate);
    assertField(clazz, "locale", Locale.class, Locale.CANADA_FRENCH);
    assertField(clazz, "jd", java.time.LocalDate.class, javaLocalDate);
    assertField(clazz, "jdt", LocalDateTime.class, javaLocalDateTime);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalDateTime(java.time.LocalDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) 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