Yii Framework Forum: Calculation with DateTime class causes php range() error... - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Calculation with DateTime class causes php range() error... Rate Topic: -----

#1 User is offline   Sourceforger 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-May 11

Posted 13 October 2011 - 08:11 AM

Calculation with DateTime class causes php range() error...
Possibly a bug?

Insert a simple DateTime calculation with DateTime::diff() in the index action of the default tutorial yii application.

Astonishing is that it causes an php range() error when you change from the home view to the contact view.

It also seem that the more often you call the diff() the greater is the chance to get the error. In other words the more often you recall the home view the greater is the chance to get the error when you switch to the contact view.

Here the code:

date_default_timezone_set('Europe/London');
//Aktuelle Zeit als DateTime
$dakt = new DateTime("2011-10-15 10:45:00");
//Endzeit Zeit als DateTime
$dend = new DateTime("2011-10-15 10:00:00");

$intv = $dakt->diff($dend);


OS: Windows XP
Yii: 1.1.8.r3324
XAMPP for win: 1.7.4
0

#2 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 13 October 2011 - 08:34 AM

Why you provide Yii version ? :lol:

it is not Yii class, it is php class

check this out http://php.net/manua...tetime.diff.php

DateTime is very strict in the date format You give it...
also put attention to echo $interval->format('%R%a days');
0

#3 User is offline   Sourceforger 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-May 11

Posted 13 October 2011 - 09:37 AM

I do not find any error in the use of DateTime.
I test with:

<?php

date_default_timezone_set('Europe/London');
//Aktuelle Zeit als DateTime
$dakt = new DateTime("2011-10-15 10:45:00");
//Endzeit Zeit als DateTime
$dend = new DateTime("2011-10-15 10:00:00");

$intv = $dakt->diff($dend);

echo 'Zeit1: ' . $dakt->format('Y-m-d H:i:s') . "<br>";
echo 'Zeit2: ' . $dend->format('Y-m-d H:i:s') . "<br>";

echo $intv->format('%H:%I:%S') . "<br>";

?>

Result printed is correct:

Zeit1: 2011-10-15 10:45:00
Zeit2: 2011-10-15 10:00:00
00:45:00


but used with yii described as i mention above i got a php error...

PHP Error

range() [<a href='function.range'>function.range</a>]: step exceeds the specified range

C:\xampp\htdocs\yii\framework\web\helpers\CJavaScript.php(83)

71 if($value===-INF)
72 return 'Number.NEGATIVE_INFINITY';
73 else if($value===INF)
74 return 'Number.POSITIVE_INFINITY';
75 else
76 return rtrim(sprintf('%.16F',$value),'0'); // locale-independent representation
77 }
78 else if(is_object($value))
79 return self::encode(get_object_vars($value));
80 else if(is_array($value))
81 {
82 $es=array();
83 if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1))
84 {
85 foreach($value as $k=>$v)
86 $es[]="'".self::quote($k)."':".self::encode($v);
87 return '{'.implode(',',$es).'}';
88 }
89 else
.
.
.
0

#4 User is offline   Lidiexy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 22-December 10

Posted 05 February 2012 - 05:56 AM

I have the same problem, with Yii 1.1.6 version. When i use DateTime diff. Please any solutions idea?
0

#5 User is offline   Ivan Ozercov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-April 12

Posted 18 May 2012 - 11:19 AM

I have this problem too. Yii 1.1.9 version. :angry:
0

#6 User is offline   randomizer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-September 12

Posted 09 September 2012 - 01:40 PM

Ran into the same problem. Seems to be platform dependent, according to this: code.google.com/p/yii/issues/detail?id=2317. It happened for me on WAMPSERVER with PHP 5.3.0 and Apache 2.2.11. The problem went away when I switched to PHP 5.3.13 on Apache 2.2.22. The 4th comment on the above linked bug report suggests a solution which worked on the older version, but was not necessary on the more recent one.
0

#7 User is offline   epulgaron 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 19-February 14

Posted 16 April 2014 - 10:07 AM

hi i am trying to show in a custom column grid that shows me the remains of two of the fields grid, and what would they be fecha_det_a1 fecha_ocu_a1
this function should develop in my admin because that's where I want it to display. Already declared the variable in the model (), now this is the function:

<?php

function dateDiff($start, $end)
{

$start_ts = strtotime($start);

$end_ts = strtotime($end);

$diff = $end_ts - $start_ts;

return round($diff / 86400);

}

$fdfo=dateDiff($model->fecha_det_a1,$model->fecha_ocu_a1);
?>

When I invoke the function within the grid, I do soÑ
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'anexo1-grid',
'itemsCssClass'=>"table table-striped",
'dataProvider'=>$model->search(),
.
.
'columns'=>array(
'id',
array('name'=>'no_hc_a1','value'=>'$data->no_hc_a1'),
array('name'=>'entidadhc_fk','value'=>'$data->entidadhcFk->enthc_nombre'),
array('name'=>'orga_hc_siglas','value'=>'$data->entidadhcFk->orgaFk->orga_hc_siglas'),
.
.
array('name'=>'fdfo','value'=>$fdfo),
.
.
array(
'class'=>'CButtonColumn',
),
),
)); ?>

but when I go to access the admin view returns me the following error:
call_user_func_array() expects parameter 1 to be a valid callback, no array or string given

could you help me? thanks


View Postdckurushin, on 13 October 2011 - 08:34 AM, said:

Why you provide Yii version ? :lol:

it is not Yii class, it is php class

check this out http://php.net/manua...tetime.diff.php

DateTime is very strict in the date format You give it...
also put attention to echo $interval->format('%R%a days');

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users