KodaShuko / magpiephp

Automatically exported from code.google.com/p/magpiephp
0 stars 0 forks source link

error in parse_w3cdtf, #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try parse_w3cdtf("2007-01-05T23:30:30-05:00");

What is the expected output? 
i expected => 2007-01-05
What do you see instead?
i get => 1969-12-31

and 

Warning: gmmktime() expects parameter 3 to be long, string given in
/home/eromero/newworkspace/linuxer/vendors/magpierss/rss_utils.inc on line 37

What version of the product are you using? 

 * Project:     MagpieRSS: a simple RSS integration tool
 * File:        rss_utils.inc, utility methods for working with RSS
 * Author:      Kellan Elliott-McCrea <kellan@protest.net>
 * Version:     0.51

On what operating system?
Gentoo Linux x86_64, PHP 5.1.6-pl4-gentoo

Please provide any additional information below.

I presume it's because of an error on the regex:
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z)
)?/
around line 28.

since i'm lazy i fixed adding:

        $hours = str_replace(":", "", $hours);
        $minutes = str_replace(":", "", $minutes);
        $seconds = str_replace(":", "", $seconds);

right above:

  $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year);

around line 37.

Original issue reported on code.google.com by earom...@gmail.com on 6 Jan 2007 at 5:36

GoogleCodeExporter commented 8 years ago
To fix this problem at the source, change the following line (lines 31-32):

        list( $year, $month, $day, $hours, $minutes, $seconds) = 
            array( $match[1], $match[3], $match[5], $match[7], $match[8], $match[9]);

To the corrected:

        list( $year, $month, $day, $hours, $minutes, $seconds) = 
            array( $match[1], $match[3], $match[5], $match[7], $match[8], $match[10]);

Hope this helps.

Original comment by thech...@gmail.com on 31 Jan 2007 at 10:44

GoogleCodeExporter commented 8 years ago
Here is the corrected regex that will fix this problem.

$pat =
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):((\d{2}))?(:?([-+])(\d{2}):?(\d{2})|(Z
))?/";

Original comment by valinor...@gmail.com on 6 Jul 2007 at 10:10