Permalink
Browse files

somewhat less dubious way to find time of day

  • Loading branch information...
1 parent 8686e6f commit e8533d0067a65b333735beb95fadc719e266e30e @abyrd abyrd committed Jun 26, 2012
@@ -127,6 +127,8 @@
* this should ideally be done when setting the routing context, but at present departure/
* arrival time is stored in the request as an epoch time with the TZ already resolved, and other
* code depends on this behavior. (AMB)
+ * Alternatively, we could eliminate the separate RoutingRequest objects and just resolve
+ * vertices and timezones here right away, but just ignore them in semantic equality checks.
*/
@Autowired GraphService graphService;
@@ -14,7 +14,9 @@
package org.opentripplanner.util;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
@@ -53,12 +55,16 @@ static public Date toDate(String date, String time, TimeZone tz) {
if (d != null && s != null)
retVal = new Date(d.getTime() + s * 1000);
} else if (time != null) {
- Integer s = secPastMid(time);
+ // we could just set the Calendar fields directly instead of using secPastMidnight
+ Integer s = secPastMid(time);
if (s != null && s > 0) {
- // ??? replace String manipulation with Calendar.set hack or JodaTime (AMB)
- String p = formatDate(DATE_FORMAT, retVal, tz);
- Date d = parseDate(p, tz);
- retVal = new Date(d.getTime() + s * 1000);
+ // Maybe we should be using JodaTime... (AMB)
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ retVal = new Date(cal.getTimeInMillis() + s * 1000);
}
}
LOG.debug( "resulting date is {}", retVal);

0 comments on commit e8533d0

Please sign in to comment.