diff --git a/app/src/main/java/com/loganfreeman/utahfishing/common/utils/Time.java b/app/src/main/java/com/loganfreeman/utahfishing/common/utils/Time.java index 38afe53..4f9fb6b 100644 --- a/app/src/main/java/com/loganfreeman/utahfishing/common/utils/Time.java +++ b/app/src/main/java/com/loganfreeman/utahfishing/common/utils/Time.java @@ -3,6 +3,7 @@ import android.annotation.SuppressLint; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -10,6 +11,15 @@ public class Time { public static final DateFormat df = new SimpleDateFormat("mm/dd/yyyy"); + public static Date getDate(String date) { + try { + return df.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + /** * yyyy-MM-dd HH:mm:ss diff --git a/app/src/main/java/com/loganfreeman/utahfishing/modules/fishing/domain/StockReport.java b/app/src/main/java/com/loganfreeman/utahfishing/modules/fishing/domain/StockReport.java index 396a8af..91113ce 100644 --- a/app/src/main/java/com/loganfreeman/utahfishing/modules/fishing/domain/StockReport.java +++ b/app/src/main/java/com/loganfreeman/utahfishing/modules/fishing/domain/StockReport.java @@ -32,6 +32,8 @@ import static java.util.Arrays.stream; import static com.loganfreeman.utahfishing.common.utils.Time.df; +import static com.loganfreeman.utahfishing.common.utils.Time.getDate; + /** * Created by shanhong on 3/21/17. */ @@ -96,14 +98,7 @@ public static List search(List items, String query) { return reports; } - public static Date getDate(String date) { - try { - return df.parse(date); - } catch (ParseException e) { - e.printStackTrace(); - } - return null; - } + public static List fromWildlife() throws IOException { List reports = new ArrayList(); diff --git a/app/src/test/java/com/loganfreeman/utahfishing/ExampleUnitTest.java b/app/src/test/java/com/loganfreeman/utahfishing/ExampleUnitTest.java index 444cf45..4b5e081 100644 --- a/app/src/test/java/com/loganfreeman/utahfishing/ExampleUnitTest.java +++ b/app/src/test/java/com/loganfreeman/utahfishing/ExampleUnitTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.text.ParseException; +import java.util.Calendar; import java.util.Date; import static org.junit.Assert.*; @@ -29,4 +30,15 @@ public void testCalendarDay() throws ParseException { assertEquals(calendarDay.getMonth(), 3); assertEquals(calendarDay.getYear(), 2017); } + + @Test + public void testDate() throws ParseException { + Date d = df.parse("03/11/2017"); + Calendar calendarDay = Calendar.getInstance(); + calendarDay.setTime(d); + assertEquals(calendarDay.get(Calendar.DAY_OF_MONTH), 11); + assertEquals(calendarDay.get(Calendar.MONTH), 3); + assertEquals(calendarDay.get(Calendar.YEAR), 2017); + + } } \ No newline at end of file