From 07c8e189128f4fb3be7f49db75b48cf9e2e3de6e Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Fri, 12 Dec 2014 21:59:37 -0500 Subject: [PATCH] Display local Ottawa time even when server is not in that timezone --- cov.sh | 4 ++++ prod/net/jaekl/frank/Schedule.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/cov.sh b/cov.sh index 4404b78..c9fb54c 100755 --- a/cov.sh +++ b/cov.sh @@ -39,6 +39,10 @@ do TESTS="${TEST_CLASS} ${TESTS}" done +echo First run: locale es_ES, timezone Europe/Madrid +java -Duser.language=es -Duser.country=ES -Duser.timezone=Europe/Madrid -Djcov.template=${WEB_ROOT}/template.xml -Djcov.file=${WEB_ROOT}/result.xml -classpath "${INSTR_DIR}:${WEB_ROOT}/test:${CLASSPATH}:/usr/share/java/junit.jar:${WEB_ROOT}/jcov/jcov_file_saver.jar" org.junit.runner.JUnitCore ${TESTS} + +echo Second run: server default locale and timezone java -Djcov.template=${WEB_ROOT}/template.xml -Djcov.file=${WEB_ROOT}/result.xml -classpath "${INSTR_DIR}:${WEB_ROOT}/test:${CLASSPATH}:/usr/share/java/junit.jar:${WEB_ROOT}/jcov/jcov_file_saver.jar" org.junit.runner.JUnitCore ${TESTS} ##################### diff --git a/prod/net/jaekl/frank/Schedule.java b/prod/net/jaekl/frank/Schedule.java index c7fd70b..edd1b39 100644 --- a/prod/net/jaekl/frank/Schedule.java +++ b/prod/net/jaekl/frank/Schedule.java @@ -6,6 +6,7 @@ import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import net.jaekl.frank.octranspo.Route; import net.jaekl.frank.octranspo.StopInfo; @@ -22,6 +23,14 @@ public class Schedule { m_bundle = FrankBundle.getInst(locale); m_hourMinFmt = new SimpleDateFormat("hh:mma", locale); m_hourMinSecFmt = new SimpleDateFormat("hh:mm:ssa", locale); + + // We always display times in Ottawa (local) time, because that's the only + // time that makes sense for a user who wants to know when to catch a bus. + // In the (unlikely?) event that our server is in a different timezone, + // we need to explicitly specify the time zone that we want to use. + TimeZone tz = TimeZone.getTimeZone("America/Toronto"); + m_hourMinFmt.setTimeZone(tz); + m_hourMinSecFmt.setTimeZone(tz); } String trans(String key) { -- 2.39.2