List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayRelativeToFixedParser.java
License:Apache License
/** * Parses the provided configuration and creates holidays for the provided * year./*from w w w . ja v a2 s . co m*/ */ public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final FixedWeekdayRelativeToFixed aFixedWeekdayRelativeToFixed : aConfig .getFixedWeekdayRelativeToFixed()) { if (!isValid(aFixedWeekdayRelativeToFixed, nYear)) continue; // parsing fixed day final int nExpectedWeekday = XMLUtil.getWeekday(aFixedWeekdayRelativeToFixed.getWeekday()); LocalDate aDay = XMLUtil.create(nYear, aFixedWeekdayRelativeToFixed.getDay()); do { // move fixed to first occurrence of weekday aDay = aFixedWeekdayRelativeToFixed.getWhen() == When.AFTER ? aDay.plusDays(1) : aDay.minusDays(1); } while (aDay.getDayOfWeek() != nExpectedWeekday); int nDays = 0; switch (aFixedWeekdayRelativeToFixed.getWhich()) { case FIRST: break; case SECOND: nDays = 7; break; case THIRD: nDays = 14; break; case FOURTH: nDays = 21; break; case LAST: // seems to be unsupported break; } // move day further if it is second, third or fourth weekday aDay = aFixedWeekdayRelativeToFixed.getWhen() == When.AFTER ? aDay.plusDays(nDays) : aDay.minusDays(nDays); final IHolidayType aType = XMLUtil.getType(aFixedWeekdayRelativeToFixed.getLocalizedType()); final String sPropertyKey = aFixedWeekdayRelativeToFixed.getDescriptionPropertiesKey(); aHolidayMap.add(aDay, new ResourceBundleHoliday(aType, sPropertyKey)); } }
From source file:com.helger.datetime.holiday.parser.impl.RelativeToEasterSundayParser.java
License:Apache License
/** * Parses relative to Easter Sunday holidays. *//*from w ww . j a v a 2 s .c o m*/ public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final RelativeToEasterSunday aDay : aConfig.getRelativeToEasterSunday()) { if (!isValid(aDay, nYear)) continue; final LocalDate aEasterSunday = getEasterSunday(nYear, aDay.getChronology()); aEasterSunday.plusDays(aDay.getDays()); final String sPropertiesKey = "christian." + aDay.getDescriptionPropertiesKey(); addChrstianHoliday(aEasterSunday, sPropertiesKey, XMLUtil.getType(aDay.getLocalizedType()), aHolidayMap); } }
From source file:com.helger.datetime.holiday.parser.impl.RelativeToFixedParser.java
License:Apache License
public void parse(final int nYear, final HolidayMap aHolidays, final Holidays aConfig) { for (final RelativeToFixed aRelativeToFixed : aConfig.getRelativeToFixed()) { if (!isValid(aRelativeToFixed, nYear)) continue; LocalDate aFixed = XMLUtil.create(nYear, aRelativeToFixed.getDate()); if (aRelativeToFixed.getWeekday() != null) { // if weekday is set -> move to weekday final int nExpectedWeekday = XMLUtil.getWeekday(aRelativeToFixed.getWeekday()); final int nDirection = (aRelativeToFixed.getWhen() == When.BEFORE ? -1 : 1); do {/*from w w w.j a v a 2s . co m*/ aFixed = aFixed.plusDays(nDirection); } while (aFixed.getDayOfWeek() != nExpectedWeekday); } else if (aRelativeToFixed.getDays() != null) { // if number of days set -> move number of days aFixed = aFixed .plusDays(aRelativeToFixed.getWhen() == When.BEFORE ? -aRelativeToFixed.getDays().intValue() : aRelativeToFixed.getDays().intValue()); } final IHolidayType aType = XMLUtil.getType(aRelativeToFixed.getLocalizedType()); final String sPropertyKey = aRelativeToFixed.getDescriptionPropertiesKey(); aHolidays.add(aFixed, new ResourceBundleHoliday(aType, sPropertyKey)); } }
From source file:com.helger.datetime.holiday.parser.impl.RelativeToWeekdayInMonthParser.java
License:Apache License
@Override public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final RelativeToWeekdayInMonth aRelativeToWeekdayInMonth : aConfig.getRelativeToWeekdayInMonth()) { if (!isValid(aRelativeToWeekdayInMonth, nYear)) continue; final int nExpectedWeekday = XMLUtil.getWeekday(aRelativeToWeekdayInMonth.getWeekday()); LocalDate aDate = parse(nYear, aRelativeToWeekdayInMonth.getFixedWeekday()); final int nDirection = (aRelativeToWeekdayInMonth.getWhen() == When.BEFORE ? -1 : 1); while (aDate.getDayOfWeek() != nExpectedWeekday) { aDate = aDate.plusDays(nDirection); }//www .j a v a 2 s . co m final IHolidayType aType = XMLUtil.getType(aRelativeToWeekdayInMonth.getLocalizedType()); final String sPropertyKey = aRelativeToWeekdayInMonth.getDescriptionPropertiesKey(); aHolidayMap.add(aDate, new ResourceBundleHoliday(aType, sPropertyKey)); } }
From source file:com.ideaspymes.arthyweb.ventas.web.controllers.ResumenMetasBean.java
public Integer getDaysBetweenIgnoreWeekends(org.joda.time.LocalDate startDate, org.joda.time.LocalDate endDate) { // If the start date is equal to the closing date, spent 0 days if (startDate.equals(endDate)) { return 0; }//from w w w . j a v a2 s . c o m // A number that represents the day for the start date, Monday = 1 , Tuesday = 2 , Wednesday = 3 ... int dayOfWeekStartDateNumber = startDate.getDayOfWeek(); // If the starting date is Saturday or Sunday , pretend to be Monday if (dayOfWeekStartDateNumber == 6 || dayOfWeekStartDateNumber == 7) { int DaysToAdd = 8 - dayOfWeekStartDateNumber; startDate = startDate.plusDays(DaysToAdd); dayOfWeekStartDateNumber = Integer.valueOf(startDate.dayOfWeek().getAsString()); } // How many days have passed counting weekends int days = Days.daysBetween(startDate, endDate).getDays(); // How many weeks have passed int weeks = days / 7; // Excess days left. E.g. one week and three days the excess will be 3 int excess = days % 7; // Excess of days spent for the weekend , then it must be removed two days // the final number of days if (excess + dayOfWeekStartDateNumber >= 6) { // Week count * 5 working days + excess days - the weekend that excess crossed return weeks * 5 + excess - 2; } // Weeks count * 5 working days + excess days return weeks * 5 + excess; }
From source file:com.index.IndexServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w.j a v a 2 s. c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("startdate") == null && request.getParameter("enddate") == null) { DateTime now = new DateTime(); LocalDate today = now.toLocalDate(); LocalDate tomorrow = today.plusDays(1); IndexData data = new IndexData(today.minusDays(7).toString(), tomorrow.toString(), "leadSession", request.getContextPath()); request.setAttribute("mostlyVisited", data.getMostlyVisited()); request.setAttribute("totalSessionCount", data.getTotalSessionCount()); request.setAttribute("totalAddressCount", data.getTotalAddressCount()); request.setAttribute("companyLinks", data.getCompanyLinks()); request.setAttribute("contacts", data.getContacts()); } if (request.getParameter("startdate") != null && request.getParameter("enddate") != null) { IndexData data = new IndexData(request.getParameter("startdate"), request.getParameter("enddate"), "leadSession", request.getContextPath()); request.setAttribute("mostlyVisited", data.getMostlyVisited()); request.setAttribute("totalSessionCount", data.getTotalSessionCount()); request.setAttribute("totalAddressCount", data.getTotalAddressCount()); request.setAttribute("companyLinks", data.getCompanyLinks()); request.setAttribute("contacts", data.getContacts()); } request.getRequestDispatcher("/index.jsp").forward(request, response); }
From source file:com.jjlharrison.jollyday.parser.AbstractHolidayParser.java
License:Apache License
/** * Moves the date using the FixedMoving information * * @param mc/*from w w w . j a v a2s. c o m*/ * @param fixed * @return */ private LocalDate moveDate(MovingCondition mc, LocalDate fixed) { int weekday = xmlUtil.getWeekday(mc.getWeekday()); int direction = (mc.getWith() == With.NEXT ? 1 : -1); while (fixed.getDayOfWeek() != weekday) { fixed = fixed.plusDays(direction); } return fixed; }
From source file:com.jjlharrison.jollyday.parser.impl.ChristianHolidayParser.java
License:Apache License
/** * {@inheritDoc}//from w w w. j a v a 2 s.c o m * * Parses all christian holidays relative to eastern. */ 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:com.jjlharrison.jollyday.parser.impl.FixedWeekdayBetweenFixedParser.java
License:Apache License
/** * {@inheritDoc}//from ww w. ja v a2 s. com * * Parses the provided configuration and creates holidays for the provided * year. */ public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (FixedWeekdayBetweenFixed fwm : config.getFixedWeekdayBetweenFixed()) { if (!isValid(fwm, year)) { continue; } LocalDate from = calendarUtil.create(year, fwm.getFrom()); LocalDate to = calendarUtil.create(year, fwm.getTo()); LocalDate result = null; for (; !from.isAfter(to);) { if (from.getDayOfWeek() == xmlUtil.getWeekday(fwm.getWeekday())) { result = from; break; } from = from.plusDays(1); } if (result != null) { HolidayType type = xmlUtil.getType(fwm.getLocalizedType()); holidays.add(new Holiday(result, fwm.getDescriptionPropertiesKey(), type)); } } }
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
private LocalDate moveNumberOfRequestedWeeks(FixedWeekdayInMonth fwm, LocalDate date) { switch (fwm.getWhich()) { case SECOND://from w w w . j ava 2 s .co m return date.plusDays(7); case THIRD: return date.plusDays(14); case FOURTH: return date.plusDays(21); default: return date; } }