summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-13 23:28:46 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-13 23:28:46 +0200
commitbf70d0b3bf1b44a2416b9963e75850be301c0e00 (patch)
tree283966d96d1d74d08e200c62f64d8ecd0043b46e
parent5544035e53cb56a0ed3e93ef53dba54d381c12e4 (diff)
downloadAntennaPod-bf70d0b3bf1b44a2416b9963e75850be301c0e00.zip
Added date parser for timestamps in Atom feeds
-rw-r--r--src/de/podfetcher/syndication/util/SyndDateUtils.java35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/de/podfetcher/syndication/util/SyndDateUtils.java b/src/de/podfetcher/syndication/util/SyndDateUtils.java
index 019e82b75..d081e684e 100644
--- a/src/de/podfetcher/syndication/util/SyndDateUtils.java
+++ b/src/de/podfetcher/syndication/util/SyndDateUtils.java
@@ -13,12 +13,19 @@ public class SyndDateUtils {
/** RFC 822 date format with day of the week. */
private static final String RFC822DAY = "EEE, " + RFC822;
- public static Date parseRFC822Date(String date) {
+ /** RFC 3339 date format for UTC dates. */
+ private static final String RFC3339UTC = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+
+ /** RFC 3339 date format for localtime dates with offset. */
+ private static final String RFC3339LOCAL = "yyyy-MM-dd'T'HH:mm:ssZ";
+
+
+ public static Date parseRFC822Date(final String date) {
Date result = null;
SimpleDateFormat format = new SimpleDateFormat(RFC822DAY);
try {
result = format.parse(date);
- } catch(ParseException e) {
+ } catch (ParseException e) {
format = new SimpleDateFormat(RFC822);
try {
result = format.parse(date);
@@ -37,4 +44,28 @@ public class SyndDateUtils {
}
return result;
}
+
+ public static Date parseRFC3339Date(final String date) {
+ Date result = null;
+ SimpleDateFormat format = null;
+ if (date.endsWith("Z")) {
+ format = new SimpleDateFormat(RFC3339UTC);
+ } else {
+ format = new SimpleDateFormat(RFC3339LOCAL);
+ // remove last colon
+ StringBuffer buf = new StringBuffer(date.length() - 1);
+ int colonIdx = date.lastIndexOf(':');
+ for (int x = 0; x < date.length(); x++) {
+ if (x != colonIdx) buf.append(date.charAt(x));
+ }
+ String bufStr = buf.toString();
+ }
+ try {
+ result = format.parse(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return result;
+
+ }
}