Skip to content

Commit 9355798

Browse files
Reduce some lines of code
1 parent a84d831 commit 9355798

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,16 @@ public String toString() {
9191
}
9292

9393
public static DateWrapper fromOffsetDateTime(final String date) throws ParsingException {
94-
if (date == null) {
95-
return null;
96-
}
9794
try {
98-
return new DateWrapper(OffsetDateTime.parse(date));
95+
return date != null ? new DateWrapper(OffsetDateTime.parse(date)) : null;
9996
} catch (final DateTimeParseException e) {
10097
throw new ParsingException("Could not parse date: \"" + date + "\"", e);
10198
}
10299
}
103100

104101
public static DateWrapper fromInstant(final String date) throws ParsingException {
105-
if (date == null) {
106-
return null;
107-
}
108102
try {
109-
return new DateWrapper(Instant.parse(date));
103+
return date != null ? new DateWrapper(Instant.parse(date)) : null;
110104
} catch (final DateTimeParseException e) {
111105
throw new ParsingException("Could not parse date: \"" + date + "\"", e);
112106
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
import java.io.IOException;
8888
import java.nio.charset.StandardCharsets;
8989
import java.time.LocalDate;
90-
import java.time.OffsetDateTime;
9190
import java.time.format.DateTimeFormatter;
9291
import java.time.format.DateTimeParseException;
9392
import java.util.ArrayList;
@@ -211,13 +210,9 @@ public String getTextualUploadDate() throws ParsingException {
211210
@Override
212211
public DateWrapper getUploadDate() throws ParsingException {
213212
final String dateText = getTextualUploadDate();
214-
if (dateText == null) {
215-
return null;
216-
}
217-
218213
try {
219-
return new DateWrapper(OffsetDateTime.parse(dateText));
220-
} catch (final DateTimeParseException e) {
214+
return DateWrapper.fromOffsetDateTime(dateText);
215+
} catch (final ParsingException e) {
221216
// Try other patterns first
222217
}
223218

0 commit comments

Comments
 (0)