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