PHP Classes

Some bugfixes for this class

Recommend this page to a friend!

      Ultimate Date Parser  >  All threads  >  Some bugfixes for this class  >  (Un) Subscribe thread alerts  
Subject:Some bugfixes for this class
Summary:Some fixes you should make before smacking into problem.
Messages:3
Author:Glenn Plas
Date:2010-04-04 03:08:35
Update:2012-03-22 16:07:23
 

  1. Some bugfixes for this class   Reply   Report abuse  
Picture of Glenn Plas 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
---
> ?>

  2. Re: Some bugfixes for this class   Reply   Report abuse  
Picture of Taha Paksu Taha Paksu - 2012-03-22 14:28:28 - In reply to message 1 from Glenn Plas
It has passed 2 years but I just realized that you wrote this :) Sorry. I made the required changes now. I don't have time to test it but I think if it doesn't work, it'll show up. Thanks for your efforts.

  3. Re: Some bugfixes for this class   Reply   Report abuse  
Picture of Taha Paksu Taha Paksu - 2012-03-22 16:07:23 - In reply to message 1 from Glenn Plas
And I've tested, it still works :) Thanks. BTW I've mentioned your name in the class as a contributor.