[YouTube/MediaCCC] Consider dates as GMT and not as local

This commit is contained in:
Stypox 2020-05-16 21:14:10 +02:00
parent 8ce711f40f
commit d0b14644bb
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 10 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public final class MediaCCCParsingHelper {
private MediaCCCParsingHelper() { }
@ -13,7 +14,9 @@ public final class MediaCCCParsingHelper {
public static Calendar parseDateFrom(final String textualUploadDate) throws ParsingException {
Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(textualUploadDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
date = sdf.parse(textualUploadDate);
} catch (ParseException e) {
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
}

View File

@ -185,7 +185,9 @@ public class YoutubeParsingHelper {
public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(textualUploadDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
date = sdf.parse(textualUploadDate);
} catch (ParseException e) {
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
}

View File

@ -172,10 +172,9 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
final Calendar expectedDate = Calendar.getInstance();
final Calendar actualDate = dateWrapper.date();
expectedDate.setTimeZone(TimeZone.getTimeZone("GMT"));
actualDate.setTimeZone(TimeZone.getTimeZone("GMT"));
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
expectedDate.setTime(sdf.parse(expectedUploadDate()));
assertEquals(expectedDate, actualDate);
}

View File

@ -80,7 +80,7 @@ public class PeertubeStreamExtractorTest {
@Override public long expectedLength() { return 113; }
@Override public long expectedTimestamp() { return TIMESTAMP_MINUTE*60 + TIMESTAMP_SECOND; }
@Override public long expectedViewCountAtLeast() { return 38600; }
@Nullable @Override public String expectedUploadDate() { return "2018-10-01 12:52:46.396"; } // GMT (!)
@Nullable @Override public String expectedUploadDate() { return "2018-10-01 10:52:46.396"; }
@Nullable @Override public String expectedTextualUploadDate() { return "2018-10-01T10:52:46.396Z"; }
@Override public long expectedLikeCountAtLeast() { return 120; }
@Override public long expectedDislikeCountAtLeast() { return 0; }
@ -137,7 +137,7 @@ public class PeertubeStreamExtractorTest {
}
@Override public long expectedLength() { return 512; }
@Override public long expectedViewCountAtLeast() { return 7; }
@Nullable @Override public String expectedUploadDate() { return "2019-10-22 08:16:48.982"; } // GMT (!)
@Nullable @Override public String expectedUploadDate() { return "2019-10-22 06:16:48.982"; }
@Nullable @Override public String expectedTextualUploadDate() { return "2019-10-22T06:16:48.982Z"; }
@Override public long expectedLikeCountAtLeast() { return 3; }
@Override public long expectedDislikeCountAtLeast() { return 0; }