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 += dst_offset_on($time, $strtimezone);
$time += intval((float)$timezone * HOURSECS); $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( list(
$getdate['seconds'], $getdate['month'],
$getdate['minutes'], $getdate['weekday'],
$getdate['hours'], $getdate['yday'],
$getdate['mday'],
$getdate['mon'],
$getdate['year'], $getdate['year'],
$getdate['mon'],
$getdate['wday'], $getdate['wday'],
$getdate['yday'], $getdate['mday'],
$getdate['weekday'], $getdate['hours'],
$getdate['month'] $getdate['minutes'],
$getdate['seconds']
) = explode('_', $datestring); ) = explode('_', $datestring);


return $getdate; 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! $USER = $user; // this is required because we need to access preferences here!


if (!empty($CFG->regenloginsession)) { 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(); 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>", $this->assertEqual("<h1>12345...</h1>",
shorten_text($text, 8)); 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.