org.joda.time.LocalDate.plusWeeks()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.joda.time.LocalDate.plusWeeks()方法的一些代码示例,展示了LocalDate.plusWeeks()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.plusWeeks()方法的具体详情如下:
包路径:org.joda.time.LocalDate
类名称:LocalDate
方法名:plusWeeks

LocalDate.plusWeeks介绍

[英]Returns a copy of this date plus the specified number of weeks.

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

LocalDate added = dt.plusWeeks(6); 
LocalDate added = dt.plus(Period.weeks(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.weeks(), 6);

[中]返回此日期加上指定周数的副本。
此LocalDate实例是不可变的,不受此方法调用的影响。
以下三行实际上是相同的:

LocalDate added = dt.plusWeeks(6); 
LocalDate added = dt.plus(Period.weeks(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.weeks(), 6);

代码示例

代码示例来源:origin: killbill/killbill

@Override
public LocalDate addToLocalDate(final LocalDate localDate) {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new IllegalStateException("Unexpected duration unit " + unit);
  }
}

代码示例来源:origin: killbill/killbill

@Override
public LocalDate addToLocalDate(final LocalDate localDate) throws CatalogApiException {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new CatalogApiException(ErrorCode.CAT_UNDEFINED_DURATION, unit);
  }
}

代码示例来源:origin: yannecer/NCalendar

@Override
protected LocalDate getDate(LocalDate localDate, int count) {
  return localDate.plusWeeks(count);
}

代码示例来源:origin: yannecer/NCalendar

@Override
protected LocalDate getLastSelectDate(LocalDate currectSelectDate) {
  return currectSelectDate.plusWeeks(-1);
}

代码示例来源:origin: yannecer/NCalendar

@Override
protected LocalDate getNextSelectDate(LocalDate currectSelectDate) {
  return currectSelectDate.plusWeeks(1);
}

代码示例来源:origin: nl.cloudfarming.client/calendar-api

public static LocalDate nextWeek(LocalDate actual) {
  return actual.plusWeeks(1);
}

代码示例来源:origin: fluxtream/fluxtream-app

public int getWeek() {
  if (timeUnit != TimeUnit.WEEK)
    throw new IllegalStateException("Unexpected check for week when not using week time unit");
  // Off by 1 because getBeginningOfWeek(year, week), and by extension
  // setWeek(year, week) goes back by 1 week
  return fromDate.plusWeeks(1).getWeekOfWeekyear();
}

代码示例来源:origin: fluxtream/fluxtream-app

public int getWeekYear() {
  if (timeUnit != TimeUnit.WEEK)
    throw new IllegalStateException("Unexpected check for week year when not using week time unit");
  // Off by 1 because getBeginningOfWeek(year, week), and by extension
  // setWeek(year, week) goes back by 1 week
  return fromDate.plusWeeks(1).getWeekyear();
}

代码示例来源:origin: fluxtream/fluxtream-app

public TreeSet<String> getDatesForWeek(final int year, final int week) {
  LocalDate weekDay = TimeUtils.getBeginningOfWeek(year, week);
  final LocalDate nextWeekStart = weekDay.plusWeeks(1);
  TreeSet<String> dates = new TreeSet<String>();
  while(weekDay.isBefore(nextWeekStart)) {
    final String date = TimeUtils.dateFormatterUTC.print(weekDay);
    dates.add(date);
    weekDay = weekDay.plusDays(1);
  }
  return dates;
}

代码示例来源:origin: net.objectlab.kit/datecalc-joda

/**
 * Assumes that the month is correct, get the day for the 2rd wednesday.
 *
 * @param original
 *            the start date
 * @return the 3rd Wednesday of the month
 */
private LocalDate calculate3rdWednesday(final LocalDate original) {
  final LocalDate firstOfMonth = original.withDayOfMonth(1);
  LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
  if (firstWed.isBefore(firstOfMonth)) {
    firstWed = firstWed.plusWeeks(1);
  }
  return firstWed.plusWeeks(2);
}

代码示例来源:origin: Appendium/objectlabkit

/**
 * Assumes that the month is correct, get the day for the 2rd wednesday.
 *
 * @param original
 *            the start date
 * @return the 3rd Wednesday of the month
 */
private LocalDate calculate3rdWednesday(final LocalDate original) {
  final LocalDate firstOfMonth = original.withDayOfMonth(1);
  LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
  if (firstWed.isBefore(firstOfMonth)) {
    firstWed = firstWed.plusWeeks(1);
  }
  return firstWed.plusWeeks(2);
}

代码示例来源:origin: org.kill-bill.billing/killbill-overdue

