We'd like our Play Framework 2.0 Scala applications to handle all date and time information in UTC, both in the app servers and in MySQL database servers.
The trick is:
- Without changing deployment environment
- Without changing CI (testing) environment
- Without changing local (dev) environment
Is there a standard best practice to do this? We want the tests to run in UTC, without having to pass -Duser.timezone=GMT
on all commandlines. Ditto for bringing up servers with play start
.
This was easier than we'd expected.
First, in
application.conf
, configure the JDBC URL with the parameters as described on another StackOverflow question:Second, in
Build.scala
, set the Java system property and the default:These two changes together will handle both test (
play test
) and development (play start
) modes.For production (
play dist
), one must still set the property before launch. For example, by:start
script to addexport _JAVA_OPTIONS=-Duser.timezone=GMT
start
script with-Duser.timezone=GMT
System.setProperty("user.timezone", "GMT")