DateTime dtOrg = new DateTime(dt); DateTime dtPlusOne = dtOrg.plusDays(1);
DateTime date = new DateTime().toDateMidnight().toDateTime(); DateTime tomorrow = date.plusDays(1);
DateTime today = new DateTime().withTimeAtStartOfDay(); DateTime tomorrow = today.plusDays(1).withTimeAtStartOfDay();
DateTime dateTime = new DateTime(date); dateTime = dateTime.plusDays(1);
/** * 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); }
@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; } }
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 );
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 )); }
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())); }
@Override public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input) { return input.rhs.getInterval().getStart().equals(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS + 2)); } }
@Override public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input) { return input.rhs.getInterval().getStart().isBefore(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS)); } }
@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); }
@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); } }
@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()))); }
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); }
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(); }
@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() ); }
@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))); }
@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))); }