List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:de.jollyday.parser.impl.ChristianHolidayParser.java
License:Apache License
/** * {@inheritDoc}/* w w w. ja v a 2s. c om*/ * * 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.FixedWeekdayBetweenFixedParser.java
License:Apache License
/** * {@inheritDoc}/*from w ww .jav a2 s . 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 (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:de.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
private LocalDate moveNumberOfRequestedWeeks(FixedWeekdayInMonth fwm, LocalDate date) { switch (fwm.getWhich()) { case SECOND:// www. j av a 2 s.c o m date = date.plusDays(7); break; case THIRD: date = date.plusDays(14); break; case FOURTH: date = date.plusDays(21); } return date; }
From source file:de.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java
License:Apache License
/** * {@inheritDoc}//from w ww . j a va 2 s.co m * * 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 {// w ww. j ava2 s.co 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; }
From source file:de.jollyday.parser.impl.RelativeToEasterSundayParser.java
License:Apache License
/** * {@inheritDoc}/* w w w .j a v a 2 s.c o m*/ * * Parses relative to easter sunday holidays. */ @Override public void parse(int year, Set<Holiday> holidays, Holidays config) { for (RelativeToEasterSunday ch : config.getRelativeToEasterSunday()) { if (!isValid(ch, year)) { continue; } LocalDate easterSunday = getEasterSunday(year, ch.getChronology()); easterSunday.plusDays(ch.getDays()); String propertiesKey = PREFIX_PROPERTY_CHRISTIAN + ch.getDescriptionPropertiesKey(); addChrstianHoliday(easterSunday, propertiesKey, ch.getLocalizedType(), holidays); } }
From source file:de.jollyday.parser.impl.RelativeToFixedParser.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w w w .j av a 2 s .c o m*/ public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (RelativeToFixed rf : config.getRelativeToFixed()) { if (!isValid(rf, year)) { continue; } LocalDate fixed = calendarUtil.create(year, rf.getDate()); if (rf.getWeekday() != null) { // if weekday is set -> move to weekday int day = xmlUtil.getWeekday(rf.getWeekday()); int direction = (rf.getWhen() == When.BEFORE ? -1 : 1); do { fixed = fixed.plusDays(direction); } while (fixed.getDayOfWeek() != day); } else if (rf.getDays() != null) { // if number of days set -> move number of days fixed = fixed.plusDays(rf.getWhen() == When.BEFORE ? -rf.getDays() : rf.getDays()); } HolidayType type = xmlUtil.getType(rf.getLocalizedType()); holidays.add(new Holiday(fixed, rf.getDescriptionPropertiesKey(), type)); } }
From source file:de.symeda.sormas.api.utils.DateHelper.java
License:Open Source License
/** * requries joda-time/*from w w w .jav a 2s . c o m*/ * * <table> * <tr> * <td>90</td> * <td>-></td> * <td>[1/1/1990, 1/1/1991)</td> * </tr> * <tr> * <td>08</td> * <td>-></td> * <td>[1/1/2008, 1/1/2009)</td> * </tr> * <tr> * <td>1830</td> * <td>-></td> * <td>[1/1/1830, 1/1/1831)</td> * </tr> * <tr> * <td>3.01</td> * <td>-></td> * <td>[1/3/2001, 1/4/2001)</td> * </tr> * <tr> * <td>3.</td> * <td>-></td> * <td>[1/3/THIS_YEAR, 1/4/THIS_YEAR)</td> * </tr> * <tr> * <td>3.4.2012</td> * <td>-></td> * <td>[3/4/2012, 4/4/2012)</td> * </tr> * <tr> * <td>3.4.</td> * <td>-></td> * <td>[3/4/THIS_YEAR, 4/4/THIS_YEAR)</td> * </tr> * </table> * * @param name * @param value * @return */ public static Date[] findDateBounds(String value) { if (value == null || value.length() < 2) return null; int day = -1; int month = -1; int year = -1; Matcher matcher = COMPLETE_DATE_PATTERN.matcher(value); if (matcher.matches()) { day = Integer.parseInt(matcher.group(1)); month = Integer.parseInt(matcher.group(3)); year = Integer.parseInt(matcher.group(5)); } else { matcher = DAY_MONTH_DATE_PATTERN.matcher(value); if (matcher.matches()) { day = Integer.parseInt(matcher.group(1)); month = Integer.parseInt(matcher.group(3)); } else { matcher = MONTH_YEAR_DATE_PATTERN.matcher(value); if (matcher.matches()) { month = Integer.parseInt(matcher.group(1)); year = Integer.parseInt(matcher.group(3)); } else { matcher = MONTH_DATE_PATTERN.matcher(value); if (matcher.matches()) { month = Integer.parseInt(matcher.group(1)); } else { matcher = DAY_DATE_PATTERN.matcher(value); if (matcher.matches()) { day = Integer.parseInt(matcher.group(1)); } else { matcher = YEAR_DATE_PATTERN.matcher(value); if (matcher.matches()) { year = Integer.parseInt(matcher.group(1)); } else return null; } } } } } int thisYear = DateTime.now().year().get(); if (year == -1) { year = thisYear; } else if (year < 100) { int thisYearDigits = thisYear % 100; int thisCentury = thisYear - thisYearDigits; if (year < thisYearDigits + 20) year += thisCentury; else year += thisCentury - 100; } LocalDate start = new LocalDate(year, 1, 1); LocalDate end = new LocalDate(year, 1, 1); if (month == -1) end = end.plusMonths(11); else { start = start.plusMonths(month - 1); end = end.plusMonths(month - 1); } if (day == -1) { end = end.plusMonths(1); } else { start = start.plusDays(day - 1); end = end.plusDays(day); } return new Date[] { start.toDate(), end.toDate() }; }
From source file:eafit.cdei.asignacion.vo.Teacher.java
public void addCourseAvaliability(List<TimeDayLocation> pt) { DateTimeFormatter fmt = DateTimeFormat.forPattern("YY-MM-DDH:mm:ss"); LocalDate mondayDate = LocalDate.parse("2014-10-20"); meetTimeIntervals = new ArrayList<>(); for (TimeDayLocation tdl : pt) { String key = tdl.getDow().dayOfWeek().getAsText() + tdl.getTimeStartString() + tdl.getTimeEndString(); if (!mapCoursesAvaliability.containsKey(key)) { getMapCoursesAvaliability().put(key, tdl); getListAvaliability().add(tdl); for (int x = 0; x <= 6; x++) { LocalDate tmpStartDate = mondayDate.plusDays(x); String tmpDay = tmpStartDate.toString("EEEE"); if (tmpStartDate.dayOfWeek().equals(tdl.getDow().dayOfWeek())) { DateTime tmpStartDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + tdl.getTimeStart().toString("H:mm:ss"), fmt); DateTime tmpStopDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + tdl.getTimeEnd().toString("H:mm:ss"), fmt); meetTimeIntervals.add(new Interval(tmpStartDateTime, tmpStopDateTime)); }// ww w .j a v a 2s. c o m } } } }
From source file:eafit.cdei.util.IntervalGenerator.java
public static List<Interval> getIntervals(List<String> days, Time startTime, Time stopTime) { DateTimeFormatter fmt = DateTimeFormat.forPattern("YY-MM-DDH:mm:ss"); List<Interval> tmpMeetTimeIntervals = new ArrayList<Interval>(); LocalDate mondayDate = LocalDate.parse("2014-10-20"); for (int x = 0; x <= 5; x++) { LocalDate tmpStartDate = mondayDate.plusDays(x); String tmpDay = tmpStartDate.toString("EEEE"); if (days.contains(tmpDay)) { DateTime tmpStartDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + LocalTime.fromDateFields(startTime).toString("H:mm:ss"), fmt);/*from w ww.java2 s. c o m*/ DateTime tmpStopDateTime = DateTime.parse( tmpStartDate.toString("YY-MM-DD") + LocalTime.fromDateFields(stopTime).toString("H:mm:ss"), fmt); tmpMeetTimeIntervals.add(new Interval(tmpStartDateTime, tmpStopDateTime)); } } return tmpMeetTimeIntervals; }