Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhong cheng committed Mar 24, 2017
1 parent 9840a38 commit 3aa7f13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
import android.annotation.SuppressLint;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -96,14 +98,7 @@ public static List<StockReport> search(List<StockReport> 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<StockReport> fromWildlife() throws IOException {
List<StockReport> reports = new ArrayList<StockReport>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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);

}
}

0 comments on commit 3aa7f13

Please sign in to comment.