Closed b3r4t closed 1 year ago
What output do you get if you run the following code?
System.out.println(Locale.getDefault());
var formatter = DateTimeFormatter.ofPattern("E, d LLL yyyy HH:mm:ss O");
System.out.println(formatter);
var timestamp = ZonedDateTime.parse("Sat, 21 Jan 2023 11:12:30 GMT", formatter);
System.out.println(timestamp);
An exception is thrown:
de_DE
Text(DayOfWeek,SHORT)','' 'Value(DayOfMonth)' 'Text(MonthOfYear,SHORT_STANDALONE)' 'Value(YearOfEra,4,19,EXCEEDS_PAD)' 'Value(HourOfDay,2)':'Value(MinuteOfHour,2)':'Value(SecondOfMinute,2)' 'LocalizedOffset(SHORT)
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Sat, 21 Jan 2023 11:12:30 GMT' could not be parsed at index 0
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:600)
at main.Main.main(Main.java:14)
If I change the locale to English it works fine: Locale.setDefault(Locale.ENGLISH);
I don't know the implementation details of the parser, but it could respect the language property of the RSS feed: <language>en-us</language>
if available. Otherwise the parser defaults to the English locale.
DateTimeFormatter
was using system default locale. Changed it to use Locale.ENGLISH formatting when parsing timestamp strings.
Fixed by PR #77
Fixed in release 3.4.2
Thank you. Everything works now.
The method
getPubDateZonedDateTime()
returns anOptional<ZonedDateTime>
. For some reason it cannot parse the date shown in the example below:An exception is thrown
I wonder that the pubDate can't be parsed. Expected behavior: Returning an empty Optional if parsing fails. Tested with version 3.4.1.