HHH-13580 Use safer ZoneId => TimeZone conversion in AbstractJavaTimeTypeTest
We were testing GMT instead of UTC-8 without even knowing it...
(cherry picked from commit 8fce51c765
)
This commit is contained in:
parent
58674a7ba7
commit
aef0405b5f
|
@ -191,7 +191,7 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
|
|||
|
||||
protected final void withDefaultTimeZone(Runnable runnable) {
|
||||
TimeZone timeZoneBefore = TimeZone.getDefault();
|
||||
TimeZone.setDefault( TimeZone.getTimeZone( env.defaultJvmTimeZone ) );
|
||||
TimeZone.setDefault( toTimeZone( env.defaultJvmTimeZone ) );
|
||||
/*
|
||||
* Run the code in a new thread, because some libraries (looking at you, h2 JDBC driver)
|
||||
* cache data dependent on the default timezone in thread local variables,
|
||||
|
@ -223,6 +223,23 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
|
|||
}
|
||||
}
|
||||
|
||||
private static TimeZone toTimeZone(ZoneId zoneId) {
|
||||
String idString = zoneId.getId();
|
||||
if ( idString.startsWith( "UTC+" ) || idString.startsWith( "UTC-" ) ) {
|
||||
// Apparently TimeZone doesn't understand UTC+XXX nor UTC-XXX
|
||||
// Using GMT+XXX or GMT-XXX as a fallback
|
||||
idString = "GMT" + idString.substring( "UTC".length() );
|
||||
}
|
||||
|
||||
TimeZone result = TimeZone.getTimeZone( idString );
|
||||
if ( !idString.equals( result.getID() ) ) {
|
||||
// If the timezone is not understood, getTimeZone returns GMT and the condition above is true
|
||||
throw new IllegalStateException( "Attempting to test an unsupported timezone: " + zoneId );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected final Class<? extends AbstractRemappingH2Dialect> getRemappingDialectClass() {
|
||||
return env.remappingDialectClass;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue