Skip to content

Commit b42a196

Browse files
authored
Merge pull request #454 from Isira-Seneviratne/Fix_date_time_issues
Fix some issues related to the date/time changes.
2 parents b13c7e1 + 4fe28d7 commit b42a196

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public DateWrapper(@NonNull Calendar calendar) {
2828
*/
2929
@Deprecated
3030
public DateWrapper(@NonNull Calendar calendar, boolean isApproximation) {
31-
offsetDateTime = OffsetDateTime.ofInstant(calendar.toInstant(), ZoneOffset.UTC);
32-
this.isApproximation = isApproximation;
31+
this(OffsetDateTime.ofInstant(calendar.toInstant(), ZoneOffset.UTC), isApproximation);
3332
}
3433

3534
public DateWrapper(@NonNull OffsetDateTime offsetDateTime) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.net.MalformedURLException;
2222
import java.net.URL;
2323
import java.net.URLDecoder;
24+
import java.time.LocalDate;
2425
import java.time.OffsetDateTime;
26+
import java.time.ZoneOffset;
2527
import java.time.format.DateTimeParseException;
2628
import java.util.Collections;
2729
import java.util.HashMap;
@@ -184,7 +186,11 @@ public static OffsetDateTime parseDateFrom(String textualUploadDate) throws Pars
184186
try {
185187
return OffsetDateTime.parse(textualUploadDate);
186188
} catch (DateTimeParseException e) {
187-
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e);
189+
try {
190+
return LocalDate.parse(textualUploadDate).atStartOfDay().atOffset(ZoneOffset.UTC);
191+
} catch (DateTimeParseException e1) {
192+
throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e1);
193+
}
188194
}
189195
}
190196

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import javax.annotation.Nullable;
1010
import java.time.OffsetDateTime;
11-
import java.time.format.DateTimeFormatter;
1211
import java.time.format.DateTimeParseException;
1312

1413
public class YoutubeFeedInfoItemExtractor implements StreamInfoItemExtractor {
@@ -61,7 +60,7 @@ public String getTextualUploadDate() {
6160
@Override
6261
public DateWrapper getUploadDate() throws ParsingException {
6362
try {
64-
return new DateWrapper(OffsetDateTime.parse(getTextualUploadDate(), DateTimeFormatter.ISO_OFFSET_DATE_TIME));
63+
return new DateWrapper(OffsetDateTime.parse(getTextualUploadDate()));
6564
} catch (DateTimeParseException e) {
6665
throw new ParsingException("Could not parse date (\"" + getTextualUploadDate() + "\")", e);
6766
}

0 commit comments

Comments
 (0)