Use GMT as base time (actually fix upload date)

This commit is contained in:
bopol 2020-02-06 22:24:28 +01:00
parent b671a4ba18
commit 5756df8dc7
1 changed files with 7 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.TimeZone;
import org.jsoup.helper.StringUtil; import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
@ -13,22 +13,23 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonObject;
public class PeertubeParsingHelper { public class PeertubeParsingHelper {
private PeertubeParsingHelper() { private PeertubeParsingHelper() {
} }
public static void validate(JsonObject json) throws ContentNotAvailableException { public static void validate(JsonObject json) throws ContentNotAvailableException {
String error = json.getString("error"); String error = json.getString("error");
if(!StringUtil.isBlank(error)) { if (!StringUtil.isBlank(error)) {
throw new ContentNotAvailableException(error); throw new ContentNotAvailableException(error);
} }
} }
public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException { public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
Date date; Date date;
try { try {
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'").parse(textualUploadDate); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
date = new Date(date.getTime() + TimeUnit.HOURS.toMillis(1)); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
date = sdf.parse(textualUploadDate);
} catch (ParseException e) { } catch (ParseException e) {
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e); throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
} }