package foodtruck.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import foodtruck.model.Location;
import foodtruck.util.Clock;

/**
 * Servlet that serves up the main food truck page.
 * @author aviolette
 * @since Jul 12, 2011
 */
@Singleton
public class FoodTruckServlet extends HttpServlet {
  private final Location mapCenter;
  private final DateTimeFormatter timeFormatter;
  private final Clock clock;
  private final DateTimeFormatter dateFormatter;

  @Inject
  public FoodTruckServlet( DateTimeZone zone, @Named("center") Location centerLocation,
      Clock clock) {
    this.clock = clock;
    this.mapCenter = centerLocation;
    this.timeFormatter = DateTimeFormat.forPattern("YYYYMMdd-HHmm").withZone(zone);
    this.dateFormatter = DateTimeFormat.forPattern("EEE MMM dd, YYYY");
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    final String path = req.getRequestURI();
    if (!Strings.isNullOrEmpty(path)) {
      req.setAttribute("showScheduleFor", path.substring(1));
    }
    final String timeRequest = req.getParameter("time");
    DateTime dateTime = null;
    if (!Strings.isNullOrEmpty(timeRequest)) {
      try {
        dateTime = timeFormatter.parseDateTime(timeRequest);
      } catch (IllegalArgumentException ignored) {
      }
    }
    if (dateTime == null) {
      dateTime = clock.now();
      // peg the time at something that actually returns results
      if (dateTime.toLocalTime().isBefore(new LocalTime(11, 30))) {
        dateTime = dateTime.withTime(11, 30, 0, 0);
      }
    }
    req.setAttribute("center", mapCenter);
    String googleAnalytics = System.getProperty("foodtruck.google.analytics", null);
    if (googleAnalytics != null) {
      req.setAttribute("google_analytics_ua", googleAnalytics);
    }
    req.setAttribute("requestDate", dateFormatter.print(dateTime));
    req.setAttribute("requestTime", timeFormatter.print(dateTime));
    req.setAttribute("requestTimeInMillis", dateTime.getMillis());
    req.getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(req, resp);
  }
}

@@ -437,40 +437,8 @@
 ne;%0A
-import org.joda.time.LocalTime;%0A
 impo
@@ -1877,201 +1877,8 @@
 ();%0A
-      // peg the time at something that actually returns results%0A      if (dateTime.toLocalTime().isBefore(new LocalTime(11, 30))) %7B%0A        dateTime = dateTime.withTime(11, 30, 0, 0);%0A      %7D%0A
     

Remove 11:30 start time since this doesn't work for mobile client.