Fix time parsing/display in EPG. Always use UTC for parsing datetimes.
This commit is contained in:
parent
4d7acd80d0
commit
b56384ac16
|
@ -4,6 +4,12 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import org.xbmc.kore.utils.JsonUtils;
|
import org.xbmc.kore.utils.JsonUtils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Types from PVR.*
|
* Types from PVR.*
|
||||||
*/
|
*/
|
||||||
|
@ -98,7 +104,6 @@ public class PVRType {
|
||||||
public static final String WASACTIVE = "wasactive";
|
public static final String WASACTIVE = "wasactive";
|
||||||
|
|
||||||
public final int broadcastid;
|
public final int broadcastid;
|
||||||
public final String endtime;
|
|
||||||
public final String episodename;
|
public final String episodename;
|
||||||
public final int episodenum;
|
public final int episodenum;
|
||||||
public final int episodepart;
|
public final int episodepart;
|
||||||
|
@ -113,10 +118,11 @@ public class PVRType {
|
||||||
public final double progresspercentage;
|
public final double progresspercentage;
|
||||||
public final int rating;
|
public final int rating;
|
||||||
public final int runtime;
|
public final int runtime;
|
||||||
public final String starttime;
|
|
||||||
public final String thumbnail;
|
public final String thumbnail;
|
||||||
public final String title;
|
public final String title;
|
||||||
public final boolean wasactive;
|
public final boolean wasactive;
|
||||||
|
public Date starttime;
|
||||||
|
public Date endtime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -125,7 +131,6 @@ public class PVRType {
|
||||||
public DetailsBroadcast(JsonNode node) {
|
public DetailsBroadcast(JsonNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
broadcastid = JsonUtils.intFromJsonNode(node, BROADCASTID);
|
broadcastid = JsonUtils.intFromJsonNode(node, BROADCASTID);
|
||||||
endtime = JsonUtils.stringFromJsonNode(node, ENDTIME);
|
|
||||||
episodename = JsonUtils.stringFromJsonNode(node, EPISODENAME);
|
episodename = JsonUtils.stringFromJsonNode(node, EPISODENAME);
|
||||||
episodenum = JsonUtils.intFromJsonNode(node, EPISODENUM, 0);
|
episodenum = JsonUtils.intFromJsonNode(node, EPISODENUM, 0);
|
||||||
episodepart = JsonUtils.intFromJsonNode(node, EPISODEPART, 0);
|
episodepart = JsonUtils.intFromJsonNode(node, EPISODEPART, 0);
|
||||||
|
@ -140,10 +145,20 @@ public class PVRType {
|
||||||
progresspercentage = JsonUtils.doubleFromJsonNode(node, PROGRESSPERCENTAGE, 0);
|
progresspercentage = JsonUtils.doubleFromJsonNode(node, PROGRESSPERCENTAGE, 0);
|
||||||
rating = JsonUtils.intFromJsonNode(node, RATING, 0);
|
rating = JsonUtils.intFromJsonNode(node, RATING, 0);
|
||||||
runtime = JsonUtils.intFromJsonNode(node, RUNTIME, 0);
|
runtime = JsonUtils.intFromJsonNode(node, RUNTIME, 0);
|
||||||
starttime = JsonUtils.stringFromJsonNode(node, STARTTIME);
|
|
||||||
thumbnail = JsonUtils.stringFromJsonNode(node, THUMBNAIL);
|
thumbnail = JsonUtils.stringFromJsonNode(node, THUMBNAIL);
|
||||||
title = JsonUtils.stringFromJsonNode(node, TITLE);
|
title = JsonUtils.stringFromJsonNode(node, TITLE);
|
||||||
wasactive = JsonUtils.booleanFromJsonNode(node, WASACTIVE, false);
|
wasactive = JsonUtils.booleanFromJsonNode(node, WASACTIVE, false);
|
||||||
|
|
||||||
|
// Get times. All in UTC
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
try {
|
||||||
|
endtime = sdf.parse(JsonUtils.stringFromJsonNode(node, ENDTIME));
|
||||||
|
starttime = sdf.parse(JsonUtils.stringFromJsonNode(node, STARTTIME));
|
||||||
|
} catch (ParseException exc) {
|
||||||
|
starttime = new Date();
|
||||||
|
endtime = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
|
@ -231,19 +232,8 @@ public class PVRChannelEPGListFragment extends Fragment
|
||||||
String duration = String.format(this.getContext().getString(R.string.minutes_abbrev2),
|
String duration = String.format(this.getContext().getString(R.string.minutes_abbrev2),
|
||||||
String.valueOf(broadcastDetails.runtime));
|
String.valueOf(broadcastDetails.runtime));
|
||||||
|
|
||||||
// Parse dates
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
|
||||||
Date startTime, endTime;
|
|
||||||
try {
|
|
||||||
startTime = sdf.parse(broadcastDetails.starttime);
|
|
||||||
// endTime = sdf.parse(broadcastDetails.endtime);
|
|
||||||
} catch (ParseException exc) {
|
|
||||||
startTime = new Date();
|
|
||||||
// endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
int flags = DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME;
|
int flags = DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME;
|
||||||
viewHolder.startTimeView.setText(DateUtils.formatDateTime(getActivity(), startTime.getTime(), flags));
|
viewHolder.startTimeView.setText(DateUtils.formatDateTime(getActivity(), broadcastDetails.starttime.getTime(), flags));
|
||||||
viewHolder.endTimeView.setText(duration);
|
viewHolder.endTimeView.setText(duration);
|
||||||
} else {
|
} else {
|
||||||
// For a day
|
// For a day
|
||||||
|
@ -307,34 +297,24 @@ public class PVRChannelEPGListFragment extends Fragment
|
||||||
* @return List of rows to show
|
* @return List of rows to show
|
||||||
*/
|
*/
|
||||||
public static List<EPGListRow> buildFromBroadcastList(List<PVRType.DetailsBroadcast> broadcasts) {
|
public static List<EPGListRow> buildFromBroadcastList(List<PVRType.DetailsBroadcast> broadcasts) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
Date currentTime = new Date();
|
||||||
Date currentTime = new Date(),
|
|
||||||
startTime, endTime;
|
|
||||||
int previousDayIdx = 0, dayIdx;
|
int previousDayIdx = 0, dayIdx;
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|
||||||
List<EPGListRow> result = new ArrayList<>(broadcasts.size() + 5);
|
List<EPGListRow> result = new ArrayList<>(broadcasts.size() + 5);
|
||||||
|
|
||||||
for (PVRType.DetailsBroadcast broadcast: broadcasts) {
|
for (PVRType.DetailsBroadcast broadcast: broadcasts) {
|
||||||
try {
|
|
||||||
startTime = sdf.parse(broadcast.starttime);
|
|
||||||
endTime = sdf.parse(broadcast.endtime);
|
|
||||||
} catch (ParseException exc) {
|
|
||||||
startTime = new Date();
|
|
||||||
endTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore if before current time
|
// Ignore if before current time
|
||||||
if (endTime.before(currentTime)) {
|
if (broadcast.endtime.before(currentTime)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
cal.setTime(startTime);
|
cal.setTime(broadcast.starttime);
|
||||||
dayIdx = cal.get(Calendar.YEAR) * 366 + cal.get(Calendar.DATE);
|
dayIdx = cal.get(Calendar.YEAR) * 366 + cal.get(Calendar.DATE);
|
||||||
if (dayIdx > previousDayIdx) {
|
if (dayIdx > previousDayIdx) {
|
||||||
// New day, add a row representing it to the list
|
// New day, add a row representing it to the list
|
||||||
previousDayIdx = dayIdx;
|
previousDayIdx = dayIdx;
|
||||||
result.add(new EPGListRow(startTime));
|
result.add(new EPGListRow(broadcast.starttime));
|
||||||
}
|
}
|
||||||
result.add(new EPGListRow(broadcast));
|
result.add(new EPGListRow(broadcast));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue