HHH-13580 Use safer ZoneId => TimeZone conversion in AbstractJavaTimeTypeTest

We were testing GMT instead of UTC-8 without even knowing it...
This commit is contained in:
Yoann Rodière 2019-08-26 11:44:53 +02:00 committed by gbadner
parent f9f6793232
commit 8fce51c765
1 changed files with 18 additions and 1 deletions

View File

@ -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;
}