List of usage examples for org.joda.time LocalDateTime minusMinutes
public LocalDateTime minusMinutes(int minutes)
From source file:com.axelor.apps.crm.service.batch.BatchEventReminder.java
License:Open Source License
private boolean isExpired(EventReminder eventReminder) { LocalDateTime startDateTime = eventReminder.getEvent().getStartDateTime(); int durationTypeSelect = eventReminder.getDurationTypeSelect(); switch (durationTypeSelect) { case IEventReminder.DURATION_MINUTES: if ((startDateTime.minusMinutes(eventReminder.getDuration())).isBefore(today)) { return true; }//from ww w . j a v a 2s . c om break; case IEventReminder.DURATION_HOURS: if ((startDateTime.minusHours(eventReminder.getDuration())).isBefore(today)) { return true; } break; case IEventReminder.DURATION_DAYS: if ((startDateTime.minusDays(eventReminder.getDuration())).isBefore(today)) { return true; } break; case IEventReminder.DURATION_WEEKS: if ((startDateTime.minusWeeks(eventReminder.getDuration())).isBefore(today)) { return true; } break; } return false; }
From source file:com.axelor.apps.organisation.service.PlanningLineService.java
License:Open Source License
public LocalDateTime computeStartDateTime(BigDecimal duration, LocalDateTime endDateTime, Unit unit) throws AxelorException { return endDateTime .minusMinutes(unitConversionService.convert(unit, unitRepo.findByCode("MIN"), duration).intValue()); }
From source file:com.axelor.csv.script.ImportDateTime.java
License:Open Source License
public LocalDateTime updateMinute(LocalDateTime dateTime, String minute) { if (!Strings.isNullOrEmpty(minute)) { Matcher matcher = patternMonth.matcher(minute); if (matcher.find()) { Integer minutes = Integer.parseInt(matcher.group()); if (minute.startsWith("+")) dateTime = dateTime.plusMinutes(minutes); else if (minute.startsWith("-")) dateTime = dateTime.minusMinutes(minutes); else/* w ww.jav a 2 s . c om*/ dateTime = dateTime.withMinuteOfHour(minutes); } } return dateTime; }
From source file:com.ephemeraldreams.gallyshuttle.ui.events.PrepareAlarmReminderEvent.java
License:Apache License
private void setAlarmCalendar() { LocalDateTime alarmDateTime = DateUtils.parseToLocalDateTime(time); alarmDateTime = alarmDateTime.minusMinutes(prefReminderLength); hour = alarmDateTime.getHourOfDay(); minute = alarmDateTime.getMinuteOfHour(); }
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public OfferDurationPrice getOfferDurationPrice(List<CalendarConfig> configs, List<Booking> confirmedBookings, LocalDate selectedDate, LocalTime selectedTime, Offer selectedOffer) throws CalendarConfigException { List<TimeSlot> timeSlotsForDate = getTimeSlotsForDate(selectedDate, configs, confirmedBookings, Boolean.TRUE, Boolean.TRUE); boolean validStartTime = false; for (TimeSlot timeSlot : timeSlotsForDate) { if (timeSlot.getStartTime().equals(selectedTime)) { validStartTime = true;/*w ww . j ava 2 s .c o m*/ break; } } OfferDurationPrice offerDurationPrices = null; if (validStartTime) { //convert to required data structure Map<Offer, List<CalendarConfig>> offerConfigMap = new HashMap<>(); for (CalendarConfig config : configs) { for (Offer offer : config.getOffers()) { if (offer.equals(selectedOffer)) { List<CalendarConfig> list = offerConfigMap.get(offer); if (list == null) { list = new ArrayList<>(); } list.add(config); //sort by start time Collections.sort(list); offerConfigMap.put(offer, list); } } } Iterator<Map.Entry<Offer, List<CalendarConfig>>> iterator = offerConfigMap.entrySet().iterator(); //for every offer while (iterator.hasNext()) { Map.Entry<Offer, List<CalendarConfig>> entry = iterator.next(); Offer offer = entry.getKey(); List<CalendarConfig> configsForOffer = entry.getValue(); //make sure the first configuration starts before the requested booking time if (selectedTime.compareTo(configsForOffer.get(0).getStartTime()) < 0) { continue; } LocalDateTime endTime = null; Integer duration = configsForOffer.get(0).getMinDuration(); BigDecimal pricePerMinute; BigDecimal price = null; CalendarConfig previousConfig = null; Map<Integer, BigDecimal> durationPriceMap = new TreeMap<>(); Boolean isContiguous = true; for (CalendarConfig config : configsForOffer) { //make sure there is no gap between calendar configurations if (endTime == null) { //first run endTime = getLocalDateTime(selectedDate, selectedTime).plusMinutes(config.getMinDuration()); } else { //break if there are durations available and calendar configs are not contiguous if (!durationPriceMap.isEmpty()) { //we substract min interval before the comparison as it has been added during the last iteration LocalDateTime configStartDateTime = getLocalDateTime(selectedDate, config.getStartTime()); if (!endTime.minusMinutes(config.getMinInterval()).equals(configStartDateTime)) { break; } } } Integer interval = config.getMinInterval(); pricePerMinute = getPricePerMinute(config); //as long as the endTime is before the end time configured in the calendar LocalDateTime configEndDateTime = getLocalDateTime(selectedDate, config.getEndTime()); while (endTime.compareTo(configEndDateTime) <= 0) { TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(selectedDate); timeSlot.setStartTime(selectedTime); timeSlot.setEndTime(endTime.toLocalTime()); timeSlot.setConfig(config); Long bookingSlotsLeft = getBookingSlotsLeft(timeSlot, offer, confirmedBookings); //we only allow contiguous bookings for any given offer if (bookingSlotsLeft < 1) { isContiguous = false; break; } if (price == null) { //see if previousConfig endTime - minInterval matches the selected time. if so, take half of the previous config price as a basis if (previousConfig != null && previousConfig.getEndTime() .minusMinutes(previousConfig.getMinInterval()).equals(selectedTime)) { BigDecimal previousConfigPricePerMinute = getPricePerMinute(previousConfig); price = previousConfigPricePerMinute.multiply( new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128); price = price.add(pricePerMinute.multiply( new BigDecimal(duration - previousConfig.getMinInterval()), MathContext.DECIMAL128)); } else { price = pricePerMinute.multiply(new BigDecimal(duration.toString()), MathContext.DECIMAL128); } } else { //add price for additional interval price = price.add(pricePerMinute.multiply(new BigDecimal(interval.toString()), MathContext.DECIMAL128)); } price = price.setScale(2, RoundingMode.HALF_EVEN); durationPriceMap.put(duration, price); //increase the duration by the configured minimum interval and determine the new end time for the next iteration duration += interval; endTime = endTime.plusMinutes(interval); } if (!durationPriceMap.isEmpty()) { OfferDurationPrice odp = new OfferDurationPrice(); odp.setOffer(offer); odp.setDurationPriceMap(durationPriceMap); odp.setConfig(config); offerDurationPrices = odp; } if (!isContiguous) { //we only allow coniguous bookings for one offer. process next offer break; } previousConfig = config; } } } return offerDurationPrices; }
From source file:view.popups.shift.ShiftPanel.java
private void makeChange() { boolean inputError = false; LocalDateTime ldt = shift.getStartTime(); //Nulstiller timer. ldt = ldt.minusHours(ldt.getHourOfDay()); //Nulstiller minuttet. ldt = ldt.minusMinutes(ldt.getMinuteOfHour()); shift.setStartTime(ldt);//from w ww . j a v a 2 s. c o m //Dernst skal det som der er indtastet i configpopuppen tilfjes til //den nulstillede dato. int modifiedStartHour = checkInput(configPanel.gettStartHour(), inputError, 23, 0); if (modifiedStartHour == -1) { inputError = true; } int modifiedStartMinute = checkInput(configPanel.gettStartMinute(), inputError, 59, 0); if (modifiedStartMinute == -1) { inputError = true; } int modifiedEndHour = checkInput(configPanel.gettEndHour(), inputError, 23, 0); if (modifiedEndHour == -1) { inputError = true; } int modifiedEndMinute = checkInput(configPanel.gettEndMinute(), inputError, 59, 0); if (modifiedEndMinute == -1) { inputError = true; } //Dernst udregnes vagttiden, alts hvor mange timer og minutter //vagten tager fra starttidspunktet. if (!inputError) { shift.setHours(Hours.hours(modifiedEndHour - modifiedStartHour)); shift.setMinutes(Minutes.minutes(modifiedEndMinute - modifiedStartMinute)); } }