LemonStand Forum: PHPr_DateTime Class - LemonStand Forum

Jump to content

Severity 0 - None Assigned Status Unconfirmed
Version - Fixed in -

Page 1 of 1
  • Cannot start a new Issue
  • You cannot reply to this issue

Report ID #211: PHPr_DateTime Class

#1 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 30 April 2012 - 04:24 PM

The PHPr_Datetime class is full of bugs. It can't correctly parse dates.

The value of the field right now is "04/01/2012" and when I press save I get this:
"Can not parse date/time string: 04/02/2012 00:00:00"

Other bugs:
http://forum.lemonst...eld-not-saving/
http://forum.lemonst...0-00-00-000000/


Page 1 of 1  
  • Cannot start a new Issue
  • You cannot reply to this issue

Replies (1 - 7)

#2 User is offline  
Manca 

  • Developer
  • Group: +Administrators
  • Posts: 252
  • Joined: 02-September 11

Posted 01 May 2012 - 02:28 PM

Updating status to: Unconfirmed

Hi,

We'll take a good look at the Phpr_DateTime class when implementing the datetime form field, which we're scheduled to do soon.

Thank you

#3 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 08 May 2012 - 05:00 PM

Every day I work this it just keeps getting more and more frustrating.

When testing it is 7:35PM on my machine.
In the config I have it set to new york which is 1 hour ahead so it should be 8:35PM server time.

However this:
var_dump(Phpr_DateTime::gmtNow()->tosqlDateTime());
var_dump(Phpr_DateTime::now()->tosqlDateTime());


Both output:
string(19) "2012-05-09 00:35:22"

Where is this 4 hour gap at?

#4 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 08 May 2012 - 05:10 PM

Here is some more things I keep trying:

$timeZoneObj = new DateTimeZone( Phpr::$config->get('TIMEZONE') );
var_dump(Phpr_DateTime::gmtNow($timeZoneObj)->tosqlDateTime());


#5 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 08 May 2012 - 05:24 PM

For those following along now() says the same time as GMT as it does not factor in any time zone. You have to manually do it:

$timeZoneObj = new DateTimeZone( Phpr::$config->get('TIMEZONE') );
$timeObj = new Phpr_DateTime( null, $timeZoneObj );
var_dump($timeObj->tosqlDateTime());


We could really use some documentation it might help make this work.

#6 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 09 May 2012 - 02:27 PM

Heres yet another example of needing this today. I am trying to get a timestamp, I have tried for an hour to get a working solution. Id rather just get rid of PHPr at this point and leave the datetime functions alone.

$timeZoneObj = new DateTimeZone( Phpr::$config->get('TIMEZONE') );
$now = new Phpr_DateTime( null, $timeZoneObj );
$now->setPHPDateTime(strtotime($product->expires));
var_dump($now->getInteger());


But this obviously outputs a huge number due the "precision" of phpr. So lets continue on other attempts.

I start looking into format() but it is not clearly documented. Strftime in php works so lets try that.

$timeZoneObj = new DateTimeZone( Phpr::$config->get('TIMEZONE') );
$now = new Phpr_DateTime( null, $timeZoneObj );
$now->setPHPDateTime(strtotime($product->expires));
var_dump($now->format('%s'));


