List of usage examples for org.joda.time LocalDateTime plusWeeks
public LocalDateTime plusWeeks(int weeks)
From source file:com.axelor.apps.crm.service.EventService.java
License:Open Source License
@Transactional public void addRecurrentEventsByMonths(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate, int monthRepeatType) { Event lastEvent = event;//from w w w . ja v a 2 s . c o m if (monthRepeatType == 1) { int dayOfMonth = event.getStartDateTime().getDayOfMonth(); if (endType == 1) { int repeated = 0; while (repeated != repetitionsNumber) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth() .getMaximumValue() >= dayOfMonth) { copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity)); eventRepo.save(copy); repeated++; lastEvent = copy; } } } else { while (!lastEvent.getStartDateTime().plusMonths(periodicity).isAfter(endDate)) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); if (copy.getStartDateTime().plusMonths(periodicity).dayOfMonth() .getMaximumValue() >= dayOfMonth) { copy.setStartDateTime(copy.getStartDateTime().plusMonths(periodicity)); copy.setEndDateTime(copy.getEndDateTime().plusMonths(periodicity)); eventRepo.save(copy); lastEvent = copy; } } } } else { int dayOfWeek = event.getStartDateTime().getDayOfWeek(); int positionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { positionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { positionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (endType == 1) { int repeated = 0; while (repeated != repetitionsNumber) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); LocalDateTime nextDateTime = new LocalDateTime(copy.getStartDateTime()); nextDateTime.plusMonths(periodicity); int nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } int nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); repeated++; lastEvent = copy; } } else { LocalDateTime nextDateTime = new LocalDateTime(lastEvent.getStartDateTime()); nextDateTime.plusMonths(periodicity); int nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } int nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } while (!nextDateTime.isAfter(endDate)) { Event copy = eventRepo.copy(lastEvent, false); copy.setParentEvent(lastEvent); Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime()); copy.setStartDateTime(nextDateTime); copy.setEndDateTime(nextDateTime.plus(dur)); eventRepo.save(copy); lastEvent = copy; nextDateTime = new LocalDateTime(lastEvent.getStartDateTime()); nextDateTime.plusMonths(periodicity); nextDayOfWeek = nextDateTime.getDayOfWeek(); if (nextDayOfWeek > dayOfWeek) { nextDateTime.minusDays(nextDayOfWeek - dayOfWeek); } else { nextDateTime.plusDays(dayOfWeek - nextDayOfWeek); } nextPositionInMonth = 0; if (event.getStartDateTime().getDayOfMonth() % 7 == 0) { nextPositionInMonth = event.getStartDateTime().getDayOfMonth() / 7; } else { nextPositionInMonth = (event.getStartDateTime().getDayOfMonth() / 7) + 1; } if (nextPositionInMonth > positionInMonth) { nextDateTime.minusWeeks(nextPositionInMonth - positionInMonth); } else { nextDateTime.plusWeeks(positionInMonth - nextPositionInMonth); } } } } }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
/** * Calculates the current release date time. Adjusts for time zone effects on release time, e.g. * delays between time zones (e.g. in the United States) and DST. Adjusts for user-defined * offset./* w ww . ja va2 s . co m*/ * * @param time See {@link #getShowReleaseTime(int)}. * @return The date is today or on the next day matching the given week day. */ public static Date getShowReleaseDateTime(@NonNull Context context, @NonNull LocalTime time, int weekDay, @Nullable String timeZone, @Nullable String country) { // determine show time zone (falls back to America/New_York) DateTimeZone showTimeZone = getDateTimeZone(timeZone); // create current date in show time zone, set local show release time LocalDateTime localDateTime = new LocalDate(showTimeZone).toLocalDateTime(time); // adjust day of week so datetime is today or within the next week // for daily shows (weekDay == 0) just use the current day if (weekDay >= 1 && weekDay <= 7) { // joda tries to preserve week // so if we want a week day earlier in the week, advance by 7 days first if (weekDay < localDateTime.getDayOfWeek()) { localDateTime = localDateTime.plusWeeks(1); } localDateTime = localDateTime.withDayOfWeek(weekDay); } localDateTime = handleHourPastMidnight(country, localDateTime); localDateTime = handleDstGap(showTimeZone, localDateTime); DateTime dateTime = localDateTime.toDateTime(showTimeZone); // handle time zone effects on release time for US shows (only if device is set to US zone) String localTimeZone = TimeZone.getDefault().getID(); if (localTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) { dateTime = applyUnitedStatesCorrections(country, localTimeZone, dateTime); } dateTime = applyUserOffset(context, dateTime); return dateTime.toDate(); }
From source file:com.effektif.workflow.api.model.NextRelativeTime.java
License:Apache License
@Override public LocalDateTime resolve(LocalDateTime base) { LocalDateTime time = null; if (HOUR_OF_DAY.equals(indexUnit)) { time = base.withTime(index, 0, 0, 0); if (!time.isAfter(base)) { return time.plusDays(1); }//from w w w. j av a 2 s. c om } else if (DAY_OF_WEEK.equals(indexUnit)) { time = base.withDayOfWeek(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusWeeks(1); } } else if (DAY_OF_MONTH.equals(indexUnit)) { time = base.withDayOfMonth(index).withTime(0, 0, 0, 0); if (!time.isAfter(base)) { time = time.plusMonths(1); } } if (atHour != null) { time = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0); } return time; }
From source file:com.tasomaniac.muzei.tvshows.util.TimeTools.java
License:Apache License
/** * Calculates the current release date time. Adjusts for time zone effects on release time, e.g. * delays between time zones (e.g. in the United States) and DST. Adjusts for user-defined * offset./*from www. j a v a 2s . c om*/ * * @param time See {@link #getShowReleaseTime(int)}. * @return The date is today or on the next day matching the given week day. */ public static Date getShowReleaseDateTime(@NonNull Context context, @NonNull LocalTime time, int weekDay, @Nullable String timeZone, @Nullable String country) { // determine show time zone (falls back to America/New_York) DateTimeZone showTimeZone = getDateTimeZone(timeZone); // create current date in show time zone, set local show release time LocalDateTime localDateTime = new LocalDate(showTimeZone).toLocalDateTime(time); // adjust day of week so datetime is today or within the next week // for daily shows (weekDay == 0) just use the current day if (weekDay >= 1 && weekDay <= 7) { // joda tries to preserve week // so if we want a week day earlier in the week, advance by 7 days first if (weekDay < localDateTime.getDayOfWeek()) { localDateTime = localDateTime.plusWeeks(1); } localDateTime = localDateTime.withDayOfWeek(weekDay); } localDateTime = handleHourPastMidnight(country, localDateTime); localDateTime = handleDstGap(showTimeZone, localDateTime); DateTime dateTime = localDateTime.toDateTime(showTimeZone); // handle time zone effects on release time for US shows (only if device is set to US zone) String localTimeZone = TimeZone.getDefault().getID(); if (localTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) { dateTime = applyUnitedStatesCorrections(country, localTimeZone, dateTime); } return dateTime.toDate(); }
From source file:org.gnucash.android.model.Recurrence.java
License:Apache License
/** * Sets the end time of this recurrence by specifying the number of occurences * @param numberOfOccurences Number of occurences from the start time *///from w ww .ja v a 2 s . c o m public void setPeriodEnd(int numberOfOccurences) { LocalDateTime localDate = new LocalDateTime(mPeriodStart.getTime()); LocalDateTime endDate; int occurrenceDuration = numberOfOccurences * mPeriodType.getMultiplier(); switch (mPeriodType) { case DAY: endDate = localDate.plusDays(occurrenceDuration); break; case WEEK: endDate = localDate.plusWeeks(occurrenceDuration); break; default: case MONTH: endDate = localDate.plusMonths(occurrenceDuration); break; case YEAR: endDate = localDate.plusYears(occurrenceDuration); break; } mPeriodEnd = new Timestamp(endDate.toDateTime().getMillis()); }
From source file:view.popups.shift.ShiftManualPopup.java
public ArrayList<LocalDateTime> getTwelveMondays() { ArrayList<LocalDateTime> mondays = new ArrayList<>(); LocalDateTime monday;//w w w .j a v a2 s .c om //Denne her uges mandag LocalDateTime thisMonday = today.withDayOfWeek(DateTimeConstants.MONDAY); //Starter monday p denne her uges mandag monday = thisMonday; //En lkke der tller alle mandage op 12 uger frem og stter dem i arrayListen for (int i = 0; i < 13; i++) { mondays.add(monday); if (monday.isBefore(twelveWeeks)) { monday = thisMonday.plusWeeks(i); System.out.println(monday); } } return mondays; }