Commit | Line | Data |
---|---|---|
bc13d5d6 H |
1 | <?php |
2 | /* | |
3 | * Project: MagpieRSS: a simple RSS integration tool | |
4 | * File: rss_utils.inc, utility methods for working with RSS | |
5 | * Author: Kellan Elliott-McCrea <kellan@protest.net> | |
6 | * Version: 0.3 | |
7 | * License: GPL | |
8 | * | |
9 | * The lastest version of MagpieRSS can be obtained from: | |
10 | * http://magpierss.sourceforge.net | |
11 | * | |
12 | * For questions, help, comments, discussion, etc., please join the | |
13 | * Mapgie mailing list: | |
14 | * magpierss-general@lists.sourceforge.net | |
15 | */ | |
16 | ||
17 | ||
18 | /*======================================================================*\ | |
19 | Function: parse_w3cdtf | |
20 | Purpose: parse a W3CDTF date into unix epoch | |
21 | ||
22 | NOTE: http://www.w3.org/TR/NOTE-datetime | |
23 | \*======================================================================*/ | |
24 | ||
25 | function parse_w3cdtf ( $date_str ) { | |
26 | ||
27 | # regex to match wc3dtf | |
28 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; | |
29 | ||
30 | if ( preg_match( $pat, $date_str, $match ) ) { | |
31 | ||
32 | list( $year, $month, $day, $hours, $minutes, $seconds) = | |
33 | array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); | |
34 | ||
35 | # calc epoch for current date assuming GMT | |
36 | $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); | |
37 | ||
38 | $offset = 0; | |
39 | if ( $match[10] == 'Z' ) { | |
40 | # zulu time, aka GMT | |
41 | } | |
42 | else { | |
43 | list( $tz_mod, $tz_hour, $tz_min ) = | |
44 | array( $match[7], $match[8], $match[9]); | |
45 | ||
46 | # zero out the variables | |
47 | if ( ! $tz_hour ) { $tz_hour = 0; } | |
48 | if ( ! $tz_min ) { $tz_min = 0; } | |
49 | ||
50 | $offset_secs = (($tz_hour*60)+$tz_min)*60; | |
51 | ||
52 | # is timezone ahead of GMT? then subtract offset | |
53 | # | |
54 | if ( $tz_mod == '+' ) { | |
55 | $offset_secs = $offset_secs * -1; | |
56 | } | |
57 | ||
58 | $offset = $offset_secs; | |
59 | } | |
60 | ||
61 | $epoch = $epoch + $offset; | |
62 | return $epoch; | |
63 | } | |
64 | else { | |
65 | return -1; | |
66 | } | |
67 | } | |
68 | ||
69 | ?> |