List of usage examples for org.joda.time LocalDate getDayOfWeek
public int getDayOfWeek()
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Returns if this date is on a wekkend. * * @param date/*from w w w . j av a2 s. c om*/ * a {@link org.joda.time.LocalDate} object. * @return is weekend */ public boolean isWeekend(final LocalDate date) { return date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY; }
From source file:com.leonarduk.finance.utils.DateUtils.java
License:Open Source License
public static LocalDate getPreviousDate(final LocalDate currentDate) { final LocalDate returnDate = currentDate.minusDays(1); if ((returnDate.getDayOfWeek() == DateTimeConstants.SATURDAY) || (returnDate.getDayOfWeek() == DateTimeConstants.SUNDAY)) { return DateUtils.getPreviousDate(returnDate); }/* w w w .j ava 2s. c o m*/ return returnDate; }
From source file:com.mars.test.jodatime.Mars_App.java
public static void main(String[] args) { // LocalDate , TimeZone LocalDate dt = new LocalDate(); // 1.?1~31//from w w w . j a va 2 s . c o m log.info("1.?" + dt.withDayOfMonth(1).toString(pattern) + " ~ " + dt.dayOfMonth().withMaximumValue().toString(pattern)); // 2.?26~25(????) log.info("2.?" + dt.minusMonths(1).withDayOfMonth(26).toString(pattern) + " ~ " + dt.withDayOfMonth(25).toString(pattern)); // 3.??? LocalDate date2 = dt.withDayOfMonth(5); if (date2.getDayOfWeek() == DateTimeConstants.SATURDAY || date2.getDayOfWeek() == DateTimeConstants.SUNDAY) { date2 = date2.plusWeeks(1).withDayOfWeek(1); } log.info("3." + date2.toString(pattern)); LocalDate date3 = dt.plusMonths(1).withDayOfMonth(5); if (date3.getDayOfWeek() >= 6) { date3 = date3.plusWeeks(1).withDayOfWeek(1); } log.info("4.2014/7" + date3.toString(pattern)); }
From source file:com.mbc.jfin.holiday.impl.WeekendHolidayCalendar.java
License:Open Source License
public boolean isWeekend(LocalDate date) { return date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY; }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
public static boolean isWeekend(@Nonnull final LocalDate aDT) { return isWeekendDay(aDT.getDayOfWeek()); }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
public static boolean isFirstDayOfWeek(@Nonnull final LocalDate aDT) { return isFirstDayOfWeek(aDT.getDayOfWeek()); }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
public static boolean isLastDayOfWeek(@Nonnull final LocalDate aDT) { return isLastDayOfWeek(aDT.getDayOfWeek()); }
From source file:com.qcadoo.mes.basic.shift.Shift.java
License:Open Source License
/** * Check if this shift will be working at given local date. This method is NOT aware of timetable exceptions * /*from w ww . j av a 2s . c o m*/ * @param localDate * @return true if this shift will be working at given local date. */ public boolean worksAt(final LocalDate localDate) { return worksAt(localDate.getDayOfWeek()); }
From source file:com.qcadoo.mes.basic.shift.Shift.java
License:Open Source License
/** * Returns a list with shift work time ranges for whole given day (of the week, to be precise). This method IS NOT AWARE of * timetable exceptions, it just check if shift works at given day of week and returns working hours. * /*from w w w. jav a 2 s . c o m*/ * @param localDate * date to check * @return shift's work time ranges for given date * @since 1.4 */ public List<TimeRange> findWorkTimeAt(final LocalDate localDate) { return Fold.fold(workingHoursPerDay.get(localDate.getDayOfWeek()), Lists.<TimeRange>newArrayList(), new BiFunction<List<TimeRange>, WorkingHours, List<TimeRange>>() { @Override public List<TimeRange> apply(final List<TimeRange> acc, final WorkingHours wh) { acc.addAll(wh.getTimeRanges()); return acc; } }); }
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
@Override public ModelAndView postEditView(@ModelAttribute("Model") ReservationRequest reservationRequest, HttpServletRequest request, BindingResult bindingResult) { ModelAndView addView = getAddView(reservationRequest); validator.validate(reservationRequest, bindingResult); if (bindingResult.hasErrors()) { return addView; }/*from ww w .j av a2 s. com*/ try { Player player = sessionUtil.getUser(request); //calculate reservation bookings, taking into account holidays LocalDate date = reservationRequest.getStartDate(); LocalDate endDate = reservationRequest.getEndDate(); List<Booking> bookings = new ArrayList<>(); List<Booking> failedBookings = new ArrayList<>(); LocalDateTime blockingTime = new LocalDateTime(); while (date.compareTo(endDate) <= 0) { Set<CalendarWeekDay> calendarWeekDays = reservationRequest.getCalendarWeekDays(); for (CalendarWeekDay calendarWeekDay : calendarWeekDays) { if (calendarWeekDay.ordinal() + 1 == date.getDayOfWeek()) { try { List<CalendarConfig> calendarConfigs = calendarConfigDAO.findFor(date); //throws CalendarConfigException Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (!bookingUtil.isHoliday(date, calendarConfig)) { for (Offer offer : reservationRequest.getOffers()) { Booking booking = new Booking(); booking.setAmount(BigDecimal.ZERO); booking.setBlockingTime(blockingTime); booking.setBookingDate(date); booking.setBookingTime(reservationRequest.getStartTime()); booking.setBookingType(BookingType.reservation); booking.setComment(reservationRequest.getComment()); booking.setConfirmed(Boolean.TRUE); booking.setCurrency(Currency.EUR); booking.setDuration(getDuration(reservationRequest, calendarConfig)); booking.setPaymentConfirmed(reservationRequest.getPaymentConfirmed()); booking.setPaymentMethod(PaymentMethod.Reservation); booking.setPlayer(player); booking.setUUID(BookingUtil.generateUUID()); booking.setOffer(offer); booking.setPublicBooking(reservationRequest.getPublicBooking()); //we call this inside the loop to prevent overbooking List<Booking> confirmedBookings = bookingDAO .findBlockedBookingsForDate(date); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice( calendarConfigs, confirmedBookings, booking.getBookingDate(), booking.getBookingTime(), offer); if (offerDurationPrice == null) { failedBookings.add(booking); continue; } else { BigDecimal price = offerDurationPrice.getDurationPriceMap() .get(booking.getDuration().intValue()); booking.setAmount(price); } TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(date); timeSlot.setStartTime(reservationRequest.getStartTime()); timeSlot.setEndTime(reservationRequest.getEndTime()); timeSlot.setConfig(calendarConfig); Long bookingSlotsLeft = bookingUtil.getBookingSlotsLeft(timeSlot, offer, confirmedBookings); if (bookingSlotsLeft < 1) { failedBookings.add(booking); continue; } //we save the booking directly to prevent overbookings booking = bookingDAO.saveOrUpdate(booking); bookings.add(booking); } } break; } break; } catch (CalendarConfigException e) { LOG.warn( "Caught calendar config exception during add reservation request. This may be normal (for holidays)", e); Booking failedBooking = new Booking(); failedBooking.setPlayer(player); failedBooking.setBookingDate(date); failedBooking.setBookingTime(reservationRequest.getStartTime()); failedBookings.add(failedBooking); } } } date = date.plusDays(1); } if (!failedBookings.isEmpty()) { throw new Exception(msg.get("UnableToReserveAllDesiredTimes", new Object[] { StringUtils.join(bookings, "<br/>"), StringUtils.join(failedBookings, "<br/>") })); } if (bookings.isEmpty()) { throw new Exception(msg.get("NoCourtReservationsForSelectedDateTime")); } return new ModelAndView("redirect:/admin/bookings/reservations"); } catch (Exception e) { LOG.error(e, e); bindingResult.addError(new ObjectError("comment", e.getMessage())); return addView; } }