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

x33g5p2x  于2022-01-17 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(690)

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

DateTime.plusDays介绍

[英]Returns a copy of this datetime plus the specified number of days.

The calculation will do its best to only change the day field retaining the same time of day. However, in certain circumstances, typically daylight savings cutover, it may be necessary to alter the time fields.

In spring an hour is typically removed. If adding one day results in the time being within the cutover then the time is adjusted to be within summer time. For example, if the cutover is from 01:59 to 03:00 and the result of this method would have been 02:30, then the result will be adjusted to 03:30.

The following three lines are identical in effect:

DateTime added = dt.plusDays(6); 
DateTime added = dt.plus(Period.days(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.days(), 6);

This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime加上指定天数的副本。
计算将尽最大努力只更改保留当天相同时间的day字段。但是,在某些情况下,通常是夏令时切换,可能需要更改时间字段。
在春天,一个小时通常被取消。如果增加一天导致时间在切换范围内,则将时间调整为在夏季时间内。例如,如果切换时间为01:59到03:00,且此方法的结果为02:30,则结果将调整为03:30。
以下三行实际上是相同的:

DateTime added = dt.plusDays(6); 
DateTime added = dt.plus(Period.days(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.days(), 6);

此datetime实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: stackoverflow.com

DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);

代码示例来源:origin: stackoverflow.com

DateTime date = new DateTime().toDateMidnight().toDateTime();
DateTime tomorrow = date.plusDays(1);

代码示例来源:origin: stackoverflow.com

DateTime today = new DateTime().withTimeAtStartOfDay();
DateTime tomorrow = today.plusDays(1).withTimeAtStartOfDay();

代码示例来源:origin: stackoverflow.com

DateTime dateTime = new DateTime(date);
dateTime = dateTime.plusDays(1);

代码示例来源:origin: apache/incubator-druid

/**
 * The inverse of {@link #jodaToCalciteDate(DateTime, DateTimeZone)}.
 *
 * @param date     Calcite style date
 * @param timeZone session time zone
 *
 * @return joda timestamp, with time zone set to the session time zone
 */
public static DateTime calciteDateToJoda(final int date, final DateTimeZone timeZone)
{
 return DateTimes.EPOCH.plusDays(date).withZoneRetainFields(timeZone);
}

代码示例来源:origin: apache/incubator-druid

@Override
 public ScheduledExecutors.Signal call()
 {
  try {
   synchronized (lock) {
    currentDay = currentDay.plusDays(1);
    CloseQuietly.close(fileWriter);
    fileWriter = getFileWriter();
   }
  }
  catch (Exception e) {
   Throwables.propagate(e);
  }
  return ScheduledExecutors.Signal.REPEAT;
 }
}

代码示例来源:origin: stackoverflow.com

DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" );
DateTime now = DateTime.now( timeZone );
DateTime todayStart = now.withTimeAtStartOfDay();
DateTime tomorrowStart = now.plusDays( 1 ).withTimeAtStartOfDay();
Interval today = new Interval( todayStart, tomorrowStart );

代码示例来源:origin: apache/incubator-druid

private static Stream getStreamOfEvents()
{
 return IntStream.range(0, MAX_ROWS).mapToObj(i -> ImmutableMap.of(
   TIME_COLUMN, DateTimes.of("2011-01-13T00:00:00.000Z").plusDays(i).getMillis(),
   DIM_NAME, DIM_VALUE,
   DIM_FLOAT_NAME, i / 1.6179775280898876
 ));
}

代码示例来源:origin: apache/incubator-gobblin

public List<? extends ProducerJob> partitionJobs() {
 DateTime start = dateFormatter.parseDateTime(getStartDate());
 DateTime end = dateFormatter.parseDateTime(getEndDate());
 int days = Days.daysBetween(start, end).getDays();
 if (days <= 0) {
  return new ArrayList<>();
 }
 int step = days / 2;
 return Arrays.asList(new SimpleProducerJob(getPage(), getStartDate(), dateFormatter.print(start.plusDays(step))),
   new SimpleProducerJob(getPage(), dateFormatter.print(start.plusDays(step + 1)), getEndDate()));
}

代码示例来源:origin: apache/incubator-druid

@Override
 public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input)
 {
  return input.rhs.getInterval().getStart().equals(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS + 2));
 }
}

代码示例来源:origin: apache/incubator-druid

@Override
 public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input)
 {
  return input.rhs.getInterval().getStart().isBefore(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS));
 }
}

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

@Test(groups = "fast")
public void testEventsForCancelledSubscriptionBeforeTransfer() throws Exception {
  final DateTime subscriptionStartTime = clock.getUTCNow();
  final DateTime subscriptionCancelTime = subscriptionStartTime.plusDays(1);
  final ImmutableList<ExistingEvent> existingEvents = ImmutableList.<ExistingEvent>of(createEvent(subscriptionStartTime, SubscriptionBaseTransitionType.CREATE),
                                            createEvent(subscriptionCancelTime, SubscriptionBaseTransitionType.CANCEL));
  final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
  final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
  final DateTime transferDate = subscriptionStartTime.plusDays(10);
  final List<SubscriptionBaseEvent> events = transferApi.toEvents(existingEvents, subscription, transferDate, catalog, internalCallContext);
  Assert.assertEquals(events.size(), 0);
}

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

