Bug 618714 - Switch feed parser to using Date object's support for ISO8601 dates, r=mak
authorPhil Ringnalda <philringnalda@gmail.com>
Sun, 26 Jun 2011 18:53:48 -0700
changeset 73951 a62c4c474f2678b8186eb30a732701c37f18d8e4
parent 73950 eef25ec2d58e3f7d845438209ba2d95c44f0e441
child 73952 f414db34c70b738ab80e275c80178feac888cea6
child 105075 e87b5d87406e3d0a1b067a8c5100ceb2c3d9feef
push id20933
push userphilringnalda@gmail.com
push dateMon, 08 Aug 2011 01:24:45 +0000
treeherdermozilla-central@a62c4c474f26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs618714
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 618714 - Switch feed parser to using Date object's support for ISO8601 dates, r=mak
toolkit/components/feeds/FeedProcessor.js
toolkit/components/feeds/test/xml/rfc4287/feed_updated.xml
--- a/toolkit/components/feeds/FeedProcessor.js
+++ b/toolkit/components/feeds/FeedProcessor.js
@@ -41,17 +41,16 @@
 function LOG(str) {
   dump("*** " + str + "\n");
 }
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cr = Components.results;
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import("resource://gre/modules/ISO8601DateUtils.jsm");
 
 const FP_CONTRACTID = "@mozilla.org/feed-processor;1";
 const FP_CLASSID = Components.ID("{26acb1f0-28fc-43bc-867a-a46aabc85dd4}");
 const FP_CLASSNAME = "Feed Processor";
 const FR_CONTRACTID = "@mozilla.org/feed-result;1";
 const FR_CLASSID = Components.ID("{072a5c3d-30c6-4f07-b87f-9f63d51403f2}");
 const FR_CLASSNAME = "Feed Result";
 const FEED_CONTRACTID = "@mozilla.org/feed;1";
@@ -195,21 +194,16 @@ function makePropGetter(key) {
       return value = bag.getProperty(key);
     }
     catch(e) {
     }
     return null;
   }
 }
 
-function W3CToIETFDate(dateString) {
-  var date = ISO8601DateUtils.parse(dateString);
-  return date.toUTCString();
-}
-
 const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
 // namespace map
 var gNamespaces = {
   "http://webns.net/mvcb/":"admin",
   "http://backend.userland.com/rss":"",
   "http://blogs.law.harvard.edu/tech/rss":"",
   "http://www.w3.org/2005/Atom":"atom",
   "http://purl.org/atom/ns#":"atom03",
@@ -897,34 +891,23 @@ const RFC822_RE = "^((Mon|Tue|Wed|Thu|Fr
  * Tries tries parsing various date formats.
  * @param dateString
  *        A string that is supposedly an RFC822 or RFC3339 date.
  * @returns A Date.toString XXX--fixme
  */
 function dateParse(dateString) {
   var date = dateString.trim();
 
-  if (date.search(/^\d\d\d\d/) != -1) //Could be a ISO8601/W3C date
-    return W3CToIETFDate(dateString);
+  // Could be a ISO8601/W3C date.
+  if (/^\d{4}/.test(date))
+    return new Date(dateString).toUTCString();
 
   if (isValidRFC822Date(date))
     return date; 
-  
-  if (!isNaN(parseInt(date, 10))) { 
-    //It's an integer, so maybe it's a timestamp
-    var d = new Date(parseInt(date, 10) * 1000);
-    var now = new Date();
-    var yeardiff = now.getFullYear() - d.getFullYear();
-    if ((yeardiff >= 0) && (yeardiff < 3)) {
-      // it's quite likely the correct date. 3 years is an arbitrary cutoff,
-      // but this is an invalid date format, and there's no way to verify
-      // its correctness.
-      return d.toString();
-    }
-  }
+
   // Can't help.
   return null;
 } 
 
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 // The XHTMLHandler handles inline XHTML found in things like atom:summary
--- a/toolkit/components/feeds/test/xml/rfc4287/feed_updated.xml
+++ b/toolkit/components/feeds/test/xml/rfc4287/feed_updated.xml
@@ -1,27 +1,27 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!--
-
-Description: atom author name works
-Expect: feed.fields.getProperty('atom:updated') == '2003-12-13T18:30:02Z'
-
--->
-
-<feed xmlns="http://www.w3.org/2005/Atom">
-  
-  <title>Example Feed</title>
-  <link href="http://example.org/"/>
-  <updated>2003-12-13T18:30:02Z</updated>
-  <author>
-       <name>John Doe</name>
-  </author>
-  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
-  
-  <entry>
-    <title>Atom-Powered Robots Run Amok</title>
-    <link href="http://example.org/2003/12/13/atom03"/>
-    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
-    <updated>2003-12-13T18:30:02Z</updated>
-    <summary>Some text.</summary>
-  </entry>
-  
-</feed>
\ No newline at end of file
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+
+Description: raw atom updated works
+Expect: feed.fields.getProperty('atom:updated') == '2003-12-13T18:30:02Z'
+
+-->
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+
+  <title>Example Feed</title>
+  <link href="http://example.org/"/>
+  <updated>2003-12-13T18:30:02Z</updated>
+  <author>
+       <name>John Doe</name>
+  </author>
+  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
+
+  <entry>
+    <title>Atom-Powered Robots Run Amok</title>
+    <link href="http://example.org/2003/12/13/atom03"/>
+    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+    <updated>2003-12-13T18:30:02Z</updated>
+    <summary>Some text.</summary>
+  </entry>
+
+</feed>