/** */
@Test
public void testPassTableWithTimeStampKeyCreation() {
final String creationQry = "CREATE TABLE %s (id TIMESTAMP primary key, dateField TIMESTAMP) " +
"WITH \"cache_name=%s, WRAP_VALUE=false\"";
Map<Timestamp, Timestamp> ent = new HashMap<>();
ent.put(Timestamp.valueOf(LocalDateTime.now()), Timestamp.valueOf(LocalDateTime.now().minusHours(1)));
ent.put(Timestamp.valueOf(LocalDateTime.now().minusHours(2)),
Timestamp.valueOf(LocalDateTime.now().minusHours(3)));
checkInsertUpdateDelete(creationQry, "Tab3", ent);
@Test public void testAcceptFileWithCreateTimeNotAvailale() { Path path = mock(Path.class); when(path.toFile()).thenReturn(mock(File.class)); when(path.toFile().lastModified()).thenReturn(System.currentTimeMillis()); when(path.getFileSystem()).thenThrow(SecurityException.class); // a filter with no start/end date should accept this file LogFilter filter = new LogFilter(Level.INFO, null, null); assertThat(filter.acceptsFile(path)).isTrue(); // a filter with a start date of now should not accept the file filter = new LogFilter(Level.INFO, LocalDateTime.now(), null); assertThat(filter.acceptsFile(path)).isFalse(); // a filter with a start date of now minus an hour should not accept the file filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null); assertThat(filter.acceptsFile(path)).isTrue(); // a filter with an end date of now should accept the file filter = new LogFilter(Level.INFO, null, LocalDateTime.now()); assertThat(filter.acceptsFile(path)).isTrue(); // a filter with an end date of an hour ago should also accept the file, because we only // know the last modified time of the file, when don't know what time this file is created, it // may still be created more than an hour ago. filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1)); assertThat(filter.acceptsFile(path)).isTrue();
filter = new LogFilter(Level.INFO, LocalDateTime.now().minusHours(1), null);
assertThat(filter.acceptsFile(path)).isTrue();
filter = new LogFilter(Level.INFO, null, LocalDateTime.now().minusHours(1));
assertThat(filter.acceptsFile(path)).isTrue();
@Test public void testRestoreStatus() throws Exception { InstanceState.RestoreStatus restoreStatus = new InstanceState.RestoreStatus(); restoreStatus.setStartDateRange(LocalDateTime.now().minusDays(2).withSecond(0).withNano(0)); restoreStatus.setEndDateRange(LocalDateTime.now().minusHours(3).withSecond(0).withNano(0)); restoreStatus.setExecutionStartTime(LocalDateTime.now().withSecond(0).withNano(0)); LOG.info(restoreStatus.toString()); InstanceState.RestoreStatus restoreStatus1 = GsonJsonSerializer.getGson() .fromJson(restoreStatus.toString(), InstanceState.RestoreStatus.class); LOG.info(restoreStatus1.toString()); Assert.assertEquals( restoreStatus.getExecutionStartTime(), restoreStatus1.getExecutionStartTime()); Assert.assertEquals(restoreStatus.getStartDateRange(), restoreStatus1.getStartDateRange()); Assert.assertEquals(restoreStatus.getEndDateRange(), restoreStatus1.getEndDateRange());
/**
* 获取当前时间相对于清算时间的日期
* 比如清算时间是9点,现在是8点,那么当前时间相对于清算时间要减1天
* @return
private LocalDate getOffsetDate() {
return LocalDateTime.now().minusHours(getOffsetHour()).toLocalDate();
LocalDateTime dt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(1429174464829L), ZoneId.systemDefault()); LocalDateTime dt2 = LocalDateTime.now().plusDays(1); System.out.println(dt1); System.out.println(dt2); StringJoiner sj = new StringJoiner(":"); long hours = ChronoUnit.HOURS.between(dt1, dt2); sj.add(Long.toString(hours)); dt2 = dt2.minusHours(hours); long mins = ChronoUnit.MINUTES.between(dt1, dt2); sj.add(Long.toString(mins)); dt2 = dt2.minusMinutes(mins); long secs = ChronoUnit.SECONDS.between(dt1, dt2); sj.add(Long.toString(secs)); System.out.println(sj);
public static LocalDateTime hourAgo() {
return now().minusHours(1);
public static LocalDateTime secondAgo() {
@Override public boolean hasNotificationBeenSent() { boolean hasNotificationBeenSent = false; if (lastNotificationSentTimestamp == null) return false; LocalDateTime now = LocalDateTime.now(); if (lastNotificationSentTimestamp.isAfter(now.minusHours(maxHoursBetweenNotifications))) hasNotificationBeenSent = true; return hasNotificationBeenSent;
private boolean isNotStale(Message message) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(message.getTimestamp()), ZoneId.systemDefault())
.isAfter(LocalDateTime.now().minusHours(messageMaxAgeHours));
/**
* Creates a date range filtering on the last hour.
* @return a date range for the given interval
public static DateRange lastHour() {
return new DateRange("1h", NLS.get("DateRange.1h"), LocalDateTime.now().minusHours(1), LocalDateTime.now());
/**
* Creates a date range filtering on the last two hours.
* @return a date range for the given interval
public static DateRange lastTwoHours() {
return new DateRange("2h", NLS.get("DateRange.2h"), LocalDateTime.now().minusHours(2), LocalDateTime.now());
/**
* Creates a date range filtering on the last two hours.
* @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
public static DateRange lastTwoHours() {
return new DateRange("2h", NLS.get("DateRange.2h"), LocalDateTime.now().minusHours(2), LocalDateTime.now());
/**
* Creates a date range filtering on the last hour.
* @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
public static DateRange lastHour() {
return new DateRange("1h", NLS.get("DateRange.1h"), LocalDateTime.now().minusHours(1), LocalDateTime.now());
/**
* Returns the supplied date time a number of hours in the specified output format.
* @param numberOfHours the number of hours in the past based on the supplied time.
* @return the time.
public String giveTimestampMinusNumberOfHours(String time, int numberOfHours, String dateFormat) {
return getTime(time, dateFormat).minusHours(numberOfHours).format(getFormat(dateFormat));
public Long parse(String formattedTime) { try { Period period = hourFormatter.parsePeriod(formattedTime); return LocalDateTime.now().minusHours(period.getHours()).atZone(clock.getZone()).toInstant().toEpochMilli(); } catch (IllegalArgumentException e) { logger.info("Could not parse period. {}", e.getMessage()); try { return LocalDateTime.parse(formattedTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME).atZone(clock.getZone()).toInstant().toEpochMilli(); } catch (DateTimeParseException e) { logger.info("Could not parse date. {}", e.getMessage()); throw new IllegalArgumentException( "Could not parse given time. Available formats: period in hours (ex. \"-7h\") or ISO local date time"
default
List<DictatorConfigHistory> findLastHour() {
Weekend<DictatorConfigHistory> weekend = Weekend.of(DictatorConfigHistory.class);
weekend.weekendCriteria()
.andGreaterThanOrEqualTo(DictatorConfigHistory::getHistoryCreatedTime, LocalDateTime.now().minusHours(1));
return this.selectByExample(weekend);
private Message messageOfAge(int ageHours) { return new JsonMessage( MessageIdGenerator.generate(), "{'a':'b'}".getBytes(), now().minusHours(ageHours).toInstant(UTC).toEpochMilli()
private
static String formatSpokenDateWithTime(Temporal date) {
// We have a time, perform some nice formatting...
LocalDateTime givenDateTime = LocalDateTime.from(date);
if (givenDateTime.isAfter(LocalDateTime.now())) {
return formatSpokenFutureDateWithTime(date, givenDateTime);
if (givenDateTime.isAfter(LocalDateTime.now().minusHours(12))) {
return formatSpokenRecentDateWithTime(givenDateTime);
if (!ChronoField.DAY_OF_MONTH.isSupportedBy(date)) {
// We don't have a date and the time difference is quite big -> simply format the time...
return getTimeFormat(getCurrentLang()).format(date);
return formatSpokenDate(date);
private
static String formatSpokenRecentDateWithTime(LocalDateTime givenDateTime) {
if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(30))) {
return NLS.get("NLS.someMinutesAgo");
if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(59))) {
return NLS.fmtr("NLS.nMinutesAgo")
.set("minutes", Duration.between(givenDateTime, LocalDateTime.now()).toMinutes())
.format();
if (givenDateTime.isAfter(LocalDateTime.now().minusHours(2))) {
return NLS.get("NLS.oneHourAgo");
return NLS.fmtr("NLS.nHoursAgo")
.set("hours", Duration.between(givenDateTime, LocalDateTime.now()).toHours())
.format();
limitDay = 1L;
} else {
limitDay = ChronoUnit.DAYS.between(now.minusHours(getOffsetHour()).toLocalDate(), planSellOutDate) + 1;