Skip to content

Commit

Permalink
moodlelib MDL-20918 usergetdate was returning an array in a different…
Browse files Browse the repository at this point in the history
… order depending on whether or not timezone was set
  • Loading branch information
Andrew Davis committed Jan 8, 2010
1 parent 366a5bb commit e45757a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
21 changes: 11 additions & 10 deletions lib/moodlelib.php
Expand Up @@ -1309,19 +1309,20 @@ function usergetdate($time, $timezone=99) {
$time += dst_offset_on($time, $strtimezone);
$time += intval((float)$timezone * HOURSECS);

$datestring = gmstrftime('%S_%M_%H_%d_%m_%Y_%w_%j_%A_%B', $time);
$datestring = gmstrftime('%B_%A_%j_%Y_%m_%w_%d_%H_%M_%S', $time);

//be careful to ensure the returned array matches that produced by getdate() above
list(
$getdate['seconds'],
$getdate['minutes'],
$getdate['hours'],
$getdate['mday'],
$getdate['mon'],
$getdate['month'],
$getdate['weekday'],
$getdate['yday'],
$getdate['year'],
$getdate['mon'],
$getdate['wday'],
$getdate['yday'],
$getdate['weekday'],
$getdate['month']
$getdate['mday'],
$getdate['hours'],
$getdate['minutes'],
$getdate['seconds']
) = explode('_', $datestring);

return $getdate;
Expand Down Expand Up @@ -3268,7 +3269,7 @@ function complete_user_login($user) {
$USER = $user; // this is required because we need to access preferences here!

if (!empty($CFG->regenloginsession)) {
// please note this setting may break some auth plugins
// please note this setting may break some auth plugins
session_regenerate_id();
}

Expand Down
37 changes: 35 additions & 2 deletions lib/simpletest/testmoodlelib.php
Expand Up @@ -261,7 +261,40 @@ function test_shorten_text() {
$this->assertEqual("<h1>12345...</h1>",
shorten_text($text, 8));
}

function test_usergetdate() {
$ts = 1261540267; //the time this function was created

}
$arr = usergetdate($ts,1);
$arr = array_values($arr);

list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
$this->assertEqual($seconds,7);
$this->assertEqual($minutes,51);
$this->assertEqual($hours,4);
$this->assertEqual($mday,23);
$this->assertEqual($wday,3);
$this->assertEqual($mon,12);
$this->assertEqual($year,2009);
$this->assertEqual($yday,357);
$this->assertEqual($weekday,'Wednesday');
$this->assertEqual($month,'December');

$arr = usergetdate($ts);
$arr = array_values($arr);

?>
list($seconds,$minutes,$hours,$mday,$wday,$mon,$year,$yday,$weekday,$month) = $arr;
$this->assertEqual($seconds,7);
$this->assertEqual($minutes,51);
$this->assertEqual($hours,11);
$this->assertEqual($mday,23);
$this->assertEqual($wday,3);
$this->assertEqual($mon,12);
$this->assertEqual($year,2009);
$this->assertEqual($yday,356);
$this->assertEqual($weekday,'Wednesday');
$this->assertEqual($month,'December');
}

}
?>

0 comments on commit e45757a

Please sign in to comment.