use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class ShiftsServiceImpl method getNearestWorkingDateForShiftWorkTime.
private void getNearestWorkingDateForShiftWorkTime(final TimeRange shiftWorkTime, final DateTime dateFrom, final DateTime currentDate, final List<DateTimeRange> workTimes) {
LocalTime currentTime = currentDate.toLocalTime();
LocalTime timeTo = shiftWorkTime.getTo();
LocalTime timeFrom = shiftWorkTime.getFrom();
if (!currentDate.equals(dateFrom.minusDays(1)) || timeFrom.isAfter(timeTo)) {
if (timeFrom.isAfter(timeTo) && currentDate.equals(dateFrom.minusDays(1))) {
if (currentTime.compareTo(LocalTime.MIDNIGHT) >= 0 && currentTime.compareTo(timeTo) <= 0) {
Optional<Interval> interval = createInterval(currentDate.plusDays(1), currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else {
if (currentDate.equals(dateFrom)) {
if (timeFrom.compareTo(currentTime) < 0 && timeTo.compareTo(currentTime) > 0) {
Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
} else if (timeFrom.isAfter(timeTo)) {
if (timeFrom.compareTo(currentTime) < 0) {
Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
} else {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else if (timeFrom.compareTo(currentTime) >= 0) {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
}
}
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class Shift method findWorkTimeAt.
/**
* Returns date range containing given date. This method IS AWARE of timetable exceptions.
*
* <b>Be aware</b> - this method doesn't compose returned date range with the timetable exclusions/inclusions. This means that
* if you have a shift which works at Monday from 8:00-16:00 and there is defined work time exclusion from 12:00-20:00 and you
* ask for 10:00 then you will get date range from 8:00-16:00 (as in plan). But if you ask for 14:00 you will get
* Optional.absent().
*
* @param date
* date with time for which work dates range you want to find.
* @return
*/
public Optional<DateRange> findWorkTimeAt(final Date date) {
if (timetableExceptions.hasFreeTimeAt(date)) {
return Optional.absent();
}
DateTime dateTime = new DateTime(date);
Optional<TimeRange> maybeTimeRangeFromPlan = findWorkTimeAt(dateTime.getDayOfWeek(), dateTime.toLocalTime());
for (TimeRange timeRangeFromPlan : maybeTimeRangeFromPlan.asSet()) {
return Optional.of(buildDateRangeFrom(timeRangeFromPlan, date));
}
return timetableExceptions.findDateRangeFor(TimetableExceptionType.WORK_TIME, date);
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class WorkingHours method stringToInterval.
private TimeRange stringToInterval(final String hoursRange) {
String[] lowerUpperBound = StringUtils.split(hoursRange, '-');
LocalTime lower = LocalTime.parse(lowerUpperBound[0], TIME_FORMATTER);
LocalTime upper = LocalTime.parse(lowerUpperBound[1], TIME_FORMATTER);
return new TimeRange(lower, upper);
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class WorkingHoursTest method shouldBuildWorkingHoursFromSingleTimeRangeWithTwoDigitsHour.
@Test
public final void shouldBuildWorkingHoursFromSingleTimeRangeWithTwoDigitsHour() {
// given
String timeRangeString = "09:00-17:00";
// when
WorkingHours workingHours = new WorkingHours(timeRangeString);
// then
assertEquals(1, workingHours.getTimeRanges().size());
TimeRange timeRange = workingHours.getTimeRanges().iterator().next();
assertEquals(new LocalTime(9, 0, 0), timeRange.getFrom());
assertEquals(new LocalTime(17, 0, 0), timeRange.getTo());
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class WorkingHoursTest method shouldBuildWorkingHoursFromSingleTimeRangeWithOneDigitsHour.
@Test
public final void shouldBuildWorkingHoursFromSingleTimeRangeWithOneDigitsHour() {
// given
String timeRangeString = "9:00-17:00";
// when
WorkingHours workingHours = new WorkingHours(timeRangeString);
// then
assertEquals(1, workingHours.getTimeRanges().size());
TimeRange timeRange = workingHours.getTimeRanges().iterator().next();
assertEquals(new LocalTime(9, 0, 0), timeRange.getFrom());
assertEquals(new LocalTime(17, 0, 0), timeRange.getTo());
}
Aggregations