Bug 512307 - Recognize and parse RFC 822 dates that use "Z" as a timezone, r=mak
authorPhil Ringnalda <philringnalda@gmail.com>
Sun, 20 Nov 2011 22:15:03 -0800
changeset 81984 38d6d2ac55e7528b6c59257b5adbde3403a817f1
parent 81983 7f8401b9f74625bde197a03b49035ca2fbb0f99d
child 81985 4ecf595875a5388e18e8592a69e806172c7d2d25
push idunknown
push userunknown
push dateunknown
reviewersmak
bugs512307
milestone11.0a1
Bug 512307 - Recognize and parse RFC 822 dates that use "Z" as a timezone, r=mak
toolkit/components/feeds/FeedProcessor.js
toolkit/components/feeds/test/xml/rss2/feed_pubDate_timezoneZ.xml
--- a/toolkit/components/feeds/FeedProcessor.js
+++ b/toolkit/components/feeds/FeedProcessor.js
@@ -868,16 +868,19 @@ function rssArrayElement(s) {
 /**
  * Tries parsing a string through the JavaScript Date object.
  * @param aDateString
  *        A string that is supposedly an RFC822 or RFC3339 date.
  * @return A Date.toUTCString, or null if the string can't be parsed.
  */
 function dateParse(aDateString) {
   let dateString = aDateString.trim();
+  // Without bug 682781 fixed, JS won't parse an RFC822 date with a Z for the
+  // timezone, so convert to -00:00 which works for any date format.
+  dateString = dateString.replace(/z$/i, "-00:00");
   let date = new Date(dateString);
   if (!isNaN(date)) {
     return date.toUTCString();
   }
   return null;
 } 
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
new file mode 100644
--- /dev/null
+++ b/toolkit/components/feeds/test/xml/rss2/feed_pubDate_timezoneZ.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+
+Description: Test whether date parsing handles "Z" as a timezone in RFC822.
+Expect:      feed.updated == 'Tue, 25 Apr 2006 08:00:00 GMT'
+
+-->
+<rss version="2.0" >
+<channel>
+<pubDate>Tue, 25 Apr 2006 08:00:00 Z</pubDate>
+</channel>
+</rss>