Java Code Examples for java.time.LocalDate#plusWeeks()
The following examples show how to use
java.time.LocalDate#plusWeeks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelativeDate.java From baleen with Apache License 2.0 | 6 votes |
private void createRelativeWeek( TextBlock block, Integer charBegin, Integer charEnd, Integer weekOffset) { Temporal t = new Temporal(block.getJCas()); block.setBeginAndEnd(t, charBegin, charEnd); t.setConfidence(1.0); t.setPrecision(PRECISION_RELATIVE); t.setScope(SCOPE_SINGLE); t.setTemporalType(TYPE_DATE); if (relativeTo != null && weekOffset != null) { LocalDate startOfWeek = relativeTo.plusWeeks(weekOffset); while (startOfWeek.getDayOfWeek() != DayOfWeek.MONDAY) { startOfWeek = startOfWeek.minusDays(1); } t.setTimestampStart(startOfWeek.atStartOfDay(ZoneOffset.UTC).toEpochSecond()); LocalDate endOfWeek = startOfWeek.plusWeeks(1); t.setTimestampStop(endOfWeek.atStartOfDay(ZoneOffset.UTC).toEpochSecond()); } addToJCasIndex(t); }
Example 2
Source File: TargetService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public LocalDate getNextDate(int periodTypeSelect, LocalDate date) { switch (periodTypeSelect) { case TargetConfigurationRepository.PERIOD_TYPE_NONE: return date; case TargetConfigurationRepository.PERIOD_TYPE_MONTHLY: return date.plusMonths(1); case TargetConfigurationRepository.PERIOD_TYPE_WEEKLY: return date.plusWeeks(1); case TargetConfigurationRepository.PERIOD_TYPE_DAILY: return date.plusDays(1); default: return date; } }
Example 3
Source File: DataTableBasic.java From finmath-lib with Apache License 2.0 | 6 votes |
private LocalDate dateFromOffset(final LocalDate startDate, final int offset) { LocalDate date = null; switch(convention) { case YEARS: date = startDate.plusYears(offset); break; case MONTHS: date = startDate.plusMonths(offset); break; case DAYS: date = startDate.plusDays(offset); break; case WEEKS: date = startDate.plusWeeks(offset); break; default: throw new IllegalArgumentException("Unknown convention " + convention + "."); } return date; }
Example 4
Source File: DataTableBasic.java From finmath-lib with Apache License 2.0 | 6 votes |
private LocalDate dateFromOffset(final LocalDate startDate, final int offset) { LocalDate date = null; switch(convention) { case YEARS: date = startDate.plusYears(offset); break; case MONTHS: date = startDate.plusMonths(offset); break; case DAYS: date = startDate.plusDays(offset); break; case WEEKS: date = startDate.plusWeeks(offset); break; default: throw new IllegalArgumentException("Unknown convention " + convention + "."); } return date; }
Example 5
Source File: DateTest.java From java-master with Apache License 2.0 | 5 votes |
@Test public void test3() { LocalDate date1 = LocalDate.of(2014, 3, 18); LocalDate date2 = date1.withYear(2011); LocalDate date3 = date2.withDayOfMonth(25); LocalDate date4 = date3.with(ChronoField.MONTH_OF_YEAR, 9); // 以相对方式创建LocalDate对象修改版 date1 = LocalDate.of(2014, 3, 18); date2 = date1.plusWeeks(1); date3 = date2.minusYears(3); date4 = date3.plus(6, ChronoUnit.MONTHS); }
Example 6
Source File: Meetup.java From java with MIT License | 5 votes |
LocalDate day(DayOfWeek dayOfWeek, MeetupSchedule schedule) { LocalDate current = cycleToNext(dayOfWeek, startOfMonth); switch (schedule) { case FIRST: break; case SECOND: current = current.plusWeeks(1); break; case THIRD: current = current.plusWeeks(2); break; case FOURTH: current = current.plusWeeks(3); break; case TEENTH: while (current.getDayOfMonth() < 13) { current = current.plusWeeks(1); } break; case LAST: current = cycleToPrev(dayOfWeek, startOfMonth.plusMonths(1).minusDays(1)); break; default: return null; } return current; }
Example 7
Source File: ScheduleGenerator.java From finmath-lib with Apache License 2.0 | 4 votes |
/** * ScheduleFromPeriods generation with futureCodes (in the format DEC17). Futures are assumed to expire on the third wednesday in the respective month. * * @param referenceDate The date which is used in the schedule to internally convert dates to doubles, i.e., the date where t=0. * @param futureCode Future code in the format DEC17 * @param startOffsetString The start date as an offset from the spotDate (build from tradeDate and spotOffsetDays) entered as a code like 1D, 1W, 1M, 2M, 3M, 1Y, etc. * @param maturityString The end date of the last period entered as a code like 1D, 1W, 1M, 2M, 3M, 1Y, etc. * @param frequency The frequency (as String). * @param daycountConvention The daycount convention (as String). * @param shortPeriodConvention If short period exists, have it first or last (as String). * @param dateRollConvention Adjustment to be applied to the all dates (as String). * @param businessdayCalendar Business day calendar (holiday calendar) to be used for date roll adjustment. * @param fixingOffsetDays Number of business days to be added to period start to get the fixing date. * @param paymentOffsetDays Number of business days to be added to period end to get the payment date. * @return The corresponding schedule */ public static Schedule createScheduleFromConventions( final LocalDate referenceDate, final String futureCode, final String startOffsetString, final String maturityString, final String frequency, final String daycountConvention, final String shortPeriodConvention, final String dateRollConvention, final BusinessdayCalendar businessdayCalendar, final int fixingOffsetDays, final int paymentOffsetDays ) { final int futureExpiryYearsShort = Integer.parseInt(futureCode.substring(futureCode.length()-2)); final String futureExpiryMonthsString = futureCode.substring(0,futureCode.length()-2); final DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("dd/MMM/yy").toFormatter(Locale.ENGLISH); final String futureExpiryString = "01/" + futureExpiryMonthsString + "/" + futureExpiryYearsShort; LocalDate futureExpiryDate; try{ futureExpiryDate = LocalDate.parse(futureExpiryString, formatter); } catch(final DateTimeParseException e) { throw new IllegalArgumentException("Error when parsing futureCode " + futureCode + ". Must be of format MMMYY with english month format (e.g. DEC17)"); } // get third wednesday in month, adjust with following if no busday while(!futureExpiryDate.getDayOfWeek().equals(DayOfWeek.WEDNESDAY)) { futureExpiryDate = futureExpiryDate.plusDays(1); } futureExpiryDate = futureExpiryDate.plusWeeks(2); futureExpiryDate = businessdayCalendar.getAdjustedDate(futureExpiryDate, startOffsetString, DateRollConvention.FOLLOWING); // adjust to the next good busday final LocalDate maturityDate = businessdayCalendar.getDateFromDateAndOffsetCode(futureExpiryDate, maturityString); return createScheduleFromConventions( referenceDate, futureExpiryDate, maturityDate, Frequency.valueOf(frequency.replace("/", "_").toUpperCase()), DaycountConvention.getEnum(daycountConvention), ShortPeriodConvention.valueOf(shortPeriodConvention.replace("/", "_").toUpperCase()), DateRollConvention.getEnum(dateRollConvention), businessdayCalendar, fixingOffsetDays, paymentOffsetDays ); }
Example 8
Source File: ScheduleGenerator.java From finmath-lib with Apache License 2.0 | 4 votes |
/** * ScheduleFromPeriods generation with futureCodes (in the format DEC17). Futures are assumed to expire on the third wednesday in the respective month. * * @param referenceDate The date which is used in the schedule to internally convert dates to doubles, i.e., the date where t=0. * @param futureCode Future code in the format DEC17 * @param startOffsetString The start date as an offset from the spotDate (build from tradeDate and spotOffsetDays) entered as a code like 1D, 1W, 1M, 2M, 3M, 1Y, etc. * @param maturityString The end date of the last period entered as a code like 1D, 1W, 1M, 2M, 3M, 1Y, etc. * @param frequency The frequency (as String). * @param daycountConvention The daycount convention (as String). * @param shortPeriodConvention If short period exists, have it first or last (as String). * @param dateRollConvention Adjustment to be applied to the all dates (as String). * @param businessdayCalendar Business day calendar (holiday calendar) to be used for date roll adjustment. * @param fixingOffsetDays Number of business days to be added to period start to get the fixing date. * @param paymentOffsetDays Number of business days to be added to period end to get the payment date. * @return The corresponding schedule */ public static Schedule createScheduleFromConventions( final LocalDate referenceDate, final String futureCode, final String startOffsetString, final String maturityString, final String frequency, final String daycountConvention, final String shortPeriodConvention, final String dateRollConvention, final BusinessdayCalendar businessdayCalendar, final int fixingOffsetDays, final int paymentOffsetDays ) { final int futureExpiryYearsShort = Integer.parseInt(futureCode.substring(futureCode.length()-2)); final String futureExpiryMonthsString = futureCode.substring(0,futureCode.length()-2); final DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("dd/MMM/yy").toFormatter(Locale.ENGLISH); final String futureExpiryString = "01/" + futureExpiryMonthsString + "/" + futureExpiryYearsShort; LocalDate futureExpiryDate; try{ futureExpiryDate = LocalDate.parse(futureExpiryString, formatter); } catch(final DateTimeParseException e) { throw new IllegalArgumentException("Error when parsing futureCode " + futureCode + ". Must be of format MMMYY with english month format (e.g. DEC17)"); } // get third wednesday in month, adjust with following if no busday while(!futureExpiryDate.getDayOfWeek().equals(DayOfWeek.WEDNESDAY)) { futureExpiryDate = futureExpiryDate.plusDays(1); } futureExpiryDate = futureExpiryDate.plusWeeks(2); futureExpiryDate = businessdayCalendar.getAdjustedDate(futureExpiryDate, startOffsetString, DateRollConvention.FOLLOWING); // adjust to the next good busday final LocalDate maturityDate = businessdayCalendar.getDateFromDateAndOffsetCode(futureExpiryDate, maturityString); return createScheduleFromConventions( referenceDate, futureExpiryDate, maturityDate, Frequency.valueOf(frequency.replace("/", "_").toUpperCase()), DaycountConvention.getEnum(daycountConvention), ShortPeriodConvention.valueOf(shortPeriodConvention.replace("/", "_").toUpperCase()), DateRollConvention.getEnum(dateRollConvention), businessdayCalendar, fixingOffsetDays, paymentOffsetDays ); }