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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations