Merge pull request #5146 from ByteHamster/future-date

Refuse to show future dates
This commit is contained in:
ByteHamster 2021-05-08 11:40:10 +02:00 committed by GitHub
commit 3c808c1393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -29,7 +29,7 @@ public class NSDublinCore extends Namespace {
String second = state.getSecondTag().getName();
if (DATE.equals(top) && ITEM.equals(second)) {
String content = state.getContentBuf().toString();
currentItem.setPubDate(DateUtils.parse(content));
currentItem.setPubDate(DateUtils.parseOrNullIfFuture(content));
}
}
}

View File

@ -124,7 +124,7 @@ public class NSRSS20 extends Namespace {
state.getCurrentItem().setLink(content);
}
} else if (PUBDATE.equals(top) && ITEM.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
state.getCurrentItem().setPubDate(DateUtils.parseOrNullIfFuture(content));
} else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
// prefer itunes:image
if (state.getFeed() != null && state.getFeed().getImageUrl() == null) {

View File

@ -205,9 +205,9 @@ public class NSAtom extends Namespace {
state.getCurrentItem().setDescriptionIfLonger(textElement.getProcessedContent());
} else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null &&
state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
state.getCurrentItem().setPubDate(DateUtils.parseOrNullIfFuture(content));
} else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
state.getCurrentItem().setPubDate(DateUtils.parseOrNullIfFuture(content));
} else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImageUrl() == null) {
state.getFeed().setImageUrl(content);
} else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.util;
import android.content.Context;
import android.util.Log;
import androidx.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import java.text.DateFormat;
@ -122,6 +123,21 @@ public class DateUtils {
return null;
}
/**
* Parses the date but if the date is in the future, returns null.
*/
@Nullable
public static Date parseOrNullIfFuture(final String input) {
Date date = parse(input);
if (date == null) {
return null;
}
Date now = new Date();
if (date.after(now)) {
return null;
}
return date;
}
/**
* Takes a string of the form [HH:]MM:SS[.mmm] and converts it to