Ensure DSpace defaults to UTC time zone in all code / tests. This is necessary so that Spring / Hibernate don't auto-switch timezones when reading from database.

This commit is contained in:
Tim Donohue
2025-02-24 09:16:19 -06:00
parent 77f07a735b
commit 2b2d0b19b6
5 changed files with 25 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.time.ZoneOffset;
import java.util.Properties;
import java.util.TimeZone;
@@ -82,8 +83,10 @@ public class AbstractDSpaceTest {
@BeforeClass
public static void initKernel() {
try {
//set a standard time zone for the tests
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Dublin"));
// All tests should assume UTC timezone by default (unless overridden in the test itself)
// This ensures that Spring doesn't attempt to change the timezone of dates that are read from the
// database (via Hibernate). We store all dates in the database as UTC.
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.UTC));
//load the properties of the tests
testProps = new Properties();