static String plusHours(int hours) { return ZonedDateTime.now().plusHours(hours).format(DateTimeFormatter.ISO_ZONED_DATE_TIME); }
@Test public void testPredicates() { boolean result = new BetweenRoutePredicateFactory() .apply(c -> c.setDatetime1(ZonedDateTime.now().minusHours(2)) .setDatetime2(ZonedDateTime.now().plusHours(1))) .test(getExchange()); assertThat(result).isTrue(); }
public ZonedDateTime plusHours(long amount) { return dt.plusHours(amount); }
/** * Constructor<br> * The end date will be the start date + {@link #DEFAULT_RANGE} hour(s) * * @param id the event id * @param title the event title * @param start the start date */ public SchedulerEvent(Number id, String title, ZonedDateTime start) { this(id, title, start, start.plusHours(DEFAULT_RANGE)); }
/** * Constructor<br> * The end date will be the start date + {@link #DEFAULT_RANGE} hour(s)<br> * <b>Caution:</b> if the id is not a number, the datasource's schema need to reflect the type * * @param id the event id * @param title the event title * @param start the start date */ public SchedulerEvent(Object id, String title, ZonedDateTime start) { this(id, title, start, start.plusHours(DEFAULT_RANGE)); }
Long input = 1457928024812L; Instant instant = Instant.ofEpochMilli ( input ); ZoneId zoneId = ZoneId.of ( "America/Chicago" ); ZonedDateTime zdt = ZonedDateTime.ofInstant ( instant, zoneId ); ZonedDateTime zdtHourLater = zdt.plusHours ( 1 );
ZoneId z = ZoneId.of( "America/Montreal" ); ZonedDateTime zdtStart = ZonedDateTime.now( z ); ZonedDateTime zdtStop = zdtStart.plusHours( 3 ).plusMinutes( 7 ); Duration d = Duration.between( zdtStart , zdtStop );
ZoneId zoneId = ZoneId.of( "America/Montreal" ); ZonedDateTime zdt1 = ZonedDateTime.of( LocalDate.of( 2016 , 1 , 2 ) , LocalTime.of( 16 , 0 , 0 ) , zoneId ); Instant start1 = zdt1.toInstant(); Instant stop1 = zdt1.plusHours( 2 ).toInstant(); // 18:00:00.0 = ( 16:00:00.0 + 2 hours ). Interval reservation1 = Interval.of( start1 , stop1 );
System.out.println ( "java.version: " + System.getProperty ( "java.version" ) ); ZoneId z = ZoneId.of ( "Europe/Istanbul" ); ZonedDateTime zdt = ZonedDateTime.of ( 2016 , 10 , 30 , 0 , 0 , 0 , 0 , z ); System.out.println ( " zdt: " + zdt ); System.out.println ( "zdt + 1: " + zdt.plusHours ( 1 ) ); System.out.println ( "zdt + 2: " + zdt.plusHours ( 2 ) ); System.out.println ( "zdt + 3: " + zdt.plusHours ( 3 ) ); System.out.println ( "zdt + 4: " + zdt.plusHours ( 4 ) ); System.out.println ( "zdt + 5: " + zdt.plusHours ( 5 ) ); System.out.println ( "zdt + 6: " + zdt.plusHours ( 6 ) );
public static ZonedDateTime calculateTimeForSunrise(ZonedDateTime from, ZonedDateTime to) { Duration d = Duration.between(from, to); long distance = d.getSeconds() / 60 / 60 / 2; return from.plusHours(distance); } }
ZonedDateTime nextDay = start.plusDays ( 1 ); ZonedDateTime zdt = start; while ( zdt.isBefore ( nextDay ) ) { ZonedDateTime zdtMinute = zdt; ZonedDateTime zdtNextHour = zdtMinute.plusHours ( 1 ); while ( zdtMinute.isBefore ( zdtNextHour ) ) { System.out.println ( zdtMinute.toString () ); // Prepare for next loop. zdtMinute = zdtMinute.plusMinutes ( 1 ); } // Prepare for next loop. zdt = zdt.plusHours ( 1 ); }
@Override public ZonedDateTime getExpiresAt() { return expiresAtPlusFive ? ZonedDateTime.now().plusHours(5) : ZonedDateTime.now(); }
public static ZonedDateTime roundUpMinutes(ZonedDateTime time, int step) { int mins = time.getMinute(); time = time.withSecond(0).withNano(0); if (mins % step == 0) return time; if (60 % step != 0) throw new IllegalArgumentException("Invalid step: " + step); mins = mins + step - (mins % step); return mins < 60 ? time.withMinute(mins) : time.plusHours(1).withMinute(mins - 60); }
@Test public void getValidityShouldReturnFalseWhenTokenIsOutdated() throws Exception { zonedDateTimeProvider.setFixedDateTime(DATE); ContinuationToken continuationToken = tokenFactory.generateContinuationToken("user"); zonedDateTimeProvider.setFixedDateTime(DATE.plusHours(1)); assertThat(tokenManager.getValidity(continuationToken)).isEqualTo(TokenStatus.EXPIRED); }
@Test public void isValidShouldReturnFalseWhenTokenIsOutdated() throws Exception { zonedDateTimeProvider.setFixedDateTime(DATE); ContinuationToken continuationToken = tokenFactory.generateContinuationToken("user"); zonedDateTimeProvider.setFixedDateTime(DATE.plusHours(1)); assertThat(tokenManager.isValid(continuationToken)).isFalse(); }
@Test public void getValidityhouldRecognizeTokenWhereExpirationDateIsModified() throws Exception { zonedDateTimeProvider.setFixedDateTime(DATE); ContinuationToken continuationToken = tokenFactory.generateContinuationToken("user"); ContinuationToken pirateContinuationToken = new ContinuationToken(continuationToken.getUsername(), continuationToken.getExpirationDate().plusHours(1), continuationToken.getSignature()); assertThat(tokenManager.getValidity(pirateContinuationToken)).isEqualTo(TokenStatus.INVALID); }
@Test public void isValidShouldRecognizeTokenWhereExpirationDateIsModified() throws Exception { zonedDateTimeProvider.setFixedDateTime(DATE); ContinuationToken continuationToken = tokenFactory.generateContinuationToken("user"); ContinuationToken pirateContinuationToken = new ContinuationToken(continuationToken.getUsername(), continuationToken.getExpirationDate().plusHours(1), continuationToken.getSignature()); assertThat(tokenManager.isValid(pirateContinuationToken)).isFalse(); }
static ResolvedSwaption sut2() { return ResolvedSwaption.builder() .expiry(EXPIRY.plusHours(1)) .longShort(SHORT) .swaptionSettlement(CASH_SETTLE) .underlying(FixedIborSwapConventions.USD_FIXED_6M_LIBOR_3M .createTrade(LocalDate.of(2014, 6, 10), Tenor.TENOR_10Y, BuySell.BUY, 1d, FIXED_RATE, REF_DATA) .getProduct().resolve(REF_DATA)) .build(); }
@Test public void addPriceWithValidityPeriod() throws Exception { final PriceDraft expectedPrice = PriceDraft.of(MoneyImpl.of(123, EUR)) .withValidFrom(SphereTestUtils.now()) .withValidUntil(SphereTestUtils.now().withZoneSameLocal(ZoneOffset.UTC).plusHours(2)); testAddPrice(expectedPrice); }