Fix from delivery dates
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package de.jeyp91.tippliga;
|
||||
|
||||
import com.google.api.client.util.DateTime;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import de.jeyp91.gists.GistProvider;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -7,6 +9,10 @@ import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class TLWMatchesManagerBase {
|
||||
@@ -36,21 +42,63 @@ public class TLWMatchesManagerBase {
|
||||
}
|
||||
}
|
||||
|
||||
protected int getDaysDifference(Date date1, Date date2) {
|
||||
long startTime = date1.getTime();
|
||||
long endTime = date2.getTime();
|
||||
long diffTime = endTime - startTime;
|
||||
long diffDays = diffTime / (1000 * 60 * 60 * 24);
|
||||
return (int) diffDays;
|
||||
public static ArrayList<TLWMatch> getMatchesStartingFromSecondDay(ArrayList<TLWMatch> matches) {
|
||||
LocalDateTime firstMatchtime = getFirstMatchtimeTLW(matches);
|
||||
ArrayList<TLWMatch> filteredMatches = new ArrayList<>();
|
||||
for(TLWMatch match : matches) {
|
||||
LocalDateTime matchDateTime = getDate(match);
|
||||
if(getDaysDifference(matchDateTime, firstMatchtime) != 0) {
|
||||
filteredMatches.add(match);
|
||||
}
|
||||
}
|
||||
return filteredMatches;
|
||||
}
|
||||
|
||||
protected Date getDateObject(String matchdatetime) {
|
||||
Date matchDateTime = null;
|
||||
try {
|
||||
matchDateTime = new SimpleDateFormat("yyyy-MM-dd").parse(matchdatetime.substring(0, 10));
|
||||
} catch (java.text.ParseException e) {
|
||||
e.printStackTrace();
|
||||
public static LocalDateTime getFirstMatchtimeTLW(ArrayList<TLWMatch> matches) {
|
||||
LocalDateTime matchtime = null;
|
||||
for(TLWMatch match : matches) {
|
||||
LocalDateTime matchtimeTemp = getDate(match);
|
||||
if(matchtime == null) {
|
||||
matchtime = matchtimeTemp;
|
||||
} else {
|
||||
if(matchtimeTemp.isBefore(matchtime)) {
|
||||
matchtime = matchtimeTemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return matchDateTime;
|
||||
return matchtime;
|
||||
}
|
||||
|
||||
public static LocalDateTime getFirstMatchtimeAPIFootball(ArrayList<APIFootballMatch> matches) {
|
||||
LocalDateTime matchtime = null;
|
||||
for(APIFootballMatch match : matches) {
|
||||
LocalDateTime matchtimeTemp = getDate(match);
|
||||
if(matchtime == null) {
|
||||
matchtime = matchtimeTemp;
|
||||
} else {
|
||||
if(matchtimeTemp.isBefore(matchtime)) {
|
||||
matchtime = matchtimeTemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return matchtime;
|
||||
}
|
||||
|
||||
public static LocalDateTime getDate(TLWMatch match) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime dateTime = LocalDateTime.parse(match.getMatchDateTime(), formatter);
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public static LocalDateTime getDate(APIFootballMatch match) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
LocalDateTime dateTime = LocalDateTime.parse(match.getMatchDateTime().substring(0, 19), formatter);
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public static int getDaysDifference(LocalDateTime date1, LocalDateTime date2) {
|
||||
date1 = date1.toLocalDate().atTime(0, 0, 0);
|
||||
date2 = date2.toLocalDate().atTime(0, 0, 0);
|
||||
return (int) date1.until(date2, ChronoUnit.DAYS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user