HHH-18065 Truncate date related milliseconds from value passed to java.sql.Time

This commit is contained in:
Christian Beikov 2024-05-03 14:43:40 +02:00
parent 17fec64fd7
commit 75e1f17139
7 changed files with 17 additions and 13 deletions

View File

@ -102,7 +102,7 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType<Calendar> {
return (X) new java.sql.Date( value.getTimeInMillis() );
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Time( value.getTimeInMillis() );
return (X) new java.sql.Time( value.getTimeInMillis() % 86_400_000 );
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Timestamp( value.getTimeInMillis() );

View File

@ -119,7 +119,7 @@ public class CalendarJavaType extends AbstractTemporalJavaType<Calendar> impleme
return (X) new java.sql.Date( value.getTimeInMillis() );
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Time( value.getTimeInMillis() );
return (X) new java.sql.Time( value.getTimeInMillis() % 86_400_000 );
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Timestamp( value.getTimeInMillis() );

View File

@ -104,7 +104,7 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType<Calendar> {
return (X) new java.sql.Date( value.getTimeInMillis() );
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Time( value.getTimeInMillis() );
return (X) new java.sql.Time( value.getTimeInMillis() % 86_400_000 );
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Timestamp( value.getTimeInMillis() );

View File

@ -125,7 +125,7 @@ public class DateJavaType extends AbstractTemporalJavaType<Date> implements Vers
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
final java.sql.Time rtn = value instanceof java.sql.Time
? ( java.sql.Time ) value
: new java.sql.Time( value.getTime() );
: new java.sql.Time( value.getTime() % 86_400_000 );
return (X) rtn;
}
if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {

View File

@ -123,7 +123,7 @@ public class InstantJavaType extends AbstractTemporalJavaType<Instant>
}
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return (X) new java.sql.Time( instant.toEpochMilli() );
return (X) new java.sql.Time( instant.toEpochMilli() % 86_400_000 );
}
if ( Date.class.isAssignableFrom( type ) ) {

View File

@ -131,7 +131,7 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType<Date> {
if ( LocalTime.class.isAssignableFrom( type ) ) {
final Time time = value instanceof java.sql.Time
? ( (java.sql.Time) value )
: new java.sql.Time( value.getTime() );
: new java.sql.Time( value.getTime() % 86_400_000 );
final LocalTime localTime = time.toLocalTime();
final long millis = time.getTime() % 1000;
if ( millis == 0 ) {
@ -143,7 +143,7 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType<Date> {
if ( Time.class.isAssignableFrom( type ) ) {
return value instanceof Time
? value
: new Time( value.getTime() );
: new Time( value.getTime() % 86_400_000 );
}
if ( Date.class.isAssignableFrom( type ) ) {
@ -181,6 +181,14 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType<Date> {
return null;
}
if ( value instanceof Time ) {
return (Date) value;
}
if ( value instanceof Date ) {
return new Time( ( (Date) value ).getTime() % 86_400_000 );
}
if ( value instanceof LocalTime ) {
final LocalTime localTime = (LocalTime) value;
final Time time = Time.valueOf( localTime );
@ -191,16 +199,12 @@ public class JdbcTimeJavaType extends AbstractTemporalJavaType<Date> {
return new Time( time.getTime() + DateTimeUtils.roundToPrecision( localTime.getNano(), 3 ) / 1000000 );
}
if ( value instanceof Date ) {
return (Date) value;
}
if ( value instanceof Long ) {
return new Time( (Long) value );
}
if ( value instanceof Calendar ) {
return new Time( ( (Calendar) value ).getTimeInMillis() );
return new Time( ( (Calendar) value ).getTimeInMillis() % 86_400_000 );
}
throw unknownWrap( value.getClass() );

View File

@ -158,7 +158,7 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType<Date> implem
if ( java.sql.Time.class.isAssignableFrom( type ) ) {
return value instanceof java.sql.Time
? ( java.sql.Time ) value
: new java.sql.Time( value.getTime() );
: new java.sql.Time( value.getTime() % 86_400_000 );
}
throw unknownUnwrap( type );