Glenn Plas - 2010-04-04 03:08:35
Here's a diff for you, it fixes the timezone regex since that wasn't parsing too well. Added a regex test function to verify the crafted regex strings. Added the P parameter to the if structure so we can use that as well now. Tested with this date:
Mon Mar 01 2010 23:29:39 GMT +02:00
diff below:
==========
17c17
< class simpledatetime{
---
> class dateparser{
58,59c58,59
< "O"=>"(+[0-9]{4})",
< "P"=>"(+[0-9]{2}:[0-9]{2})",
---
> "O"=>"(\+[0-9]{4})",
> "P"=>"(\+[0-9]{2}:[0-9]{2})",
72a73,88
>
> /**
> * function which tests regex pattern for validity :
> * Test regexes and throw exception if they don't parse well
> *
> * @param string $regex
> * @return true/throw exception
> */
> function preg_test($regex) {
> if (sprintf("%s",@preg_match($regex,'')) == '') {
> $error = error_get_last();
> throw new Exception(substr($error['message'],70));
> } else {
> return true;
> }
> }
108a125,127
> $this->preg_test($pattern);
> // Exception will be thrown here when its trying to match a non-valid regex (which I fixed).
>
160,162c179,187
< if($result["O"]) $timezone = $result["O"];
< elseif ($result["Z"]) $timezone = ($result["Z"]/3600);
< else $timezone = date("O");
---
> if($result["P"]) {
> $timezone = $result["P"] ;
> } elseif($result["O"]) {
> $timezone = $result["O"] ;
> } elseif ($result["Z"]) {
> $timezone = ($result["Z"]/3600);
> } else {
> $timezone = date("O");
> }
277c302
< ?>
\ No newline at end of file
---
> ?>