Closed (fixed)
Project:
Drupal core
Component:
aggregator.module
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
15 Jun 2004 at 23:27 UTC
Updated:
9 Aug 2004 at 19:20 UTC
Jump to comment: Most recent file
The aggregator.module in HEAD currently only supports iso8601 dates in the format of "yyyy-mm-ddThh:mm:ss". Unfortunately, iso8601 dates can be far more generic or detailed then that. Nor does it handle timezones. I've attached a patch that makes it support a /few more/ iso8601 dates in the wild, but certainly not all the possibilities. Likewise, drumm suggests that instead of using strtotime, we use gmmktime, adding/subtracting the item timezone after the fact:
print strtotime("2004-06-15 07:14:00-0500") . "\n";
print gmmktime(07, 14, 00, 06, 15, 2004) - (60 * 60 * 5);
I agree with this approach, but didn't have time to properly modify the patch to support it (as well as timezones that include half-hours), etc., etc.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | aggregator.w3cdtf.diff | 4.71 KB | drumm |
| aggro.patch | 1.67 KB | morbus iff |
Comments
Comment #1
mda-1 commentedHere is my current fix (mostly comments). This is based on painful examination of
the retarded grammar that php uses.
// first see if strtotime manages it.
$timestamp = strtotime($date); // strtotime() returns -1 on failure
if ($timestamp < 0) {
/*
* You might think from the php docs at http://us4.php.net/strtotime
* that php strtotime uses gnu strtotime. It doesn't.
* Rather, it implements its own grammar at:
* http://cvs.php.net/php-src/ext/standard/parsedate.y
* In http://cvs.php.net/php-src/ext/standard/
* As you can see there, the support for parsing ISO8601 dates is poor prior to v1.52 of Mar 1 05:42:27 2004
*
* As an example feed that has dates with timezone offsets, see
* http://www.rpgdot.com/team/rss/rss13.xml
* For example, it has dc:date of "2004-06-15T09:55+06:00".
*/
// remove numerical timezone, and parse that ourselves
if (preg_match('/(.*)([\+\-]\d\d):?(\d\d)/', $date, $matches)) {
$timestamp = strtotime($matches[1]);
$secs = 0 + $matches[2] * 3600 + $matches[3] * 60;
//print("timestamp=$timestamp secs=$secs from ($matches[1],$matches[2],$matches[3]) in $date\n");
// timezone offsets are local time minus UTC. so UTC = localtime - offset.
$timestamp -= $secs;
}
else {
//print("date $date did not match my tz pattern\n");
}
}
Comment #2
morbus iffSee also rss_date_utime in import.module.
Comment #3
mda-1 commentedOnce again, wrapped with php tags....
Comment #4
mda-1 commentedA third time, wrapped with pre tags....
Comment #5
mda-1 commentedOk, now with square brackets. Are well all fed up now?
Comment #6
drummTook this date parser from MagpieRSS (conveniently GPL). The main benefit here is that timezones are handled properly (I have been noticing increasing complaints about that). I tested with a few feeds of different time formats and time zones and everything appeared correctly in my site's local time. Making this another function adds the benefit of parsability by other RSS (or other contexts) and RSS extension handling functions, where the W3C DTF is recomended.
Comment #7
drummAnd a couple code style updates made it in too.
Comment #8
dries commentedCommitted to HEAD.
Comment #9
(not verified) commented