faruktoptas/RetrofitRssConverterFactory

Date Format issue

monowar1993 opened this issue · 5 comments

the returned date through getRssItem().getPublishDate() is not in valid format some times.
example
java.text.ParseException: Unparseable date: "Tue, 03 Apr 2018 16:45:36 G"
java.text.ParseException: Unparseable date: "Sat, 07 A"

could please fix the issue. I think its a parsing issue from xml. Also if you can return Date instead of String through getRssItem().getPublishDate() then developers can format the date value as required.

@monowar1993 I used String instead of Date because the format changes depends on the content. I tried on many sites RSS contents but all of them use different date formats. So it is not possible to use Date format. The reason of your case is the same. Can you share you RSS link please I will check it?

To convert it to a Date object you must define a certain date format. If you use only one RSS link it is possible. But if you use multiple rss links, all of them should be in the same format.

but why date string that's getting parsed is like "Tue, 03 Apr 2018 16:45:36 G" or "Sat, 07 A"?
The links I used

public static final String RSS_BBC_LINK = "http://feeds.bbci.co.uk/news/health/rss.xml?edition=uk";
public static final String RSS_NY_TIMES = "http://rss.nytimes.com/services/xml/rss/nyt/Health.xml";
public static final String RSS_NY_REUTERS = "http://feeds.reuters.com/reuters/healthNews";
public static final String RSS_NY_MEDICINE_NET = "https://www.medicinenet.com/rss/dailyhealth.xml";
public static final String RSS_NY_WEBMD = "https://rssfeeds.webmd.com/rss/rss.aspx?RSSSource=RSS_PUBLIC";

I tried them all. They have different formats:

Tue, 10 Apr 2018 09:46:52 GMT
Tue, 10 Apr 2018 10:58:49 GMT
Mon, 09 Apr 2018 10:33:59 -0400
Tue, 10 Apr 2018 00:00:00 PDT
Tue, 10 Apr 2018 09:20:17 EST

If you want to convert to Date object. You should use different DateFormatters for each format.

All formats can be converted with SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss")
Can you try?

@monowar1993 I used String instead of Date because the format changes depends on the content. I tried on many sites RSS contents but all of them use different date formats. So it is not possible to use Date format. The reason of your case is the same. Can you share you RSS link please I will check it?

To convert it to a Date object you must define a certain date format. If you use only one RSS link it is possible. But if you use multiple rss links, all of them should be in the same format.