Search in sources :

Example 16 with TimeRange

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

the class PPSReportXlsService method getShiftStartDate.

private Optional<DateTime> getShiftStartDate(final DateTime day, final Entity shift) {
    Shift shiftFirst = new Shift(shift);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
    if (ranges.isEmpty()) {
        return Optional.empty();
    }
    LocalTime startTime = ranges.get(0).getFrom();
    DateTime startShitTime = day;
    startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
    startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    return Optional.of(startShitTime);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime)

Example 17 with TimeRange

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

the class PPSReportXlsService method getShiftEndDate.

private Optional<DateTime> getShiftEndDate(final DateTime day, final Entity shift) {
    Shift shiftFirst = new Shift(shift);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
    if (ranges.isEmpty()) {
        return Optional.empty();
    }
    LocalTime startTime = ranges.get(0).getTo();
    DateTime startShitTime = day;
    startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
    startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    return Optional.of(startShitTime);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime)

Example 18 with TimeRange

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

the class PpsTimeHelper method findFinishDate.

public Date findFinishDate(final Entity dailyProgress, final Date dateOfDay, final Entity order) {
    DateTime endDate = null;
    DateTime dateOfDayDT = new DateTime(dateOfDay, DateTimeZone.getDefault());
    DateTime orderStartDate = new DateTime(order.getDateField(OrderFields.START_DATE), DateTimeZone.getDefault());
    Entity shiftEntity = dailyProgress.getBelongsToField(DailyProgressFields.SHIFT);
    Shift shift = new Shift(shiftEntity);
    int time = dailyProgress.getIntegerField(DailyProgressFields.EFFICIENCY_TIME);
    List<TimeRange> shiftWorkTime = Lists.newArrayList();
    List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList();
    if (shift.worksAt(dateOfDay.getDay() == 0 ? 7 : dateOfDay.getDay())) {
        shiftWorkTime = shift.findWorkTimeAt(new LocalDate(dateOfDay));
    }
    for (TimeRange range : shiftWorkTime) {
        DateTimeRange dateTimeRange = new DateTimeRange(dateOfDayDT, range);
        DateTimeRange trimmedRange = dateTimeRange.trimBefore(orderStartDate);
        if (trimmedRange != null) {
            shiftWorkDateTime.add(trimmedRange);
        }
    }
    shiftWorkDateTime = shiftExceptionService.manageExceptions(shiftWorkDateTime, order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay, true);
    for (DateTimeRange range : shiftWorkDateTime) {
        if (range.durationInMins() >= time && time > 0) {
            endDate = range.getFrom().plusMinutes(time);
            time = 0;
        } else {
            endDate = range.getTo();
            time -= range.durationInMins();
        }
    }
    return endDate != null ? endDate.toDate() : null;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 19 with TimeRange

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

the class ShiftTest method shouldReturnWorkingHoursForDay.

@Test
public final void shouldReturnWorkingHoursForDay() {
    // given
    String hours = "6:00-12:00, 21:30-2:30";
    given(shiftEntity.getStringField(ShiftFields.MONDAY_HOURS)).willReturn(hours);
    given(shiftEntity.getBooleanField(ShiftFields.MONDAY_WORKING)).willReturn(true);
    LocalDate mondayDate = new LocalDate(2013, 9, 2);
    // when
    Shift shift = new Shift(shiftEntity);
    List<TimeRange> timeRanges = shift.findWorkTimeAt(mondayDate);
    // then
    List<TimeRange> expectedTimeRanges = ImmutableList.of(new TimeRange(new LocalTime(6, 0), new LocalTime(12, 0)), new TimeRange(new LocalTime(21, 30), new LocalTime(2, 30)));
    assertEquals(expectedTimeRanges, timeRanges);
}
Also used : TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

TimeRange (com.qcadoo.commons.dateTime.TimeRange)19 DateTime (org.joda.time.DateTime)12 LocalTime (org.joda.time.LocalTime)12 Shift (com.qcadoo.mes.basic.shift.Shift)10 Entity (com.qcadoo.model.api.Entity)6 LocalDate (org.joda.time.LocalDate)5 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)4 Date (java.util.Date)4 Test (org.junit.Test)4 Lists (com.google.common.collect.Lists)2 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 List (java.util.List)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Service (org.springframework.stereotype.Service)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 FluentIterable (com.google.common.collect.FluentIterable)1 Maps (com.google.common.collect.Maps)1 FluentOptional (com.qcadoo.commons.functional.FluentOptional)1