@Override public LocalDateTimeValue add( DurationValue duration ) { return replacement( assertValidArithmetic( () -> value.plus( duration ) ) ); }
/** * Returns the given packedDateTime with amtToAdd of temporal units added * * TODO(lwhite): Replace with a native implementation that doesn't convert everything to LocalDateTime */ public static long plus(long packedDateTime, long amountToAdd, TemporalUnit unit) { LocalDateTime dateTime = asLocalDateTime(packedDateTime); return pack(dateTime.plus(amountToAdd, unit)); }
LocalDateTime endTime = LocalDateTime.now().plus(remainingSeconds, ChronoUnit.SECONDS); LocalDateTime currentTime = LocalDateTime.now(); if (endTime.getDayOfWeek() != currentTime.getDayOfWeek())
/** * @param response The Http response * @param lastModified The last modified */ protected void setDateAndCacheHeaders(MutableHttpResponse response, long lastModified) { // Date header MutableHttpHeaders headers = response.getHeaders(); LocalDateTime now = LocalDateTime.now(); headers.date(now); // Add cache headers LocalDateTime cacheSeconds = now.plus(configuration.getCacheSeconds(), ChronoUnit.SECONDS); if (response.header(HttpHeaders.EXPIRES) == null) { headers.expires(cacheSeconds); } if (response.header(HttpHeaders.CACHE_CONTROL) == null) { response.header(HttpHeaders.CACHE_CONTROL, "private, max-age=" + configuration.getCacheSeconds()); } if (response.header(HttpHeaders.LAST_MODIFIED) == null) { headers.lastModified(lastModified); } }
String input = "2011120312345655"; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); int len = input.length(); LocalDateTime ldt = LocalDateTime.parse(input.substring(0, len - 2), dtf); int millis = Integer.parseInt(input.substring(len - 2)) * 10; ldt = ldt.plus(millis, ChronoUnit.MILLIS); System.out.println(ldt); // 2011-12-03T12:34:56.550
@Test public void rangeQueries() { Instant instant = Instant.ofEpochMilli(System.currentTimeMillis()); LocalDate localDate = LocalDate.of(1995, 10, 15); LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000); LocalTime localTime = LocalTime.of(10, 29, 15, 848493); for (int i = 0; i < 10; i++) { createEntity(getDs(), instant.plus(i, DAYS), localDate.plus(i, DAYS), localDateTime.plus(i, DAYS), localTime.plus(i, ChronoUnit.HOURS)); } Assert.assertEquals(2L, getDs().find(Java8Entity.class).field("instant").lessThanOrEq(instant.plus(1, DAYS)).count()); Assert.assertEquals(1L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.plus(1, DAYS)).count()); Assert.assertEquals(0L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.minus(1, DAYS)).count()); Assert.assertEquals(9L, getDs().find(Java8Entity.class).field("localDateTime") .notEqual(localDateTime.plus(6, DAYS)).count()); }
public void recommitOffsets() { LocalDateTime now = LocalDateTime.now(clock); if (now.isAfter(lastUpdateTime.plus(IDLE_DURATION))) { for (TopicPartition tp : offsetData.keySet()) { OffsetAndTime offsetAndTime = offsetData.get(tp); if (now.isAfter(offsetAndTime.time.plus(IDLE_DURATION))) { try { consumer.commitSync(Collections.singletonMap(tp, new OffsetAndMetadata(offsetAndTime.offset))); } catch (CommitFailedException covfefe) { logger.info("Caught CommitFailedException attempting to commit {} {}", tp, offsetAndTime.offset); } offsetAndTime.time = now; } } lastUpdateTime = now; } }
final LocalDateTime testEnd = testStart.plus(TEST_DURATION);
/** * Convert a Duration into a LocalTime and format the value as a String * * @param input * @param format * @return */ @UserFunction( "apoc.temporal.formatDuration" ) @Description( "apoc.temporal.formatDuration(input, format) | Format a Duration" ) public String formatDuration( @Name("input") Object input, @Name("format") String format ) { try { LocalDateTime midnight = LocalDateTime.of(0, 1, 1, 0, 0, 0, 0); LocalDateTime newDuration = midnight.plus( (DurationValue) input ); DateTimeFormatter formatter = getOrCreate(format); return newDuration.format(formatter); } catch (Exception e){ throw new RuntimeException("Available formats are:\n" + String.join("\n", getTypes()) + "\nSee also: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/mapping-date-format.html#built-in-date-formats " + "and https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html"); } }
if (date.isAfter(now.plus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES))) || date.isBefore(now.minus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES)))) { throw new RestException(HttpStatus.FORBIDDEN.value(), String.format("requestTimeTooSkewed"));
@Override public Instant next() { Instant result = next.atZone(zoneId).toInstant(); next = next.plus(amount).with(adjuster); return result; }
@Override public LocalDateTime next() { final LocalDateTime next = value; value = ascend ? value.plus(step) : value.minus(step); return next; } };
/** * Build a random {@link LocalDateTime} with an year either side of today. For example * <p/> * <code> * LocalDateTime aRandomBirthday = RandomBuilder.aRandomLocalDateTime(); * </code> * * @return a random {@link LocalDateTime} with an year either side of today. */ public static LocalDateTime aRandomLocalDateTime() { return LocalDateTime.now().plus(nextInt(SECONDS_IN_A_YEAR), ChronoUnit.SECONDS); }
private Instant plusOne(Instant date){ LocalDateTime current = LocalDateTime.ofInstant(date, UTC) .plus(1L, unit).withMinute(0).withSecond(0); return current.atZone(UTC).toInstant(); }
/** * Returns the time at the center */ @Nonnull public LocalDateTime getCenter() { Duration duration = getDuration(); return start.plus(duration.dividedBy(2)); }
@Override public LocalDateTimeValue add( DurationValue duration ) { return replacement( assertValidArithmetic( () -> value.plus( duration ) ) ); }
public SumkDate plusMilSeconds(int mils) { if (mils == 0) { return this; } return of(this.toLocalDateTime().plus(mils, ChronoUnit.MILLIS)); }
public LocalDateTime evaluate(LocalDateTime ldt, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) { if (code == ApacheCommonsDateUtils.MODIFY_TRUNCATE) { return ldt.truncatedTo(fieldName.getChronoUnit()); } else if (code == ApacheCommonsDateUtils.MODIFY_CEILING) { return ldt.plus(1, fieldName.getChronoUnit()).truncatedTo(fieldName.getChronoUnit()); } else { throw new EPException("Round-half operation not supported for LocalDateTime"); } }