Example usage for org.joda.time LocalDate minusDays

List of usage examples for org.joda.time LocalDate minusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate minusDays.

Prototype

public LocalDate minusDays(int days) 

Source Link

Document

Returns a copy of this date minus the specified number of days.

Usage

From source file:com.squid.kraken.v4.api.core.EngineUtils.java

License:Open Source License

/**
 * Convert the facet value into a date. 
 * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant.
 * @param ctx//from w  w w .  j  av a 2s .  c  o m
 * @param index
 * @param lower 
 * @param value
 * @param compareFromInterval 
 * @return
 * @throws ParseException
 * @throws ScopeException
 * @throws ComputingException 
 */
public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value,
        IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException {
    if (value.equals("")) {
        return null;
    } else if (value.startsWith("__")) {
        //
        // support hard-coded shortcuts
        if (value.toUpperCase().startsWith("__COMPARE_TO_")) {
            // for compareTo
            if (compareFromInterval == null) {
                // invalid compare_to selection...
                return null;
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                if (bound == Bound.UPPER) {
                    LocalDate date = localLower.minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate date = localLower.minusDays(1 + days.getDays());
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusMonths(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusYears(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
        } else {
            // for regular
            // get MIN, MAX first
            Intervalle range = null;
            if (index.getDimension().getType() == Type.CONTINUOUS) {
                if (index.getStatus() == Status.DONE) {
                    List<DimensionMember> members = index.getMembers();
                    if (!members.isEmpty()) {
                        DimensionMember member = members.get(0);
                        Object object = member.getID();
                        if (object instanceof Intervalle) {
                            range = (Intervalle) object;
                        }
                    }
                } else {
                    try {
                        DomainHierarchy hierarchy = universe
                                .getDomainHierarchy(index.getAxis().getParent().getDomain());
                        hierarchy.isDone(index, null);
                    } catch (ComputingException | InterruptedException | ExecutionException
                            | TimeoutException e) {
                        throw new ComputingException("failed to retrieve period interval");
                    }
                }
            }
            if (range == null) {
                range = IntervalleObject.createInterval(new Date(), new Date());
            }
            if (value.equalsIgnoreCase("__ALL")) {
                if (index.getDimension().getType() != Type.CONTINUOUS) {
                    return null;
                }
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getLowerBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_DAY")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getUpperBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_7_DAYS")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.minusDays(6);// 6+1
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_MONTH")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_YEAR")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1);
                    return date.toDate();
                }
            }
        }
        throw new ScopeException("undefined facet expression alias: " + value);
    } else if (value.startsWith("=")) {
        // if the value starts by equal token, this is a formula that can be
        // evaluated
        try {
            String expr = value.substring(1);
            // check if the index content is available or wait for it
            DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(),
                    true);
            hierarchy.isDone(index, null);
            // evaluate the expression
            Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval);
            // check we can use it
            if (defaultValue == null) {
                //throw new ScopeException("unable to parse the facet expression as a constant: " + expr);
                // T1769: it's ok to return null
                return null;
            }
            if (!(defaultValue instanceof Date)) {
                throw new ScopeException("unable to parse the facet expression as a date: " + expr);
            }
            // ok, it's a date
            return (Date) defaultValue;
        } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) {
            throw new ComputingException("failed to retrieve period interval");
        }
    } else {
        Date date = ServiceUtils.getInstance().toDate(value);
        if (bound == Bound.UPPER
                && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) {
            // clear the timestamp
            return new LocalDate(date.getTime()).toDate();
        } else {
            return date;
        }
    }
}

From source file:config.TimeManipulation.java

License:Open Source License

/**
 * //w ww  . jav a  2  s.c  om
 * @param LocalDate Date
 * @param String Time 
 */

public DateTime EventDateTime(LocalDate Date, String Time) {

    if (Time == null)
        return null;

    char modifier = Time.charAt(Time.length() - 1);
    Time = Time.substring(0, Time.length() - 1);

    if (modifier == 'B') {
        Date.minusDays(1);
    }

    if (modifier == 'X') {
        Date.plusDays(1);
    }
    LocalTime timeformat = new LocalTime(Time);

    return Date.toDateTime(timeformat);
}

From source file:cz.muni.fi.pb138.jizdenky.service.pojo.FirstMinuteDiscount.java

@Override
public boolean isApplicable(LocalDate dayOfOrder) {
    return dayOfOrder.minusDays(daysInAdvance).isAfter(LocalDate.now());
}

From source file:de.appsolve.padelcampus.controller.ranking.RankingController.java

