Introduce class that indicates when the time ago is an approximation
This commit is contained in:
@@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services;
|
||||
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
|
||||
import java.util.Calendar;
|
||||
@@ -31,9 +32,9 @@ public final class DefaultTests {
|
||||
|
||||
final String textualUploadDate = streamInfoItem.getTextualUploadDate();
|
||||
if (textualUploadDate != null && !textualUploadDate.isEmpty()) {
|
||||
final Calendar uploadDate = streamInfoItem.getUploadDate();
|
||||
final DateWrapper uploadDate = streamInfoItem.getUploadDate();
|
||||
assertNotNull("No parsed upload date", uploadDate);
|
||||
assertTrue("Upload date not in the past", uploadDate.before(Calendar.getInstance()));
|
||||
assertTrue("Upload date not in the past", uploadDate.date().before(Calendar.getInstance()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
|
||||
|
||||
@@ -95,6 +96,6 @@ public class MediaCCCStreamExtractorTest implements BaseExtractorTest {
|
||||
public void testGetUploadDate() throws ParsingException, ParseException {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2018-05-11"));
|
||||
Assert.assertEquals(instance, extractor.getUploadDate());
|
||||
assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
@@ -80,7 +81,7 @@ public class SoundcloudStreamExtractorDefaultTest {
|
||||
public void testGetUploadDate() throws ParsingException, ParseException {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss +0000").parse("2016/07/31 18:18:07 +0000"));
|
||||
Assert.assertEquals(instance, extractor.getUploadDate());
|
||||
assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.localization.Localization;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -61,9 +62,9 @@ public class YoutubeChannelLocalizationTest {
|
||||
String debugMessage = "[" + String.format("%02d", i) + "] "
|
||||
+ currentLocalization.getLocalizationCode() + " → " + item.getName()
|
||||
+ "\n:::: " + item.getStreamType() + ", views = " + item.getViewCount();
|
||||
final Calendar uploadDate = item.getUploadDate();
|
||||
final DateWrapper uploadDate = item.getUploadDate();
|
||||
if (uploadDate != null) {
|
||||
String dateAsText = dateFormat.format(uploadDate.getTime());
|
||||
String dateAsText = dateFormat.format(uploadDate.date().getTime());
|
||||
debugMessage += "\n:::: " + item.getTextualUploadDate() +
|
||||
"\n:::: " + dateAsText;
|
||||
}
|
||||
@@ -102,17 +103,17 @@ public class YoutubeChannelLocalizationTest {
|
||||
final StreamInfoItem referenceItem = referenceList.get(i);
|
||||
final StreamInfoItem currentItem = currentList.get(i);
|
||||
|
||||
final Calendar referenceUploadDate = referenceItem.getUploadDate();
|
||||
final Calendar currentUploadDate = currentItem.getUploadDate();
|
||||
final DateWrapper referenceUploadDate = referenceItem.getUploadDate();
|
||||
final DateWrapper currentUploadDate = currentItem.getUploadDate();
|
||||
|
||||
final String referenceDateString = referenceUploadDate == null ? "null" :
|
||||
dateFormat.format(referenceUploadDate.getTime());
|
||||
dateFormat.format(referenceUploadDate.date().getTime());
|
||||
final String currentDateString = currentUploadDate == null ? "null" :
|
||||
dateFormat.format(currentUploadDate.getTime());
|
||||
dateFormat.format(currentUploadDate.date().getTime());
|
||||
|
||||
long difference = -1;
|
||||
if (referenceUploadDate != null && currentUploadDate != null) {
|
||||
difference = Math.abs(referenceUploadDate.getTimeInMillis() - currentUploadDate.getTimeInMillis());
|
||||
difference = Math.abs(referenceUploadDate.date().getTimeInMillis() - currentUploadDate.date().getTimeInMillis());
|
||||
}
|
||||
|
||||
final boolean areTimeEquals = difference < 5 * 60 * 1000L;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.stream;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.DownloaderTestImpl;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
@@ -18,9 +17,9 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
@@ -93,7 +92,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest {
|
||||
public void testGetUploadDate() throws ParsingException, ParseException {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2017-01-25"));
|
||||
assertEquals(instance, extractor.getUploadDate());
|
||||
assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
@@ -92,7 +93,7 @@ public class YoutubeStreamExtractorControversialTest {
|
||||
public void testGetUploadDate() throws ParsingException, ParseException {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2010-09-09"));
|
||||
assertEquals(instance, extractor.getUploadDate());
|
||||
assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,9 +17,9 @@ import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
@@ -119,7 +119,7 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
public void testGetUploadDate() throws ParsingException, ParseException {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2015-10-22"));
|
||||
Assert.assertEquals(instance, extractor.getUploadDate());
|
||||
assertEquals(instance, requireNonNull(extractor.getUploadDate()).date());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user