Refine search
protected ZonedDateTimeWithZoneIdSerializer() { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, // Serialize in a backwards compatible way: with zone id, using toString method null); }
public ZonedDateTimeSerializer(DateTimeFormatter formatter) { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, formatter); _writeZoneId = null; }
/** * Parse the first header value for the given header name as a date, * return -1 if there is no value or also in case of an invalid value * (if {@code rejectInvalid=false}), or raise {@link IllegalArgumentException} * if the value cannot be parsed as a date. * @param headerName the header name * @param rejectInvalid whether to reject invalid values with an * {@link IllegalArgumentException} ({@code true}) or rather return -1 * in that case ({@code false}) * @return the parsed date header, or -1 if none (or invalid) * @see #getFirstZonedDateTime(String, boolean) */ private long getFirstDate(String headerName, boolean rejectInvalid) { ZonedDateTime zonedDateTime = getFirstZonedDateTime(headerName, rejectInvalid); return (zonedDateTime != null ? zonedDateTime.toInstant().toEpochMilli() : -1); }
public long toEpochMilli() { return zonedDateTime.toInstant().toEpochMilli(); }
public ZonedDateTimeSerializer(DateTimeFormatter formatter) { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, formatter); _writeZoneId = null; }
protected ZonedDateTimeWithZoneIdSerializer() { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, // Serialize in a backwards compatible way: with zone id, using toString method null); }
/** * Converts local date time to epoh milliseconds. */ public static long toMilliseconds(final LocalDateTime localDateTime) { return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
@Override public Optional<Long> getEpochMilli(final String time) { final ZonedDateTime parsed = ZonedDateTime.parse(time, ISO_ZONED_DATE_TIME); return Optional.of(parsed.toInstant().toEpochMilli()); }
@Override public Optional<Long> getEpochMilli(final String time) { final LocalDateTime parsed = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME); return Optional.of(parsed.atZone(zoneId).toInstant().toEpochMilli()); }
public static long dateToLong(Object datelike) { if (datelike instanceof Date) { Date date = (Date) datelike; return date.getTime(); } else if (datelike instanceof Calendar) { Calendar calendar = (Calendar) datelike; return calendar.getTimeInMillis(); } else if (datelike instanceof Instant) { Instant instant = (Instant) datelike; return instant.toEpochMilli(); } else if (datelike instanceof LocalDateTime) { LocalDateTime date = (LocalDateTime) datelike; return date.atZone(ZoneId.of("UTC")).toInstant().toEpochMilli(); } else if (datelike instanceof LocalDate) { LocalDate date = (LocalDate) datelike; return date.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli(); } else { throw new IllegalArgumentException("Illegal argument " + datelike + ". Expected a Number, Date, Instant, LocalDateTime, or LocalDate"); } }
private Date acquireData() { return new Date(LocalDateTime.now().atZone(ZoneId.systemDefault()) .toInstant().toEpochMilli() - (hmilyConfig.getRecoverDelayTime() * 1000)); }
/** * Parse the first header value for the given header name as a date, * return -1 if there is no value or also in case of an invalid value * (if {@code rejectInvalid=false}), or raise {@link IllegalArgumentException} * if the value cannot be parsed as a date. * @param headerName the header name * @param rejectInvalid whether to reject invalid values with an * {@link IllegalArgumentException} ({@code true}) or rather return -1 * in that case ({@code false}) * @return the parsed date header, or -1 if none (or invalid) * @see #getFirstZonedDateTime(String, boolean) */ private long getFirstDate(String headerName, boolean rejectInvalid) { ZonedDateTime zonedDateTime = getFirstZonedDateTime(headerName, rejectInvalid); return (zonedDateTime != null ? zonedDateTime.toInstant().toEpochMilli() : -1); }
private Date acquireData() { return new Date(LocalDateTime.now() .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - (txConfig.getRecoverDelayTime() * 1000)); }
private Date acquireData(final MythConfig mythConfig) { return new Date(LocalDateTime.now().atZone(ZoneId.systemDefault()) .toInstant().toEpochMilli() - (mythConfig.getRecoverDelayTime() * 1000)); }
protected static long firstDelay(int resetTime, TimeUnit resetTimeUnit) { LocalDateTime firstResetTime = computeFirstResetTime(LocalDateTime.now(), resetTime, resetTimeUnit); return firstResetTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - System.currentTimeMillis(); }
@Override protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) { final Object datish = value.required(args, context); if (datish instanceof DateTime) { return (DateTime) datish; } if (datish instanceof Date) { return new DateTime(datish); } if (datish instanceof ZonedDateTime) { final ZonedDateTime zonedDateTime = (ZonedDateTime) datish; final DateTimeZone timeZone = DateTimeZone.forID(zonedDateTime.getZone().getId()); return new DateTime(zonedDateTime.toInstant().toEpochMilli(), timeZone); } return null; }
@Override @SuppressWarnings("unchecked") public <X> X unwrap(LocalDate value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( LocalDate.class.isAssignableFrom( type ) ) { return (X) value; } if ( java.sql.Date.class.isAssignableFrom( type ) ) { return (X) java.sql.Date.valueOf( value ); } final LocalDateTime localDateTime = value.atStartOfDay(); if ( Timestamp.class.isAssignableFrom( type ) ) { return (X) Timestamp.valueOf( localDateTime ); } final ZonedDateTime zonedDateTime = localDateTime.atZone( ZoneId.systemDefault() ); if ( Calendar.class.isAssignableFrom( type ) ) { return (X) GregorianCalendar.from( zonedDateTime ); } final Instant instant = zonedDateTime.toInstant(); if ( Date.class.equals( type ) ) { return (X) Date.from( instant ); } if ( Long.class.isAssignableFrom( type ) ) { return (X) Long.valueOf( instant.toEpochMilli() ); } throw unknownUnwrap( type ); }
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Timestamp.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Date.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Time.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) Long.valueOf( instant.toEpochMilli() );
final Instant instant = zonedDateTime.toInstant(); return (X) Long.valueOf( instant.toEpochMilli() );
@Override @SuppressWarnings("unchecked") public <X> X unwrap(ZonedDateTime zonedDateTime, Class<X> type, WrapperOptions options) { if ( zonedDateTime == null ) { return null; } if ( ZonedDateTime.class.isAssignableFrom( type ) ) { return (X) zonedDateTime; } if ( Calendar.class.isAssignableFrom( type ) ) { return (X) GregorianCalendar.from( zonedDateTime ); } if ( Timestamp.class.isAssignableFrom( type ) ) { return (X) Timestamp.from( zonedDateTime.toInstant() ); } if ( java.sql.Date.class.isAssignableFrom( type ) ) { return (X) java.sql.Date.from( zonedDateTime.toInstant() ); } if ( java.sql.Time.class.isAssignableFrom( type ) ) { return (X) java.sql.Time.from( zonedDateTime.toInstant() ); } if ( Date.class.isAssignableFrom( type ) ) { return (X) Date.from( zonedDateTime.toInstant() ); } if ( Long.class.isAssignableFrom( type ) ) { return (X) Long.valueOf( zonedDateTime.toInstant().toEpochMilli() ); } throw unknownUnwrap( type ); }