@Override
public LocalDate addToLocalDate(final LocalDate localDate) {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new IllegalStateException("Unexpected duration unit " + unit);
  }
}

代码示例来源:origin: fluxtream/fluxtream-app

/**
 * Returns one past the end date.
 *
 * This is similar to the behavior of Python's range function or Java's String.substring method,
 * and it has the desirable property that the number of milliseconds between midnight on
 * getToDate() and midnight on fromDate is equal to the number of milliseconds in a day times
 * the number of days in the range described by TimeUnit (assuming there is no time zone change,
 * leap second, or daylight savings time start/end in the middle).
 */
private LocalDate getToDate() {
  switch (timeUnit) {
    case DAY:
      return fromDate.plusDays(1);
    case WEEK:
      return fromDate.plusWeeks(1);
    case MONTH:
      return fromDate.plusMonths(1);
    case YEAR:
      return fromDate.plusYears(1);
  }
  throw new UnsupportedOperationException("Unexpected TimeUnit value");
}

代码示例来源:origin: ManyDesigns/Portofino

public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) {
  logger.debug("Initializing month");
  this.referenceDateTime = referenceDateTime;
  logger.debug("Reference date time: {}", referenceDateTime);
  this.firstDayOfWeek = firstDayOfWeek;
  logger.debug("First day of week: {}", firstDayOfWeek);
  referenceDateMidnight = new LocalDate(referenceDateTime);
  referenceYear = referenceDateTime.getYear();
  referenceMonth = referenceDateTime.getMonthOfYear();
  monthStart = referenceDateMidnight.withDayOfMonth(1);
  monthEnd = monthStart.plusMonths(1);
  monthInterval = new Interval(monthStart.toDateTimeAtStartOfDay(), monthEnd.toDateTimeAtStartOfDay());
  monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek);
  monthViewEnd = monthViewStart.plusWeeks(6);
  monthViewInterval = new Interval(monthViewStart.toDateTimeAtStartOfDay(), monthViewEnd.toDateTimeAtStartOfDay());
  logger.debug("Month view start: {}", monthViewStart);
  logger.debug("Initializing weeks");
  weeks = createWeeksArray(6);
  LocalDate weekStart = monthViewStart;
  for (int i = 0; i < weeks.length; i++) {
    LocalDate weekEnd = weekStart.plusWeeks(1);
    weeks[i] = createWeek(weekStart, weekEnd);
    weekStart = weekEnd;
  }
}

代码示例来源:origin: fluxtream/fluxtream-app

public void incrementTimespan() {
  switch (timeUnit) {
    case DAY:
      fromDate = fromDate.plusDays(1);
      break;
    case WEEK:
      fromDate = fromDate.plusWeeks(1);
      break;
    case MONTH:
      fromDate = fromDate.plusMonths(1);
      break;
    case YEAR:
      fromDate = fromDate.plusYears(1);
      break;
  }
}

代码示例来源:origin: com.manydesigns/portofino-calendar

public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) {
  logger.debug("Initializing month");
  this.referenceDateTime = referenceDateTime;
  logger.debug("Reference date time: {}", referenceDateTime);
  this.firstDayOfWeek = firstDayOfWeek;
  logger.debug("First day of week: {}", firstDayOfWeek);
  referenceDateMidnight = new LocalDate(referenceDateTime);
  referenceYear = referenceDateTime.getYear();
  referenceMonth = referenceDateTime.getMonthOfYear();
  monthStart = referenceDateMidnight.withDayOfMonth(1);
  monthEnd = monthStart.plusMonths(1);
  monthInterval = new Interval(monthStart.toDateTimeAtStartOfDay(), monthEnd.toDateTimeAtStartOfDay());
  monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek);
  monthViewEnd = monthViewStart.plusWeeks(6);
  monthViewInterval = new Interval(monthViewStart.toDateTimeAtStartOfDay(), monthViewEnd.toDateTimeAtStartOfDay());
  logger.debug("Month view start: {}", monthViewStart);
  logger.debug("Initializing weeks");
  weeks = createWeeksArray(6);
  LocalDate weekStart = monthViewStart;
  for (int i = 0; i < weeks.length; i++) {
    LocalDate weekEnd = weekStart.plusWeeks(1);
    weeks[i] = createWeek(weekStart, weekEnd);
    weekStart = weekEnd;
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-catalog

@Override
public LocalDate addToLocalDate(final LocalDate localDate) throws CatalogApiException {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new CatalogApiException(ErrorCode.CAT_UNDEFINED_DURATION, unit);
  }
}

相关文章