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
Page 1 of 1
Calculation with DateTime class causes php range() error...
#2
Posted 13 October 2011 - 08:34 AM
Why you provide Yii version ?
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');
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');
Certification:

Test Yii:
Yii Framework Demos
Wiki:
Common Yii Questions
Tutorials:
Demo Blog Search with Zend_Lucene
Fundamentals:
Yii "registry" | Understanding the layout->view randering flow
Etc:
Shrink Yii | Caching config/main.php | CPhpAuthManager - how it works, and when to use it
Extensions:
Theme Picker | Language Picker (i18n)

Test Yii:
Yii Framework Demos
Wiki:
Common Yii Questions
Tutorials:
Demo Blog Search with Zend_Lucene
Fundamentals:
Yii "registry" | Understanding the layout->view randering flow
Etc:
Shrink Yii | Caching config/main.php | CPhpAuthManager - how it works, and when to use it
Extensions:
Theme Picker | Language Picker (i18n)
#3
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
.
.
.
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
.
.
.
#4
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?
#6
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.
Share this topic:
Page 1 of 1

Help














