hjjae2 / anything

:fire: anything
2 stars 0 forks source link

LocalDateTimeJavaDescriptor #13

Open hjjae2 opened 2 years ago

hjjae2 commented 2 years ago

ZeroDate's byte[19] = {48, 48, 48, 48, 45, 48, 48, 45, 48, 48, 32, 48, 48, 58, 48, 48, 58, 48, 48}

0000-00-00 00:00:00

    public <X> LocalDateTime wrap(X value, WrapperOptions options) {
        if ( value == null ) {
            return null;
        }

        if ( LocalDateTime.class.isInstance( value ) ) {
            return (LocalDateTime) value;
        }

        if ( Timestamp.class.isInstance( value ) ) {
            final Timestamp ts = (Timestamp) value;
            /*
             * Workaround for HHH-13266 (JDK-8061577).
             * We used to do LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ),
             * but on top of being more complex than the line below, it won't always work.
             * ts.toInstant() assumes the number of milliseconds since the epoch
             * means the same thing in Timestamp and Instant, but it doesn't, in particular before 1900.
             */
            return ts.toLocalDateTime();
        }

        if ( Long.class.isInstance( value ) ) {
            final Instant instant = Instant.ofEpochMilli( (Long) value );
            return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() );
        }

        if ( Calendar.class.isInstance( value ) ) {
            final Calendar calendar = (Calendar) value;
            return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );
        }

        if ( Date.class.isInstance( value ) ) {
            final Timestamp ts = (Timestamp) value;
            final Instant instant = Instant.ofEpochMilli( ts.getTime() );
            return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() );
        }

        throw unknownWrap( value.getClass() );
    }
hjjae2 commented 2 years ago

zeroDateTimeBehavior=convertToNull 적용 시 value = null 값으로 넘어온다.