.plusMinutes(minutes) .plusSeconds(seconds) .plusNanos(nanoSeconds);
/** * Converts a MySQL {@code TIME} value <em>without fractional seconds</em> to a {@link java.time.Duration}. * * @param inputStream the binary stream containing the raw binlog event data for the value * @return the {@link LocalTime} object * @throws IOException if there is an error reading from the binlog event data */ protected static Serializable deserializeTime(ByteArrayInputStream inputStream) throws IOException { // Times are stored as an integer as `HHMMSS`, so we need to split out the digits ... int value = inputStream.readInteger(3); int[] split = split(value, 100, 3); int hours = split[2]; int minutes = split[1]; int seconds = split[0]; return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds); }
return Duration.ofDays(interval.getDays()) .plusHours(interval.getHours()) .plusMinutes(interval.getMinutes()) .plusSeconds(secondsLong) .plusNanos(nanos);
@Test public void testWriteReadNegativeDuration() { handle.execute("insert into intervals(id, foo) values(?, ?)", 8, Duration.ofDays(-3).plusMinutes(2)); final Duration d = handle.createQuery("select foo from intervals where id=?") .bind(0, 8) .mapTo(Duration.class) .findOnly(); assertThat(d).isEqualTo(Duration.ofDays(-3).plusMinutes(2)); }
@Test public void onExpirationUpdatedSetExpireSession() throws Exception { String sessionKey = this.policy.getSessionKey(this.session.getId()); this.policy.onExpirationUpdated(null, this.session); verify(this.sessionRedisOperations).boundHashOps(sessionKey); verify(this.hashOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void onExpirationUpdatedAddsExpirationTimeRoundedUp() throws Exception { long expirationTimeInMs = RedisSessionExpirationPolicy .expiresInMillis(this.session); long expirationRoundedUpInMs = RedisSessionExpirationPolicy .roundUpToNextMinute(expirationTimeInMs); String expectedExpireKey = this.policy.getExpirationKey(expirationRoundedUpInMs); this.policy.onExpirationUpdated(null, this.session); verify(this.sessionRedisOperations).boundSetOps(expectedExpireKey); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void onExpirationUpdatedDeleteOnZero() throws Exception { String sessionKey = this.policy.getSessionKey("expires:" + this.session.getId()); long originalExpirationTimeInMs = ONE_MINUTE_AGO; this.session.setMaxInactiveInterval(Duration.ZERO); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); // verify the original is removed verify(this.setOperations).remove("expires:" + this.session.getId()); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.sessionRedisOperations).delete(sessionKey); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void testReadsViaFluentAPI() { List<Duration> periods = handle.createQuery("select foo from intervals where id = 1 or id = 2 order by id") .mapTo(Duration.class) .list(); assertThat(periods).isEqualTo(ImmutableList.of( Duration.ofDays(1).plusHours(15), Duration.ofDays(40).plusMinutes(22) )); }
nanoSeconds = deserializeFractionalSecondsInNanos(meta, inputStream); return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusNanos(nanoSeconds);
@Test public void saveJavadocSummary() { RedisSession session = this.redisRepository.createSession(); String sessionKey = "spring:session:sessions:" + session.getId(); String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy.roundUpToNextMinute( RedisSessionExpirationPolicy.expiresInMillis(session)); String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId(); given(this.redisOperations.boundHashOps(sessionKey)) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(backgroundExpireKey)) .willReturn(this.boundSetOperations); given(this.redisOperations.boundValueOps(destroyedTriggerKey)) .willReturn(this.boundValueOperations); this.redisRepository.save(session); // the actual data in the session expires 5 minutes after expiration so the data // can be accessed in expiration events // if the session is retrieved and expired it will not be returned since // findById checks if it is expired long fiveMinutesAfterExpires = session.getMaxInactiveInterval().plusMinutes(5) .getSeconds(); verify(this.boundHashOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).expire(fiveMinutesAfterExpires, TimeUnit.SECONDS); verify(this.boundSetOperations).add("expires:" + session.getId()); verify(this.boundValueOperations).expire(1800L, TimeUnit.SECONDS); verify(this.boundValueOperations).append(""); }
@Test public void saveJavadoc() { RedisSession session = this.redisRepository.new RedisSession(this.cached); session.setLastAccessedTime(session.getLastAccessedTime()); given(this.redisOperations.boundHashOps("spring:session:sessions:session-id")) .willReturn(this.boundHashOperations); given(this.redisOperations .boundSetOps("spring:session:expirations:1404361860000")) .willReturn(this.boundSetOperations); given(this.redisOperations .boundValueOps("spring:session:sessions:expires:session-id")) .willReturn(this.boundValueOperations); this.redisRepository.save(session); // the actual data in the session expires 5 minutes after expiration so the data // can be accessed in expiration events // if the session is retrieved and expired it will not be returned since // findById checks if it is expired verify(this.boundHashOperations).expire( session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
long expectedMillis = Duration.ofHours(17).plusMinutes(51).plusSeconds(4).plusMillis(780).toMillis(); assertThat(c2).isEqualTo((int)expectedMillis);
private static void binaryEncodeINTERVAL(Interval interval, ByteBuf buff) { Duration duration = Duration .ofHours(interval.getHours()) .plusMinutes(interval.getMinutes()) .plusSeconds(interval.getSeconds()) .plus(interval.getMicroseconds(), ChronoUnit.MICROS); // days won't be changed Period monthYear = Period.of(interval.getYears(), interval.getMonths(), interval.getDays()).normalized(); binaryEncodeINT8(NANOSECONDS.toMicros(duration.toNanos()), buff); binaryEncodeINT4(monthYear.getDays(), buff); binaryEncodeINT4((int) monthYear.toTotalMonths(), buff); }
private static void binaryEncodeINTERVAL(Interval interval, ByteBuf buff) { Duration duration = Duration .ofHours(interval.getHours()) .plusMinutes(interval.getMinutes()) .plusSeconds(interval.getSeconds()) .plus(interval.getMicroseconds(), ChronoUnit.MICROS); // days won't be changed Period monthYear = Period.of(interval.getYears(), interval.getMonths(), interval.getDays()).normalized(); binaryEncodeINT8(NANOSECONDS.toMicros(duration.toNanos()), buff); binaryEncodeINT4(monthYear.getDays(), buff); binaryEncodeINT4((int) monthYear.toTotalMonths(), buff); }
@Override public void initialize(DurationMin constraintAnnotation) { this.minDuration = Duration.ofNanos( constraintAnnotation.nanos() ) .plusMillis( constraintAnnotation.millis() ) .plusSeconds( constraintAnnotation.seconds() ) .plusMinutes( constraintAnnotation.minutes() ) .plusHours( constraintAnnotation.hours() ) .plusDays( constraintAnnotation.days() ); this.inclusive = constraintAnnotation.inclusive(); }
@Override public void initialize(DurationMax constraintAnnotation) { this.maxDuration = Duration.ofNanos( constraintAnnotation.nanos() ) .plusMillis( constraintAnnotation.millis() ) .plusSeconds( constraintAnnotation.seconds() ) .plusMinutes( constraintAnnotation.minutes() ) .plusHours( constraintAnnotation.hours() ) .plusDays( constraintAnnotation.days() ); this.inclusive = constraintAnnotation.inclusive(); }
protected TemporalAmount toTemporalDuration(Duration duration) { int days = normalize(duration.getDays()); int hours = normalize(duration.getHours()); int minutes = normalize(duration.getMinutes()); int seconds = normalize(duration.getSeconds()); java.time.Duration timeDuration = java.time.Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds); return duration.getSign() == -1 ? timeDuration.negated() : timeDuration; }
protected TemporalAmount toTemporalDuration(Duration duration) { int days = normalize(duration.getDays()); int hours = normalize(duration.getHours()); int minutes = normalize(duration.getMinutes()); int seconds = normalize(duration.getSeconds()); java.time.Duration timeDuration = java.time.Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds); return duration.getSign() == -1 ? timeDuration.negated() : timeDuration; }
@Test public void invokeParamTemporalDuration() { FunctionTestUtil.assertResult( durationFunction.invoke(Duration.parse("P2DT3H28M15S")), Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28).plusSeconds(15)); }
@Test public void invokeParamStringDuration() { FunctionTestUtil.assertResult(durationFunction.invoke("P2D"), Duration.of(2, ChronoUnit.DAYS)); FunctionTestUtil.assertResult(durationFunction.invoke("P2DT3H"), Duration.of(2, ChronoUnit.DAYS).plusHours(3)); FunctionTestUtil.assertResult( durationFunction.invoke("P2DT3H28M"), Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28)); FunctionTestUtil.assertResult( durationFunction.invoke("P2DT3H28M15S"), Duration.of(2, ChronoUnit.DAYS).plusHours(3).plusMinutes(28).plusSeconds(15)); }