X-Git-Url: http://jaekl.net/gitweb/?p=frank.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Ffrank%2FSchedule.java;h=eb8cb2bce26cee168d800d2baef13770ff96c580;hp=c7fd70bfcd3a7b5ed991bdaf537b9bf762af6971;hb=2dcf5c21337e4b12e56c3520828edfc062ce7338;hpb=24f097b0fe78fa44f99b9f6f2e51a8e689d86a4a diff --git a/prod/net/jaekl/frank/Schedule.java b/prod/net/jaekl/frank/Schedule.java index c7fd70b..eb8cb2b 100644 --- a/prod/net/jaekl/frank/Schedule.java +++ b/prod/net/jaekl/frank/Schedule.java @@ -6,22 +6,33 @@ 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; import net.jaekl.frank.octranspo.Trip; public class Schedule { - Locale m_locale; - FrankBundle m_bundle; DateFormat m_hourMinFmt; DateFormat m_hourMinSecFmt; + FrankBundle m_bundle; + Locale m_locale; + Style m_style; public Schedule(Locale locale) { m_locale = locale; + m_style = new Style(); 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) { @@ -31,17 +42,7 @@ public class Schedule { String mapUrl(double latitude, double longitude) { return "http://www.openstreetmap.org/?mlat=" + latitude + "&mlon=" + longitude + "&zoom=15"; } - - void writeStyle(PrintWriter pw) { - pw.println(""); - } - + // Countdown timer that updates time remaining until each bus is expected. void writeScript(PrintWriter pw, String remainArray, int remainCount) { String min = trans(FrankBundle.MINUTES); @@ -61,7 +62,7 @@ public class Schedule { pw.println(" if (remain_delta <= 0) {"); pw.println(" element.innerHTML = \"----\";"); pw.println(" } else {"); - pw.println(" element.innerHTML = (Math.floor(remain_delta / 60)) + \"" + trans(min) + "\";"); + pw.println(" element.innerHTML = (Math.floor(remain_delta / 60)) + \"" + min + "\";"); pw.println(" }"); pw.println(" }"); pw.println("}"); @@ -73,7 +74,7 @@ public class Schedule { pw.println(""); pw.println(""); pw.println("" + title + ""); - writeStyle(pw); + new Style().writeStyle(pw); pw.println(""); } @@ -106,7 +107,7 @@ public class Schedule { Route route = stopInfo.getRoute(routeIdx); for (int tripIdx = 0; tripIdx < route.getNumTrips(); ++tripIdx) { Trip trip = route.getTrip(tripIdx); - boolean isGhost = ((-1) == trip.getAdjAge()); + boolean isGhost = (trip.getAdjAge() < 0); if (isGhost) { // GPS is off. This bus may not exist. pw.println(" "); @@ -124,7 +125,7 @@ public class Schedule { remainArray.append(trip.getAdjTime()); remainCount++; - if (trip.getAdjAge() < 0) { + if (isGhost) { pw.println(" " + trans(FrankBundle.GPS_OFF) + ""); } else {