Example usage for org.joda.time LocalDate withDayOfWeek

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

Introduction

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

Prototype

public LocalDate withDayOfWeek(int dayOfWeek) 

Source Link

Document

Returns a copy of this date with the day of week field updated.

Usage

From source file:com.cronutils.htime.DateTimeFormatParser.java

License:Apache License

@VisibleForTesting
Map<String, String> initDaysOfWeek(Locale locale) {
    String fullDoW = String.format("%s%s%s%s", constants.dayOfWeekName(), constants.dayOfWeekName(),
            constants.dayOfWeekName(), constants.dayOfWeekName());
    LocalDate date = new LocalDate();
    Map<String, String> mapping = Maps.newHashMap();
    for (int j = 1; j < 8; j++) {
        String dow = date.withDayOfWeek(j).dayOfWeek().getAsText(locale).toLowerCase();
        mapping.put(dow, fullDoW);/*w  ww.ja v  a2s .  c om*/
        mapping.put(dow.substring(0, 3), constants.dayOfWeekName());
    }
    return mapping;
}

From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java

License:Apache License

private LocalDate adjustToNthWeekDay(LocalDate dueRepaymentPeriodDate, int nthDay, int dayOfWeek) {
    // adjust date to start of month
    dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfMonth(1);
    // adjust date to next week if current day is past specified day of
    // week./*from w ww  .  j  a  v  a 2s. com*/
    if (dueRepaymentPeriodDate.getDayOfWeek() > dayOfWeek) {
        dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(1);
    }
    // adjust date to specified date of week
    dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfWeek(dayOfWeek);
    // adjust to specified nth week day
    dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(nthDay - 1);
    return dueRepaymentPeriodDate;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

License:Apache License

private LocalDate setDayOfWeek(LocalDate nextDueLocalDate) {
    if (this.feeOnDay != nextDueLocalDate.getDayOfWeek()) {
        nextDueLocalDate = nextDueLocalDate.withDayOfWeek(this.feeOnDay);
    }/*from   w  ww . j  a  va2s  .  c  o m*/
    return nextDueLocalDate;
}

From source file:com.pamarin.income.util.DateUtils.java

private static Date toDateOfWeek(Date date, int index) {
    LocalDate now = new LocalDate(filterDate(date));
    return toStartTime(now.withDayOfWeek(index).toDate());
}

From source file:com.pamarin.income.util.JodaTimeT.java

@Test
public void firstDateOfThisWeek() {
    LocalDate now = new LocalDate(new Date().getTime());
    LOG.debug("first date of week --> {}", now.withDayOfWeek(DateTimeConstants.MONDAY));
    LOG.debug("last date of week --> {}", now.withDayOfWeek(DateTimeConstants.SUNDAY));
}

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   w  w w .ja v  a 2s  . co m
        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:fr.mycellar.application.booking.impl.BookingEventServiceImpl.java

License:Open Source License

@Override
public BookingEvent nextBookingEvent(Integer id) throws BusinessException {
    BookingEvent bookingEvent = getById(id);
    if (bookingEvent == null) {
        throw new BusinessException(BusinessError.OTHER_00003);
    }/*  w w  w.j  ava 2  s . c  o m*/

    BookingEvent next = new BookingEvent();
    next.setName(bookingEvent.getName());

    LocalDate today = new LocalDate();
    LocalDate friday = today.withDayOfWeek(DateTimeConstants.FRIDAY);
    if (!friday.isAfter(today)) {
        friday = friday.plusWeeks(1);
    }
    next.setStart(friday);
    next.setEnd(friday.plusWeeks(1).withDayOfWeek(DateTimeConstants.WEDNESDAY));

    for (BookingBottle bookingBottle : bookingEvent.getBottles()) {
        BookingBottle copy = new BookingBottle();
        copy.setBookingEvent(next);
        copy.setBottle(new Bottle());
        copy.getBottle().setFormat(bookingBottle.getBottle().getFormat());
        Wine wine;
        Wine original = bookingBottle.getBottle().getWine();
        if (original.getVintage() == null) {
            wine = original;
        } else {
            wine = wineService.find(original.getProducer(), original.getAppellation(), original.getType(),
                    original.getColor(), original.getName(), original.getVintage() + 1);
            if (wine == null) {
                wine = wineService
                        .createVintages(original, original.getVintage() + 1, original.getVintage() + 1).get(0);
            }
        }
        copy.getBottle().setWine(wine);
        copy.setMax(bookingBottle.getMax());
        copy.setPosition(bookingBottle.getPosition());
        copy.setPrice(bookingBottle.getPrice());
        copy.setUrl(bookingBottle.getUrl());
        next.getBottles().add(copy);
    }
    return save(next);
}

From source file:liteshiftwindow.LSForm.java

public LocalDate getSunday(LocalDate selectedDate) {

    // If the user selected a Sunday, return that sunday.
    if (selectedDate.dayOfWeek().get() == 7) {
        return selectedDate;
    } else {//w  w  w  .j a v  a  2  s .  c o m
        selectedDate = selectedDate.minusWeeks(1);
        return selectedDate.withDayOfWeek(7);
    }
}

From source file:net.objectlab.kit.datecalc.joda.LocalDateIMMDateCalculator.java

License:Apache License

/**
 * Assumes that the month is correct, get the day for the 2rd wednesday.
 *
 * @param original/*from   w  ww  . j a va  2  s.  co  m*/
 *            the start date
 * @return the 3rd Wednesday of the month
 */
private LocalDate calculate3rdWednesday(final LocalDate original) {
    final LocalDate firstOfMonth = original.withDayOfMonth(1);
    LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
    if (firstWed.isBefore(firstOfMonth)) {
        firstWed = firstWed.plusWeeks(1);
    }
    return firstWed.plusWeeks(2);
}

From source file:org.squashtest.tm.domain.planning.StandardWorkloadCalendar.java

License:Open Source License

private LocalDate truncateWeekendToLastFriday(LocalDate date) {
    if (isWeekend(date)) {
        return date.withDayOfWeek(DateTimeConstants.FRIDAY);
    } else {//from   ww  w.  ja v  a 2  s  . com
        return date;
    }
}