@RequestMapping("{participantUUID}/history")
public ModelAndView getRankingHistory(@PathVariable() String participantUUID) throws JsonProcessingException {
    Participant participant = participantDAO.findByUUID(participantUUID);
    if (participant == null) {
        throw new ResourceNotFoundException();
    }//from  w ww . j  av  a 2  s . c om

    LocalDate endDate = LocalDate.now();
    LocalDate startDate = endDate.minusDays(365);
    Map<Gender, Map<Long, BigDecimal>> genderDateRankingMap = new TreeMap<>();
    for (Gender gender : EnumSet.of(Gender.male, Gender.female, Gender.unisex)) {
        List<Ranking> rankings = rankingUtil.getPlayerRanking(gender, participant, startDate, endDate);
        if (rankings != null && !rankings.isEmpty()) {
            Map<Long, BigDecimal> dateRankingMap = new TreeMap<>();
            for (Ranking ranking : rankings) {
                LocalDate date = ranking.getDate();
                Long millis = date.toDateTimeAtStartOfDay().getMillis();
                dateRankingMap.put(millis, ranking.getValue().setScale(0, RoundingMode.HALF_UP));
            }
            genderDateRankingMap.put(gender, dateRankingMap);
        }
    }
    ModelAndView mav = new ModelAndView(getPath() + "ranking/history");
    mav.addObject("Participant", participant);
    mav.addObject("GenderDateRankingMap", genderDateRankingMap);
    mav.addObject("ChartMap", objectMapper.writeValueAsString(genderDateRankingMap));
    return mav;
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public void addWeekView(HttpServletRequest request, LocalDate selectedDate, List<Facility> selectedFacilities,
        ModelAndView mav, Boolean onlyFutureTimeSlots, Boolean preventOverlapping)
        throws JsonProcessingException {
    //calculate date configuration for datepicker
    LocalDate today = new LocalDate(DEFAULT_TIMEZONE);
    LocalDate firstDay = today.dayOfMonth().withMinimumValue();
    LocalDate lastDay = getLastBookableDay(request).plusDays(1);
    List<CalendarConfig> calendarConfigs = calendarConfigDAO.findBetween(firstDay, lastDay);
    Collections.sort(calendarConfigs);
    Map<String, DatePickerDayConfig> dayConfigs = getDayConfigMap(firstDay, lastDay, calendarConfigs);

    List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsBetween(firstDay, lastDay);

    //calculate available time slots
    List<TimeSlot> timeSlots = new ArrayList<>();
    List<LocalDate> weekDays = new ArrayList<>();
    for (int i = 1; i <= CalendarWeekDay.values().length; i++) {
        LocalDate date = selectedDate.withDayOfWeek(i);
        weekDays.add(date);//from ww  w  .  j  a  v  a 2s  . c om
        if ((!onlyFutureTimeSlots || !date.isBefore(today)) && lastDay.isAfter(date)) {
            try {
                //generate list of bookable time slots
                timeSlots.addAll(getTimeSlotsForDate(date, calendarConfigs, confirmedBookings,
                        onlyFutureTimeSlots, preventOverlapping));
            } catch (CalendarConfigException e) {
                //safe to ignore
            }
        }
    }

    SortedSet<Offer> offers = new TreeSet<>();
    List<TimeRange> rangeList = new ArrayList<>();
    //Map<TimeRange, List<TimeSlot>> rangeList = new TreeMap<>();
    for (TimeSlot slot : timeSlots) {
        Set<Offer> slotOffers = slot.getConfig().getOffers();
        offers.addAll(slotOffers);

        TimeRange range = new TimeRange();
        range.setStartTime(slot.getStartTime());
        range.setEndTime(slot.getEndTime());

        if (rangeList.contains(range)) {
            range = rangeList.get(rangeList.indexOf(range));
        } else {
            rangeList.add(range);
        }

        List<TimeSlot> slotis = range.getTimeSlots();
        slotis.add(slot);
        range.setTimeSlots(slotis);
    }
    Collections.sort(rangeList);

    List<Offer> selectedOffers = new ArrayList<>();
    if (selectedFacilities.isEmpty()) {
        selectedOffers = offerDAO.findAll();
    } else {
        for (Facility facility : selectedFacilities) {
            selectedOffers.addAll(facility.getOffers());
        }
    }
    Collections.sort(selectedOffers);

    mav.addObject("dayConfigs", objectMapper.writeValueAsString(dayConfigs));
    mav.addObject("maxDate", lastDay.toString());
    mav.addObject("Day", selectedDate);
    mav.addObject("NextMonday", selectedDate.plusDays(8 - selectedDate.getDayOfWeek()));
    mav.addObject("PrevSunday", selectedDate.minusDays(selectedDate.getDayOfWeek()));
    mav.addObject("WeekDays", weekDays);
    mav.addObject("RangeMap", rangeList);
    mav.addObject("Offers", offers);
    mav.addObject("SelectedOffers", selectedOffers);
    mav.addObject("SelectedFacilities", selectedFacilities);
    mav.addObject("Facilities", facilityDAO.findAll());
}

From source file:de.appsolve.padelcampus.utils.RankingUtil.java

private List<Game> getGamesInLastYearSince(Gender gender, LocalDate date) {
    LocalDate since = date.minusDays(ELO_MAX_DAYS);
    List<Game> games = gameDAO.findAllYoungerThanForGenderWithPlayers(since, gender);
    return games;
}

From source file:de.appsolve.padelcampus.utils.RankingUtil.java

private List<Game> getGamesInLastYearSince(Gender gender, LocalDate date, Customer customer) {
    LocalDate since = date.minusDays(ELO_MAX_DAYS);
    List<Game> games = gameBaseDAO.findAllYoungerThanForGenderWithPlayers(since, gender, customer);
    return games;
}

From source file:de.jollyday.parser.impl.ChristianHolidayParser.java

License:Apache License

/**
 * {@inheritDoc}//from   w w w  . java  2 s.  c o m
 *
 * Parses all christian holidays relative to eastern.
 */
@Override
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (ChristianHoliday ch : config.getChristianHoliday()) {
        if (!isValid(ch, year)) {
            continue;
        }
        LocalDate easterSunday = getEasterSunday(year, ch.getChronology());
        switch (ch.getType()) {
        case EASTER:
            break;
        case CLEAN_MONDAY:
        case SHROVE_MONDAY:
            easterSunday = easterSunday.minusDays(48);
            break;
        case MARDI_GRAS:
        case CARNIVAL:
            easterSunday = easterSunday.minusDays(47);
            break;
        case ASH_WEDNESDAY:
            easterSunday = easterSunday.minusDays(46);
            break;
        case MAUNDY_THURSDAY:
            easterSunday = easterSunday.minusDays(3);
            break;
        case GOOD_FRIDAY:
            easterSunday = easterSunday.minusDays(2);
            break;
        case EASTER_SATURDAY:
            easterSunday = easterSunday.minusDays(1);
            break;
        case EASTER_MONDAY:
            easterSunday = easterSunday.plusDays(1);
            break;
        case EASTER_TUESDAY:
            easterSunday = easterSunday.plusDays(2);
            break;
        case GENERAL_PRAYER_DAY:
            easterSunday = easterSunday.plusDays(26);
            break;
        case ASCENSION_DAY:
            easterSunday = easterSunday.plusDays(39);
            break;
        case PENTECOST:
        case WHIT_SUNDAY:
            easterSunday = easterSunday.plusDays(49);
            break;
        case WHIT_MONDAY:
        case PENTECOST_MONDAY:
            easterSunday = easterSunday.plusDays(50);
            break;
        case CORPUS_CHRISTI:
            easterSunday = easterSunday.plusDays(60);
            break;
        case SACRED_HEART:
            easterSunday = easterSunday.plusDays(68);
            break;
        default:
            throw new IllegalArgumentException("Unknown christian holiday type " + ch.getType());
        }
        String propertiesKey = "christian." + ch.getType().name();
        addChrstianHoliday(easterSunday, propertiesKey, ch.getLocalizedType(), holidays);
    }
}

