MDL-32234 Library: usergetdate return different values when timezone is set

usergetdate should return consistent values for different timezone. There are
two return path
1. If timezone is servertime, it returns getdate
2. If timezone other then servertime, it use gmstrftime, which returns string and
   values with leading zero.
In second case, leading zero's are removed and values are type casted. One major fix
is with yday, getdate returns 0 through 365, whereas %j returns 001 through 366. This
has been fixed as well.
This commit is contained in:
Rajesh Taneja
2012-04-30 10:53:24 +08:00
parent eddceb69c7
commit 7cdb2e4575
2 changed files with 11 additions and 2 deletions
+9
View File
@@ -1798,6 +1798,15 @@ function usergetdate($time, $timezone=99) {
$getdate['seconds']
) = explode('_', $datestring);
// set correct datatype to match with getdate()
$getdate['seconds'] = (int)$getdate['seconds'];
$getdate['yday'] = (int)$getdate['yday'] - 1; // gettime returns 0 through 365
$getdate['year'] = (int)$getdate['year'];
$getdate['mon'] = (int)$getdate['mon'];
$getdate['wday'] = (int)$getdate['wday'];
$getdate['mday'] = (int)$getdate['mday'];
$getdate['hours'] = (int)$getdate['hours'];
$getdate['minutes'] = (int)$getdate['minutes'];
return $getdate;
}
+2 -2
View File
@@ -580,7 +580,7 @@ class moodlelib_test extends UnitTestCase {
$this->assertEqual($wday,3);
$this->assertEqual($mon,12);
$this->assertEqual($year,2009);
$this->assertEqual($yday,357);
$this->assertEqual($yday,356);
$this->assertEqual($weekday, 'Wednesday');
$this->assertEqual($month, 'December');
@@ -595,7 +595,7 @@ class moodlelib_test extends UnitTestCase {
$this->assertEqual($wday,3);
$this->assertEqual($mon,12);
$this->assertEqual($year,2009);
$this->assertEqual($yday,357);
$this->assertEqual($yday,356);
$this->assertEqual($weekday, 'Wednesday');
$this->assertEqual($month, 'December');