@Test(groups = "fast")
  public void testDataCalc() {
    final DefaultPlan p0 = MockPlan.createBicycleTrialEvergreen1USD();

    final DefaultPlan p1 = MockPlan.createBicycleTrialEvergreen1USD(100);

    final DefaultPlan p2 = MockPlan.createBicycleNoTrialEvergreen1USD();

    final DateTime requestedDate = new DateTime();
    Assert.assertEquals(p0.dateOfFirstRecurringNonZeroCharge(requestedDate, null).compareTo(requestedDate.plusDays(30)), 0);
    Assert.assertEquals(p1.dateOfFirstRecurringNonZeroCharge(requestedDate, null).compareTo(requestedDate.plusDays(100)), 0);
    Assert.assertEquals(p2.dateOfFirstRecurringNonZeroCharge(requestedDate, null).compareTo(requestedDate.plusDays(0)), 0);
  }
}

代码示例来源:origin: apache/incubator-druid

private DataSegment makeSegment(int offset)
{
 return DataSegment.builder()
          .dataSource("foo")
          .interval(
            new Interval(
              SEGMENT_INTERVAL_START.plusDays(offset),
              SEGMENT_INTERVAL_START.plusDays(offset + 1)
            )
          )
          .version(DateTimes.nowUtc().toString())
          .build();
}

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

@Test public void shouldReturnDateForLatestTransition() throws Exception {
  JobInstance instance = JobInstanceMother.scheduled("jobConfig1");
  instance.setClock(timeProvider);
  when(timeProvider.currentTime()).thenReturn(new DateTime().plusDays(1).toDate());
  instance.completing(JobResult.Passed);
  assertThat(instance.latestTransitionDate(),is(greaterThan(instance.getScheduledDate())));
}

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

private void insertOverdueCheckAndVerifyQueueContent(final Account account, final int nbDaysInFuture, final int expectedNbDaysInFuture) throws IOException {
  final DateTime futureNotificationTime = testReferenceTime.plusDays(nbDaysInFuture);
  final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(account.getId());
  checkPoster.insertOverdueNotification(account.getId(), futureNotificationTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext);
  final List<NotificationEventWithMetadata<OverdueCheckNotificationKey>> notificationsForKey = getNotificationsForOverdueable(account);
  Assert.assertEquals(notificationsForKey.size(), 1);
  final NotificationEventWithMetadata nm = notificationsForKey.get(0);
  Assert.assertEquals(nm.getEvent(), notificationKey);
  Assert.assertEquals(nm.getEffectiveDate().compareTo(testReferenceTime.plusDays(expectedNbDaysInFuture)), 0);
}

代码示例来源:origin: apache/incubator-druid

private DataSegment makeSegment(int offset)
{
 return DataSegment.builder()
          .dataSource("foo")
          .interval(
            new Interval(
              DateTimes.of("2013-01-01").plusDays(offset),
              DateTimes.of("2013-01-02").plusDays(offset)
            )
          )
          .version(DateTimes.nowUtc().toString())
          .dimensions(ImmutableList.of("dim1", "dim2"))
          .metrics(ImmutableList.of("met1", "met2"))
          .loadSpec(ImmutableMap.of("type", "local"))
          .build();
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testUsedOutOfBoundsHigh() throws IOException
{
 coordinator.announceHistoricalSegments(SEGMENTS);
 Assert.assertTrue(
   coordinator.getUsedSegmentsForInterval(
     defaultSegment.getDataSource(),
     new Interval(defaultSegment.getInterval().getEnd(), defaultSegment.getInterval().getEnd().plusDays(10))
   ).isEmpty()
 );
}

代码示例来源:origin: prestodb/presto

@Test
public void testAddFieldToDate()
{
  assertFunction("date_add('day', 0, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE));
  assertFunction("date_add('day', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusDays(3)));
  assertFunction("date_add('week', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + DATE_LITERAL + ")", DateType.DATE, toDate(DATE.plusYears(3)));
}

代码示例来源:origin: prestodb/presto

@Test
public void testAddFieldToTimestamp()
{
  assertFunction("date_add('millisecond', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMillis(3), session));
  assertFunction("date_add('second', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusSeconds(3), session));
  assertFunction("date_add('minute', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMinutes(3), session));
  assertFunction("date_add('hour', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(3), session));
  assertFunction("date_add('hour', 23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(23), session));
  assertFunction("date_add('hour', -4, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(4), session));
  assertFunction("date_add('hour', -23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(23), session));
  assertFunction("date_add('day', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusDays(3), session));
  assertFunction("date_add('week', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusWeeks(3), session));
  assertFunction("date_add('month', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3), session));
  assertFunction("date_add('quarter', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3 * 3), session));
  assertFunction("date_add('year', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusYears(3), session));
  assertFunction("date_add('millisecond', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMillis(3)));
  assertFunction("date_add('second', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusSeconds(3)));
  assertFunction("date_add('minute', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMinutes(3)));
  assertFunction("date_add('hour', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusHours(3)));
  assertFunction("date_add('day', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusDays(3)));
  assertFunction("date_add('week', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusYears(3)));
}

相关文章

DateTime类方法