Nope, phpr doesnt support this. So lets have a look at what it does support:


				'a' => array( self::spType=>self::spTypeString, self::spDomain=>'a_weekday_', self::spMethod=>'GetDayOfWeek', self::spValueNum=>7 ),
				'A' => array( self::spType=>self::spTypeString, self::spDomain=>'A_weekday_', self::spMethod=>'GetDayOfWeek', self::spValueNum=>7 ),
				'b' => array( self::spType=>self::spTypeString, self::spDomain=>'b_month_', self::spMethod=>'GetMonth' ),
				'B' => array( self::spType=>self::spTypeString, self::spDomain=>'B_month_', self::spMethod=>'GetMonth' ),
				'c' => array( self::spType=>self::spTypeComplex, self::spComplexValue=>'%x %X' ),
				'C' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>99, self::spMethod=>self::spCustomMethod, self::spIntPadding=>2 ),
				'd' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>31, self::spMethod=>'GetDay', self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnDay ),
				'D' => array( self::spType=>self::spTypeComplex, self::spComplexValue=>'%m/%d/%y' ),
				'e' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>31, self::spMethod=>'GetDay', self::spParserMeaning=>self::spPrMnDay ),
				'F' => array( self::spType=>self::spTypeLocLink, self::spLocLinkKey=>'full_date_format' ),
				'H' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>23, self::spMethod=>'GetHour', self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnHour ),
				'I' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>12, self::spMethod=>self::spCustomMethod, self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnHour ),
				'j' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>366, self::spMethod=>'GetDayOfYear', self::spIntPadding=>3 ),
				'm' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>12, self::spMethod=>'GetMonth', self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnMonth ),
				'M' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>59, self::spMethod=>'GetMinute', self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnMinute ),
				'n' => array( self::spType=>self::spTypeString, self::spDomain=>'n_month_', self::spMethod=>'GetMonth' ),
				'p' => array( self::spType=>self::spTypeString, self::spDomain=>'ampm_', self::spMethod=>self::spCustomMethod, self::spParserMeaning=>self::spPrMnCustom, self::spValueList=>array('ampm_am', 'ampm_pm') ),
				'S' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>59, self::spMethod=>'GetSecond', self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnSecond ),
				'T' => array( self::spType=>self::spTypeComplex, self::spComplexValue=>'%H:%M:%S' ),
				'u' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>7, self::spMethod=>'GetDayOfWeek' ),
				'w' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>6, self::spMethod=>self::spCustomMethod ),
				'x' => array( self::spType=>self::spTypeLocLink, self::spLocLinkKey=>'short_date_format' ),
				'X' => array( self::spType=>self::spTypeLocLink, self::spLocLinkKey=>'time_format' ),
				'y' => array( self::spType=>self::spTypeInt, self::spIntMin=>0, self::spIntMax=>99, self::spMethod=>self::spCustomMethod, self::spIntPadding=>2, self::spParserMeaning=>self::spPrMnCustom ),
				'Y' => array( self::spType=>self::spTypeInt, self::spIntMin=>1, self::spIntMax=>9999, self::spMethod=>'GetYear', self::spParserMeaning=>self::spPrMnYear )


Well thats absolutely no help as you can see. No documentation and no idea what is even going on. From the looks of it it looks like there is no timestamp.

#7 User is offline  
activeholdingco 

  • LemonGroupy
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 187
  • Joined: 23-September 10

Posted 09 May 2012 - 02:35 PM

Continuing on, when getting the seconds it has some math, so lets try that:

$timeZoneObj = new DateTimeZone( Phpr::$config->get('TIMEZONE') );
$now = new Phpr_DateTime( null, $timeZoneObj );
$now->setPHPDateTime(strtotime($product->expires));
$end_time = ($now->getInteger() / Phpr_DateTime::intInSecond);


Great! It looks sort of like a timestamp, but its one digit to long and 6x what it needs to be. Continuing on...

#8 User is offline  
Manca 

  • Developer
  • Group: +Administrators
  • Posts: 252
  • Joined: 02-September 11

Posted 09 May 2012 - 04:08 PM

You can always skip phpr_datetime and use something like:
$input = '31.12.2001 00:00 GMT';
$timeZone = Phpr::$config->get('TIMEZONE');
$date = new DateTime($input);
$date->setTimezone(new DateTimeZone($timeZone));
$end_date = $date->format('Y-m-d\TH:i:sO');


I had to use that in one of our modules to get that format for a datetime field. Use 'U' to get a unix timestamp. If $input is null, you can get the current time.


Page 1 of 1
  • Cannot start a new Issue
  • You cannot reply to this issue

0 User(s) are reading this issue
0 Guests and 0 Anonymous Users