title: Bad startMin/startMax on get Google Calendar Entries, Google API Java Client
body: <p>I'm making the same query to get Calendar events two different ways. The odd thing is, one way it works, the other way it doesn't, even though everything is nearly exactly the same. Using the timeMin, timeMax on Google's API Explorer returns bad request for the time that the second method is sending. </p>
  
  <p>Not only that, but the Google Calendar API docs say the field should be start-min and start-max while the client and the API Explorer say the field should be timeMin and timeMax.</p>
  
  <p>Here's the code for method 1 that works:</p>
  
  <pre><code>void setPeriod() {
      Date nowDate = new Date();
      startTime = new DateTime(nowDate);
      Time t = new Time();
      t.setToNow();
      t.hour = 23;
      t.minute = 59;
      nowDate.setTime(t.toMillis(false));
      endTime = new DateTime(nowDate);
  }
  
  new AsyncTask&lt;Void, Void, Void&gt;() {
  @Override
  protected Void doInBackground(Void... params) {
      try {
      Events evlist = g.getClient().events().list(calendarIds.get(cal)).setTimeMin(startTime).setTimeMax(endTime).execute();
      if (evlist.getItems() != null) {
          //Parse the events
      ...
  }.execute();
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>new AsyncTask&lt;Void, Void, List&lt;Event&gt;&gt;() {
      @Override
  protected List&lt;Event&gt; doInBackground(Void... arg0) {
      Date nowDate = new Date();
      DateTime startTime = new DateTime(nowDate);
      Time t = new Time();
      t.setToNow();
      t.hour = 23;
      t.minute = 59;
      nowDate.setTime(t.toMillis(true));
      DateTime endTime = new DateTime(nowDate);
      Calendar client = com.google.api.services.calendar.Calendar
                  .builder(transport, jsonFactory)
                  .setApplicationName("Wayk by Senti")
                  .setHttpRequestInitializer(
                      new HttpRequestInitializer() {
                          public void initialize(HttpRequest request)
                                          throws IOException {
                                      request.getHeaders()
                                              .setAuthorization(
                                                      GoogleHeaders
                                                              .getGoogleLoginValue(authToken));
                                  }
                              })
                      .setJsonHttpRequestInitializer(
                              new JsonHttpRequestInitializer() {
  
                                  public void initialize(
                                          JsonHttpRequest request)
                                          throws IOException {
                                      CalendarRequest calendarRequest = (CalendarRequest) request;
                                      calendarRequest
                                              .setKey(CalendarClientCredentials.KEY);
                                  }
                              }).build();
              try {
                  List&lt;Event&gt; events = new ArrayList&lt;Event&gt;();
                  for (int i = currentCal; i &lt; enables.size(); i++) {
                      if (enables.get(i)) {
                          AiLog.v("Getting events");
                          AiLog.v("AuthToken: " + authToken);
                          AiLog.v("CalendarID: " + calendarIds.get(i));
                          AiLog.v("Calendar name: " + calendarNames.get(i));
                          AiLog.v("Calendar account: " + account);
                          Calendar.Events.List eventReq = client.events()
                                  .list(calendarIds.get(i)).setTimeMin(startTime).setTimeMax(endTime).execute();//Bad request here
  </code></pre>
  
  <p>Note that the client is exactly the same for both. The client in the second method successfully grabs the list of calendars for the account. I have verified that the calendar ID is correct, which leaves me with the error coming from startMin and startMax.</p>
  
  <p>Any help appreciated.</p>
  
  <p>Cheers, Z</p>