List of usage examples for org.joda.time LocalDateTime plusMinutes
public LocalDateTime plusMinutes(int minutes)
From source file:com.axelor.apps.organisation.service.PlanningLineService.java
License:Open Source License
public LocalDateTime computeEndDateTime(LocalDateTime startDateTime, BigDecimal duration, Unit unit) throws AxelorException { return startDateTime .plusMinutes(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 w w .ja v a2 s . c om dateTime = dateTime.withMinuteOfHour(minutes); } } return dateTime; }
From source file:com.marand.thinkmed.medications.business.impl.TherapyDisplayProvider.java
License:Open Source License
private String getCalculatedIntervalDisplay(final HourMinuteDto startHourMinute, final Integer durationInMinutes, final DateTime therapyEnd) { if (startHourMinute != null) { final LocalDateTime start = new LocalDateTime(1, 1, 1, startHourMinute.getHour(), startHourMinute.getMinute()); String intervalString = hourMinuteToString(startHourMinute) + ""; if (durationInMinutes != null) { final LocalDateTime end = start.plusMinutes(durationInMinutes); final HourMinuteDto endHourMinute = new HourMinuteDto(end.getHourOfDay(), end.getMinuteOfHour()); intervalString += hourMinuteToString(endHourMinute); } else if (therapyEnd != null) { final HourMinuteDto endHourMinute = new HourMinuteDto(therapyEnd.getHourOfDay(), therapyEnd.getMinuteOfHour()); intervalString += hourMinuteToString(endHourMinute); } else {/*from w w w. ja v a 2s . com*/ intervalString += "..."; } return intervalString; } return null; }
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public List<TimeSlot> getTimeSlotsForDate(LocalDate selectedDate, List<CalendarConfig> allCalendarConfigs, List<Booking> existingBookings, Boolean onlyFutureTimeSlots, Boolean preventOverlapping) throws CalendarConfigException { List<CalendarConfig> calendarConfigs = calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs, selectedDate);/*from ww w . jav a 2 s. c o m*/ Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (isHoliday(selectedDate, calendarConfig)) { iterator.remove(); } } List<TimeSlot> timeSlots = new ArrayList<>(); if (calendarConfigs.size() > 0) { LocalDate today = new LocalDate(DEFAULT_TIMEZONE); //sort all calendar configurations for selected date by start time Collections.sort(calendarConfigs); CalendarConfig previousConfig = null; LocalDateTime time = null; LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE); //generate list of bookable time slots int i = 0; for (CalendarConfig config : calendarConfigs) { i++; LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime()); if (time == null) { //on first iteration time = startDateTime; } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) { //reset basePriceLastConfig as this is a non contiguous offer previousConfig = null; time = startDateTime; } LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime()); while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) { BigDecimal pricePerMinDuration; if (previousConfig == null) { pricePerMinDuration = config.getBasePrice(); } else { BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig); pricePerMinDuration = previousConfigBasePricePerMinute .multiply(new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128); BigDecimal basePricePerMinute = getPricePerMinute(config); pricePerMinDuration = pricePerMinDuration.add(basePricePerMinute.multiply( new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()), MathContext.DECIMAL128)); previousConfig = null; } pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN); if (onlyFutureTimeSlots) { if (selectedDate.isAfter(today) || time.isAfter(now)) { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } } else { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } time = time.plusMinutes(config.getMinInterval()); } //make sure to display the last min interval of the day if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) { if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) { addTimeSlot(timeSlots, time, config, null); } } previousConfig = config; } //sort time slots by time Collections.sort(timeSlots); //decrease court count for every blocking booking for (TimeSlot timeSlot : timeSlots) { checkForBookedCourts(timeSlot, existingBookings, preventOverlapping); } } return timeSlots; }
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;/*from ww w. j av a2 s. c om*/ 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:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java
License:Open Source License
public void addToField(Granulaarsus field, int value) { if (field == Granulaarsus.MINUTE || field == Granulaarsus.HOUR_OF_HALF_DAY || field == Granulaarsus.HOUR_OF_DAY) { // Put date and time together LocalDateTime ajaFookus = getAsLocalDateTime(); // perform operation if (field == Granulaarsus.MINUTE) { ajaFookus = ajaFookus.plusMinutes(value); this.underlyingTime = ajaFookus.toLocalTime(); this.underlyingDate = ajaFookus.toLocalDate(); if (dateModified) { updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); }/*from w w w.ja v a2 s . co m*/ updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; } if (field == Granulaarsus.HOUR_OF_DAY || field == Granulaarsus.HOUR_OF_HALF_DAY) { ajaFookus = ajaFookus.plusHours(value); this.underlyingTime = ajaFookus.toLocalTime(); this.underlyingDate = ajaFookus.toLocalDate(); if (dateModified) { updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION); } updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; } } if (field == Granulaarsus.DAY_OF_MONTH) { this.underlyingDate = (this.underlyingDate).plusDays(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.DAY_OF_WEEK) { this.underlyingDate = (this.underlyingDate).plusDays(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.WEEK_OF_YEAR) { this.underlyingDate = (this.underlyingDate).plusWeeks(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.MONTH) { this.underlyingDate = (this.underlyingDate).plusMonths(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.YEAR) { this.underlyingDate = (this.underlyingDate).plusYears(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.YEAR_OF_CENTURY) { // NB! Toimib nagu tavalise aastaarvu muutmine this.underlyingDate = (this.underlyingDate).plusYears(value); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } if (field == Granulaarsus.CENTURY_OF_ERA) { this.underlyingDate = (this.underlyingDate).plusYears(value * 100); updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION); functionOtherThanSetUsed = true; dateModified = true; } }
From source file:energy.usef.agr.workflow.nonudi.service.PowerMatcher.java
License:Apache License
/** * Returns a interval ({@link String}) based on the date, ptuIndex, ptuDuration and number of ptus. For example: * "2015-05-01T13:00:00Z/2015-05-01T14:00:00Z". This time format is compatible with the PowerMatcher. * * @param date//ww w. j a v a 2 s .c o m * @param ptuIndex * @param ptuDuration * @param numberOfPtus * @return */ public static String getInterval(LocalDate date, int ptuIndex, int ptuDuration, int numberOfPtus) { LocalDateTime start = date.toDateTimeAtStartOfDay().toLocalDateTime() .plusMinutes((ptuIndex - 1) * ptuDuration); LocalDateTime end = start.plusMinutes(numberOfPtus * ptuDuration).minusSeconds(1); DateTime startDateTime = start.toDateTime().toDateTime(DateTimeZone.UTC); DateTime endDateTime = end.toDateTime().toDateTime(DateTimeZone.UTC); return startDateTime.toString(POWER_MATCHER_TIME_FORMAT) + "/" + endDateTime.toString(POWER_MATCHER_TIME_FORMAT); }
From source file:energy.usef.core.service.business.PrognosisConsolidationBusinessService.java
License:Apache License
private List<PtuPrognosis> filterPtuPrognosisForIntradayGateClosureValidity(List<PtuPrognosis> ptuPrognosisList, LocalDateTime planboardMessageCreationTime) { List<PtuPrognosis> filteredPrognoses = new ArrayList<>(); LocalDate prognosisPeriod = ptuPrognosisList.get(0).getPtuContainer().getPtuDate(); Integer gateClosurePtus = config.getIntegerProperty(ConfigParam.INTRADAY_GATE_CLOSURE_PTUS); Integer ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION); LocalDateTime creationTimePlusGateClosure = planboardMessageCreationTime .plusMinutes(gateClosurePtus * ptuDuration); Integer pivotIndex = PtuUtil.getPtuIndex(creationTimePlusGateClosure, ptuDuration); if (creationTimePlusGateClosure.toLocalDate().isEqual(prognosisPeriod)) { filteredPrognoses = ptuPrognosisList.stream() .filter(ptuPrognosis -> ptuPrognosis.getPtuContainer().getPtuIndex() > pivotIndex) .collect(Collectors.toList()); } else if (creationTimePlusGateClosure.toLocalDate().isBefore(prognosisPeriod)) { filteredPrognoses = ptuPrognosisList.stream().collect(Collectors.toList()); }/* w w w . j ava2 s . c om*/ return filteredPrognoses; }
From source file:org.jtwig.functions.builtin.DateFunctions.java
License:Apache License
private Date modify(String modifyString, LocalDateTime localDateTime) throws FunctionException { LocalDateTime result;/*from w w w. ja v a 2 s.c o m*/ Matcher matcher = compile(MODIFY_PATTERN).matcher(modifyString); matcher.find(); int signal = 1; if (matcher.group(1).equals("-")) signal = -1; int val = Integer.valueOf(matcher.group(2)) * signal; String type = matcher.group(3).toLowerCase(); if (type.startsWith("day")) result = localDateTime.plusDays(val); else if (type.startsWith("month")) result = localDateTime.plusMonths(val); else if (type.startsWith("year")) result = localDateTime.plusYears(val); else if (type.startsWith("second")) result = localDateTime.plusSeconds(val); else if (type.startsWith("hour")) result = localDateTime.plusHours(val); else if (type.startsWith("minute")) result = localDateTime.plusMinutes(val); else throw new FunctionException("Unknown type " + matcher.group(3)); return result.toDate(); }
From source file:org.odk.collect.android.widgets.QuestionWidget.java
License:Apache License
protected LocalDateTime skipDaylightSavingGapIfExists(LocalDateTime ldt) { while (DateTimeZone.getDefault().isLocalDateTimeGap(ldt)) { ldt = ldt.plusMinutes(1); }//ww w . ja v a 2 s . c o m return ldt; }