DateTime now = DateTime.now(); DateTime dateTime = now.plusMinutes(10); Seconds seconds = Seconds.secondsBetween(now, dateTime); System.out.println(seconds.getSeconds());
private Date getDefaultExpirationDate() { return new DateTime(clock.currentTimeMillis()) .plusMinutes(SYNTHESIZE_SPEECH_DEFAULT_EXPIRATION_MINUTES) .toDate(); }
private Date getExpirationDate() { return new DateTime(clock.currentTimeMillis()).plusMinutes(DEFAULT_EXPIRATION_IN_MINUTES).toDate(); }
@Override public boolean shouldDeleteSnapshot(FileStatus snapshot, Trash trash) { DateTime snapshotTime = Trash.TRASH_SNAPSHOT_NAME_FORMATTER.parseDateTime(snapshot.getPath().getName()); return snapshotTime.plusMinutes(this.retentionMinutes).isBeforeNow(); } }
private void sampleDateTime() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Now: " + now); text.add("Now + 30 minutes: " + now.plusMinutes(30)); text.add("Now + 5 hours: " + now.plusHours(5)); text.add("Now + 2 days: " + now.plusDays(2)); addSample("DateTime", text); }
private DateTime roundDate(final DateTime dateTime, final int minutes) { if (minutes < 1 || 60 % minutes != 0) { throw new IllegalArgumentException("minutes must be a factor of 60"); } final DateTime hour = dateTime.hourOfDay().roundFloorCopy(); final long millisSinceHour = new Duration(hour, dateTime).getMillis(); final int roundedMinutes = ((int)Math.round( millisSinceHour / 60000.0 / minutes)) * minutes; return hour.plusMinutes(roundedMinutes); }
private void sampleDateRange() { List<String> text = new ArrayList<String>(); DateTime start = DateTime.now(); DateTime end = start.plusMinutes(30).plusHours(2).plusDays(56); text.add("Range: " + DateUtils.formatDateRange(this, start, end, 0)); text.add("Range (with year): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_YEAR)); text.add("Range (abbreviated): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_ABBREV_ALL)); text.add("Range (with time): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_TIME)); addSample("DateUtils.formatDateRange()", text); }
private void sampleGetRelativeTimeSpanString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25))); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5))); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3))); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25))); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5))); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3))); addSample("DateUtils.getRelativeTimeSpanString()", text); }
private void sampleGetRelativeDateTimeString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeDateTimeString(this, now.plusMinutes(25), null, 0)); text.add("Medium future: " + DateUtils.getRelativeDateTimeString(this, now.plusHours(5), null, 0)); text.add("Long future: " + DateUtils.getRelativeDateTimeString(this, now.plusDays(3), null, 0)); text.add("Short past: " + DateUtils.getRelativeDateTimeString(this, now.minusMinutes(25), null, 0)); text.add("Medium past: " + DateUtils.getRelativeDateTimeString(this, now.minusHours(5), null, 0)); text.add("Long past: " + DateUtils.getRelativeDateTimeString(this, now.minusDays(3), null, 0)); addSample("DateUtils.getRelativeDateTimeString()", text); }
private void sampleGetRelativeTimeSpanStringWithPreposition() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true)); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true)); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true)); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true)); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true)); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true)); addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text); }
break; case MINUTES: ret = new org.joda.time.Duration(dt, dt.plusMinutes((int) sampling.getValue())).getMillis(); break; case SECONDS:
/** * Test metric reporting methods, including InMemoryMetricEmitter methods */ @Test public void managerEmitterHandlingTest() throws Exception { // metrics use System.currentTimeMillis, so that method should be the millis provider final DateTime aboutNow = new DateTime(System.currentTimeMillis()); this.emitter.purgeAllData(); final Date from = aboutNow.minusMinutes(1).toDate(); this.metric.notifyManager(); this.emitterWrapper.countDownLatch.await(10L, TimeUnit.SECONDS); final Date to = aboutNow.plusMinutes(1).toDate(); final List<InMemoryHistoryNode> nodes = this.emitter.getMetrics("FakeMetric", from, to, false); assertEquals("Failed to report metric", 1, nodes.size()); assertEquals("Failed to report metric", nodes.get(0).getValue(), 4); }
@Test public void shouldUpdateCompletedByTransitionIdAndStageState() throws Exception { assertThat(stage.getCompletedByTransitionId(), is(nullValue())); DateTime fiveMinsForNow = new DateTime().plusMinutes(5); complete(firstJob, fiveMinsForNow); complete(secondJob, fiveMinsForNow); JobStateTransition lastTransition = secondJob.getTransition(JobState.Completed); stage.calculateResult(); assertThat(stage.getCompletedByTransitionId(), is(nextId)); assertThat(stage.getState(), is(StageState.Passed)); }
queryStr = StringUtils.replace(queryStr, "%%TIMEBOUNDARY_RESPONSE_MINTIME%%", TIMESTAMP_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_START%%", INTERVAL_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_END%%", INTERVAL_FMT.print(dtLast.plusMinutes(2))); queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_RESPONSE_TIMESTAMP%%", TIMESTAMP_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_START%%", INTERVAL_FMT.print(dtFirst)); queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_END%%", INTERVAL_FMT.print(dtLast.plusMinutes(2))); String postAgResponseTimestamp = TIMESTAMP_FMT.print(dtGroupBy.withSecondOfMinute(0)); queryStr = StringUtils.replace(queryStr, "%%POST_AG_RESPONSE_TIMESTAMP%%", postAgResponseTimestamp);
public static JobInstance buildEndingWithState(JobState endState, JobResult result, String jobConfig) { final JobInstance instance = new JobInstance(jobConfig); instance.setAgentUuid("1234"); instance.setId(1L); instance.setIdentifier(defaultJobIdentifier(jobConfig)); instance.setState(endState); instance.setTransitions(new JobStateTransitions()); DateTime now = new DateTime(); Date scheduledDate = now.minusMinutes(5).toDate(); instance.setScheduledDate(scheduledDate); List<JobState> orderedStates = orderedBuildStates(); DateTime stateDate = new DateTime(scheduledDate); for (JobState stateToCompareTo : orderedStates) { if (endState.compareTo(stateToCompareTo) >= 0) { instance.changeState(stateToCompareTo, stateDate.toDate()); stateDate = stateDate.plusMinutes(1); } } if (endState.equals(JobState.Completed)) { instance.setResult(result); } return instance; }
Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1));
data.setNotOnOrAfter(DateTime.now().plusMinutes(1)); data.setRecipient(recipient); conditions.setNotOnOrAfter(DateTime.now().plusMinutes(1));
@Test public void testCompareHour() { Result<Object> res = new Result<Object>(time, null); Result<Object> same = new Result<Object>(time.plusMinutes(55), null); Result<Object> greater = new Result<Object>(time.plusHours(1), null); Result<Object> less = new Result<Object>(time.minusHours(1), null); Granularity hour = Granularities.HOUR; Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, same), 0); Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, greater), descending ? 1 : -1); Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, less), descending ? -1 : 1); } }
@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))); }
assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, 0)); assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0)); assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0)); assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0)); assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0));