/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.persistence.local;

import com.google.common.truth.Truth;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import org.junit.Test;

public class DateTimeResponseTest {

  public final DateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
  public final DateFormat dateFormat =
      new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());

  @Test
  public void testTimeFormat() {
    Date originalDate = new Date();
    String timeString = timeFormat.format(originalDate);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm", Locale.getDefault());
    LocalTime lt = LocalTime.parse(timeString, formatter);
    String formattedTime = lt.format(formatter);
    Truth.assertThat(timeString).isEqualTo(formattedTime);
  }

  @Test
  public void testDateFormat() {
    Date originalDate = new Date();
    String dateString = dateFormat.format(originalDate);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.getDefault());
    LocalDate ld = LocalDate.parse(dateString, formatter);
    String formattedDate = ld.format(formatter);
    Truth.assertThat(dateString).isEqualTo(formattedDate);
  }
}

@@ -662,90 +662,150 @@
 gle.
-common.truth.Truth;%0Aimport java.text.DateFormat;%0Aimport java.text.SimpleDateFormat
+android.gnd.model.observation.DateResponse;%0Aimport com.google.android.gnd.model.observation.TimeResponse;%0Aimport com.google.common.truth.Truth
 ;%0Aim
@@ -819,25 +819,23 @@
 va.time.
-LocalDate
+Instant
 ;%0Aimport
@@ -850,19 +850,19 @@
 me.Local
-Tim
+Dat
 e;%0Aimpor
@@ -877,32 +877,13 @@
 ime.
-format.DateTimeFormatter
+Month
 ;%0Aim
@@ -896,17 +896,19 @@
 ava.
-u
 ti
-l.Date
+me.ZoneId
 ;%0Aim
@@ -922,21 +922,19 @@
 va.util.
-Local
+Dat
 e;%0Aimpor
@@ -995,995 +995,627 @@
 %0A%0A  
-public final DateFormat timeFormat = new SimpleDateFormat(%22HH:mm%22, Locale.getDefault());%0A  public final DateFormat dateFormat =%0A      new SimpleDateFormat(%22yyyy-MM-dd%22, Locale.getDefault());%0A%0A  @Test%0A  public void testTimeFormat() %7B%0A    Date originalDate = new Date();
+// Sat, 23 Oct 2021 07:30:45 (Local Time)%0A  private static final Instant EXPECTED_INSTANT =%0A      LocalDate.of(2021, Month.OCTOBER, 23)%0A          .atTime(7, 30, 45)%0A          .atZone(ZoneId.systemDefault())
 %0A    
-String timeString = timeFormat.format(originalDate
+      .toInstant(
 );%0A
+%0A
   
-  DateTimeFormatter formatter = DateTimeFormatter.ofPattern(%22HH:mm%22, Locale.getDefault());%0A    LocalTime lt = LocalTime.parse(timeString, formatter);%0A    String formattedTime = lt.format(formatter);%0A    Truth.assertThat(timeString).isEqualTo(formattedTime);%0A  %7D%0A%0A  @Test%0A  public void testDateFormat() %7B%0A    Date originalDate = new Date();%0A    String dateString = dateFormat.format(originalDate);%0A    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(%22yyyy-MM-dd%22, Locale.getDefault());%0A    LocalDate ld = LocalDate.parse(dateString, formatter);%0A    String formattedDate = ld.format(formatter);%0A    Truth.assertThat(dateString).isEqualTo(formattedDate
+private Date getExpectedDate() %7B%0A    return Date.from(EXPECTED_INSTANT);%0A  %7D%0A%0A  @Test%0A  public void testTimeResponse_textDetails() %7B%0A    Truth.assertThat(new TimeResponse(getExpectedDate()).getDetailsText()).isEqualTo(%2207:30%22);%0A  %7D%0A%0A  @Test%0A  public void testDateResponse_textDetails() %7B%0A    Truth.assertThat(new DateResponse(getExpectedDate()).getDetailsText()).isEqualTo(%222021-10-23%22
 );%0A 

Fix DateTimeResponseTest to actually test DateResponse and TimeResponse