From source file:de.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java

License:Apache License

/**
 * {@inheritDoc}// ww  w  .  ja  v a  2s . c om
 * 
 * Parses the provided configuration and creates holidays for the provided
 * year.
 */
@Override
public void parse(int year, Set<Holiday> holidays, final Holidays config) {
    for (FixedWeekdayRelativeToFixed f : config.getFixedWeekdayRelativeToFixed()) {
        if (!isValid(f, year)) {
            continue;
        }
        LocalDate day = calendarUtil.create(year, f.getDay());
        day = moveDateToFirstOccurenceOfWeekday(f, day);
        int days = determineNumberOfDays(f);
        day = f.getWhen() == When.AFTER ? day.plusDays(days) : day.minusDays(days);
        HolidayType type = xmlUtil.getType(f.getLocalizedType());
        holidays.add(new Holiday(day, f.getDescriptionPropertiesKey(), type));
    }
}

From source file:de.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java

License:Apache License

private LocalDate moveDateToFirstOccurenceOfWeekday(FixedWeekdayRelativeToFixed f, LocalDate day) {
    do {//from   www. j  a v a2s  .  c  o  m
        // move fixed to first occurrence of weekday
        day = f.getWhen() == When.AFTER ? day.plusDays(1) : day.minusDays(1);
    } while (day.getDayOfWeek() != xmlUtil.getWeekday(f.getWeekday()));
    return day;
}