Browse files

moodlelib MDL-20918 usergetdate was returning an array in a different…

… order depending on whether or not timezone was set
  • Loading branch information...
1 parent 366a5bb commit e45757ad632ec4811b53f98d8fb97037df6bbea3 Andrew Davis committed Jan 8, 2010
Showing with 46 additions and 12 deletions.
  1. +11 −10 lib/moodlelib.php
  2. +35 −2 lib/simpletest/testmoodlelib.php
View
21 lib/moodlelib.php
@@ -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;
@@ -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();
}
View
37 lib/simpletest/testmoodlelib.php
@@ -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.