Search in sources :

Example 11 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderHooksTest method shouldReturnTrueForNullDates.

@Test
public void shouldReturnTrueForNullDates() throws Exception {
    // given
    DateRange dateRange = new DateRange(null, null);
    given(orderDatesService.getCalculatedDates(order)).willReturn(dateRange);
    // when
    boolean result = orderHooks.checkOrderDates(orderDD, order);
    // then
    assertTrue(result);
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Test(org.junit.Test)

Example 12 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderHooksTest method shouldReturnTrueForNullFromDate.

@Test
public void shouldReturnTrueForNullFromDate() throws Exception {
    // given
    DateRange dateRange = new DateRange(null, new Date());
    given(orderDatesService.getCalculatedDates(order)).willReturn(dateRange);
    // when
    boolean result = orderHooks.checkOrderDates(orderDD, order);
    // then
    assertTrue(result);
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) Test(org.junit.Test)

Example 13 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class Shift method buildDateRangeFrom.

private DateRange buildDateRangeFrom(final TimeRange timeRange, final Date date) {
    DateTime dateTime = new DateTime(date);
    DateTime midnight = dateTime.withTimeAtStartOfDay();
    DateTime from;
    DateTime to;
    if (timeRange.startsDayBefore()) {
        if (dateTime.toLocalTime().isBefore(timeRange.getFrom())) {
            from = timeRange.getFrom().toDateTime(midnight.minusDays(1));
            to = timeRange.getTo().toDateTime(midnight);
        } else {
            from = timeRange.getFrom().toDateTime(midnight);
            to = timeRange.getTo().toDateTime(midnight.plusDays(1));
        }
    } else {
        from = timeRange.getFrom().toDateTime(midnight);
        to = timeRange.getTo().toDateTime(midnight);
    }
    return new DateRange(from.toDate(), to.toDate());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) DateTime(org.joda.time.DateTime)

Example 14 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderDatesServiceTest method shouldReturnDateRangeWithEffectiveStartAndEffectiveEndDate.

@Test
public final void shouldReturnDateRangeWithEffectiveStartAndEffectiveEndDate() {
    // given
    Date plannedStartDate = new DateTime(2012, 12, 30, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_FROM, plannedStartDate);
    Date plannedEndDate = new DateTime(2013, 1, 1, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_TO, plannedEndDate);
    Date correctedStartDate = new DateTime(2013, 1, 3, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_FROM, correctedStartDate);
    Date correctedEndDate = new DateTime(2013, 1, 5, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_TO, correctedEndDate);
    Date effectiveStartDate = new DateTime(2013, 2, 3, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.EFFECTIVE_DATE_FROM, effectiveStartDate);
    Date effectiveEndDate = new DateTime(2013, 2, 8, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.EFFECTIVE_DATE_TO, effectiveEndDate);
    // when
    DateRange dateRange = orderDatesService.getCalculatedDates(order);
    // then
    assertEquals(effectiveStartDate, dateRange.getFrom());
    assertEquals(effectiveEndDate, dateRange.getTo());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderDatesServiceTest method shouldReturnDateRangeWithPlannedStartDate.

@Test
public final void shouldReturnDateRangeWithPlannedStartDate() {
    // given
    Date plannedStartDate = new DateTime(2013, 01, 01, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_FROM, plannedStartDate);
    // when
    DateRange dateRange = orderDatesService.getCalculatedDates(order);
    // then
    assertEquals(plannedStartDate, dateRange.getFrom());
    assertNull(dateRange.getTo());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateRange (com.qcadoo.commons.dateTime.DateRange)29 Test (org.junit.Test)25 Date (java.util.Date)24 DateTime (org.joda.time.DateTime)20 Entity (com.qcadoo.model.api.Entity)2 Shift (com.qcadoo.mes.basic.shift.Shift)1 EntityList (com.qcadoo.model.api.EntityList)1 LocalTime (org.joda.time.LocalTime)1