LocalDate today = LocalDate.now() LocalDate yeasterday = today.minusDays(1); Duration oneDay = Duration.between(today, yesterday); Duration.between(today.atTime(0, 0), yesterday.atTime(0, 0)).toDays() // another option
/** * Parse the string to LocalDateTime * * @param date to parse. Accepted formats are yyyyMMddHHmm and yyyyMMdd * @return the parsed LocalDateTime or null if input could not be parsed */ public static LocalDateTime getLocalDateTime(String date) { if (StringUtils.isEmpty(date)) return null; try { LocalDateTime localDateTime = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(yyyyMMddHHmm)); if (localDateTime != null) return localDateTime; } catch (DateTimeParseException e) { // Try the date only. try { LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern(yyyyMMdd)); return localDate.atTime(0, 0); } catch (DateTimeParseException ex) { return null; } } return null; }
public static SqlTime sqlTimeOf(LocalTime time, Session session) { if (session.toConnectorSession().isLegacyTimestamp()) { long millisUtc = LocalDate.ofEpochDay(0) .atTime(time) .atZone(UTC) .withZoneSameLocal(ZoneId.of(session.getTimeZoneKey().getId())) .toInstant() .toEpochMilli(); return new SqlTime(millisUtc, session.getTimeZoneKey()); } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); }
flight.setFlightNumber(flightNumber); flight.setDepartureAirport(departureAirport); flight.setDepartureUTCDateTime(date.atTime(departureMinute / 60, departureMinute % 60)); flight.setArrivalAirport(arrivalAirport); flight.setArrivalUTCDateTime(date.atTime(arrivalMinute / 60, arrivalMinute % 60)); logger.trace("Created flight ({}).", flight); flightList.add(flight);
public static LocalDateTime parseDateTime(String str) { if (str == null || str.length() == 0 || str.equals("null")) { return null; } return LocalDate.parse(str, formatter).atTime(LocalTime.MIN); }
@Test public void localDateToDate() throws Exception { LocalDate localDate = LocalDate.of(1983, 4, 20); Date date = (Date) transformer.transform(localDate); assertEquals(localDate.atTime(0, 0), date); }
/** * Gets the expiry date-time. * <p> * The option expires at this date and time. * <p> * The result is returned by combining the expiry date, time and time-zone. * * @return the expiry date and time */ public ZonedDateTime getExpiry() { return expiryDate.atTime(expiryTime).atZone(expiryZone); }
/** * Gets the expiry date-time. * <p> * The option expires at this date and time. * <p> * The result is returned by combining the expiry date, time and time-zone. * * @return the expiry date and time */ public ZonedDateTime getExpiry() { return expiryDate.atTime(expiryTime).atZone(expiryZone); }
/** * Gets the expiry date-time. * <p> * The option expires at this date and time. * <p> * The result is returned by combining the expiry date, time and time-zone. * * @return the expiry date and time */ public ZonedDateTime getExpiry() { return expiryDate.atTime(expiryTime).atZone(expiryZone); }
@Override public ZonedDateTime calculateFixingDateTime(LocalDate fixingDate) { return fixingDate.atTime(fixingTime).atZone(fixingZone); }
/** * delegates to {@link #to(LocalDateTime)} with MIDNIGHT */ public QueryBuilder to(LocalDate toDate) { return to(toDate.atTime(MIDNIGHT)); }
/** * Parse date given in format 'YYYY-MM-DD' to millis in UTC timezone */ public static long getDate(String date) { LocalDate localDate = LocalDate.parse(date, DateTimes.CALCITE_LOCAL_DATE_FORMATTER); return localDate.atTime(LocalTime.MIDNIGHT).toInstant(ZoneOffset.UTC).toEpochMilli(); }
/** * Gets the expiry date-time. * <p> * The option expires at this date and time. * <p> * The result is returned by combining the expiry date, time and time-zone. * * @return the expiry date and time */ public ZonedDateTime getExpiry() { return expiryDate.getUnadjusted().atTime(expiryTime).atZone(expiryZone); }
/** * delegates to {@link #from(LocalDateTime)} with MIDNIGHT */ public QueryBuilder from(LocalDate fromDate) { return from(fromDate.atTime(MIDNIGHT)); }
private Optional<LocalDateTime> getLocalDateTime(TemporalAccessor parsed) { return getLocalDate(parsed).map(date -> { Optional<LocalTime> time = getLocalTime(parsed); return time.isPresent()? date.atTime(time.get()) : null; }); }
public void test_of_LocalDateAndTime() { HullWhiteOneFactorPiecewiseConstantParametersProvider test = HullWhiteOneFactorPiecewiseConstantParametersProvider.of(PARAMETERS, ACT_360, VAL_DATE, TIME, ZONE); assertEquals(test.getDayCount(), ACT_360); assertEquals(test.getParameters(), PARAMETERS); assertEquals(test.getValuationDateTime(), VAL_DATE.atTime(TIME).atZone(ZONE)); }
@Override public ResolvedSwaption resolve(ReferenceData refData) { return ResolvedSwaption.builder() .expiry(expiryDate.adjusted(refData).atTime(expiryTime).atZone(expiryZone)) .longShort(longShort) .swaptionSettlement(swaptionSettlement) .underlying(underlying.resolve(refData)) .build(); }
public void test_resolve() { Swaption base = sut(); ResolvedSwaption test = base.resolve(REF_DATA); assertEquals(test.getExpiry(), ADJUSTMENT.adjust(EXPIRY_DATE, REF_DATA).atTime(EXPIRY_TIME).atZone(ZONE)); assertEquals(test.getLongShort(), LONG); assertEquals(test.getSwaptionSettlement(), PHYSICAL_SETTLE); assertEquals(test.getUnderlying(), SWAP.resolve(REF_DATA)); }
public void test_resolve() { FxVanillaOption base = sut(); ResolvedFxVanillaOption expected = ResolvedFxVanillaOption.builder() .longShort(LONG) .expiry(EXPIRY_DATE.atTime(EXPIRY_TIME).atZone(EXPIRY_ZONE)) .underlying(FX.resolve(REF_DATA)) .build(); assertEquals(base.resolve(REF_DATA), expected); }
public void test_resolve() { BondFutureOption test = sut(); ResolvedBondFutureOption expected = ResolvedBondFutureOption.builder() .securityId(SECURITY_ID) .putCall(CALL) .strikePrice(STRIKE_PRICE) .expiry(EXPIRY_DATE.atTime(EXPIRY_TIME).atZone(EXPIRY_ZONE)) .premiumStyle(FutureOptionPremiumStyle.DAILY_MARGIN) .underlyingFuture(FUTURE.resolve(REF_DATA)) .build(); assertEquals(test.resolve(REF_DATA), expected); }