X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=inc%2Frss%2Frss_utils.inc;fp=inc%2Frss%2Frss_utils.inc;h=38c21d96994b0213396bbe1f85951064464b01c7;hb=bc13d5d6e1834068f8b690c32bba114e352dacdd;hp=0000000000000000000000000000000000000000;hpb=07269e54b4e79c0a5e77d8f378cf0849bd8276e5;p=mirrors%2FKyberia-bloodline.git diff --git a/inc/rss/rss_utils.inc b/inc/rss/rss_utils.inc new file mode 100644 index 0000000..38c21d9 --- /dev/null +++ b/inc/rss/rss_utils.inc @@ -0,0 +1,69 @@ + + * Version: 0.3 + * License: GPL + * + * The lastest version of MagpieRSS can be obtained from: + * http://magpierss.sourceforge.net + * + * For questions, help, comments, discussion, etc., please join the + * Mapgie mailing list: + * magpierss-general@lists.sourceforge.net + */ + + +/*======================================================================*\ + Function: parse_w3cdtf + Purpose: parse a W3CDTF date into unix epoch + + NOTE: http://www.w3.org/TR/NOTE-datetime +\*======================================================================*/ + +function parse_w3cdtf ( $date_str ) { + + # regex to match wc3dtf + $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; + + if ( preg_match( $pat, $date_str, $match ) ) { + + list( $year, $month, $day, $hours, $minutes, $seconds) = + array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); + + # calc epoch for current date assuming GMT + $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); + + $offset = 0; + if ( $match[10] == 'Z' ) { + # zulu time, aka GMT + } + else { + list( $tz_mod, $tz_hour, $tz_min ) = + array( $match[7], $match[8], $match[9]); + + # zero out the variables + if ( ! $tz_hour ) { $tz_hour = 0; } + if ( ! $tz_min ) { $tz_min = 0; } + + $offset_secs = (($tz_hour*60)+$tz_min)*60; + + # is timezone ahead of GMT? then subtract offset + # + if ( $tz_mod == '+' ) { + $offset_secs = $offset_secs * -1; + } + + $offset = $offset_secs; + } + + $epoch = $epoch + $offset; + return $epoch; + } + else { + return -1; + } +} + +?>