From 5544035e53cb56a0ed3e93ef53dba54d381c12e4 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 13 Jun 2012 21:22:50 +0200 Subject: [PATCH] Created class for parsing RSS 2 date formats --- .../syndication/namespace/rss20/NSRSS20.java | 2 + .../syndication/util/SyndDateUtils.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/de/podfetcher/syndication/util/SyndDateUtils.java diff --git a/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java b/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java index 9b97c1f89..aee611db0 100644 --- a/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java +++ b/src/de/podfetcher/syndication/namespace/rss20/NSRSS20.java @@ -1,6 +1,7 @@ package de.podfetcher.syndication.namespace.rss20; import java.util.ArrayList; +import java.util.Date; import de.podfetcher.feed.Feed; import de.podfetcher.feed.FeedImage; @@ -10,6 +11,7 @@ import de.podfetcher.syndication.handler.HandlerState; import de.podfetcher.syndication.handler.SyndHandler; import de.podfetcher.syndication.namespace.Namespace; import de.podfetcher.syndication.namespace.SyndElement; +import de.podfetcher.syndication.util.SyndDateUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; diff --git a/src/de/podfetcher/syndication/util/SyndDateUtils.java b/src/de/podfetcher/syndication/util/SyndDateUtils.java new file mode 100644 index 000000000..019e82b75 --- /dev/null +++ b/src/de/podfetcher/syndication/util/SyndDateUtils.java @@ -0,0 +1,40 @@ +package de.podfetcher.syndication.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import android.util.Log; + +/** Parses several date formats. */ +public class SyndDateUtils { + private static final String TAG = "DateUtils"; + private static final String RFC822 = "dd MMM yyyy HH:mm:ss Z"; + /** RFC 822 date format with day of the week. */ + private static final String RFC822DAY = "EEE, " + RFC822; + + public static Date parseRFC822Date(String date) { + Date result = null; + SimpleDateFormat format = new SimpleDateFormat(RFC822DAY); + try { + result = format.parse(date); + } catch(ParseException e) { + format = new SimpleDateFormat(RFC822); + try { + result = format.parse(date); + } catch (ParseException e1) { + e1.printStackTrace(); + } + } + if (result != null) { + Log.d(TAG, "Day is " + result.getDay()); + Log.d(TAG, "Hours is " + result.getHours()); + Log.d(TAG, "Minutes is " + result.getMinutes()); + Log.d(TAG, "Seconds is" + result.getSeconds()); + Log.d(TAG, "Month is " + result.getMonth()); + Log.d(TAG, "Year is " + result.getYear()); + Log.d(TAG, format.format(result)); + } + return result; + } +}