mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 18:55:30 +00:00
Bug 618714 - Switch feed parser to using Date object's support for ISO8601 dates, r=mak
--HG-- extra : rebase_source : 2be179a2de7c21b890471c1ffc80a004f7410159
This commit is contained in:
parent
8c09fbac55
commit
5d0fd95b3e
@ -46,7 +46,6 @@ 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}");
|
||||
@ -200,11 +199,6 @@ function makePropGetter(key) {
|
||||
}
|
||||
}
|
||||
|
||||
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 = {
|
||||
@ -902,24 +896,13 @@ const RFC822_RE = "^((Mon|Tue|Wed|Thu|Fri|Sat|Sun)([a-z]+)?,? *)?\\d\\d?"
|
||||
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;
|
||||
}
|
||||
|
@ -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>
|
||||
<?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>
|
||||
|
Loading…
Reference in New Issue
Block a user