diff --git a/lib/cronlib.php b/lib/cronlib.php
index 9f9f3a1..541288b 100644
--- a/lib/cronlib.php
+++ b/lib/cronlib.php
@@ -834,14 +834,15 @@ function notify_login_failures() {
  * Delete files and directories older than one week from directory provided by $CFG->tempdir.
  *
  * @exception Exception Failed reading/accessing file or directory
+ * @time unixtimestamp A fixed timestamp to test against (for testing)
  * @return bool True on successful file and directory deletion; otherwise, false on failure
  */
-function cron_delete_from_temp() {
+function cron_delete_from_temp($now = NULL) {
     global $CFG;
 
     $tmpdir = $CFG->tempdir;
     // Default to last weeks time.
-    $time = strtotime('-1 week');
+    $time = strtotime('-1 week', is_null($now) ? time() : $now);
 
     try {
         $dir = new RecursiveDirectoryIterator($tmpdir);
diff --git a/lib/tests/cronlib_test.php b/lib/tests/cronlib_test.php
index 100153b..b0dca7d 100644
--- a/lib/tests/cronlib_test.php
+++ b/lib/tests/cronlib_test.php
@@ -43,7 +43,11 @@ class cronlib_testcase extends basic_testcase {
         $time = 0;
 
         // Relative time stamps. Did you know data providers get executed during phpunit init?
-        $lastweekstime = -(7 * 24 * 60 * 60);
+        // The following lets us handle Daylight Saving correctly (might be an hour more or less than 7 x 24 x 3600)
+        // Just get time() once to avoid the (tiny) potential for time() & strtotime('-1 week') to have different
+        // unix timestamps.
+        $temp_time = time();
+        $lastweekstime = strtotime('-1 week', $temp_time) - $temp_time;
         $beforelastweekstime = $lastweekstime - 60;
         $afterlastweekstime = $lastweekstime + 60;
 
@@ -149,6 +153,7 @@ class cronlib_testcase extends basic_testcase {
         global $CFG;
 
         $tmpdir = $CFG->tempdir;
+        $time = time();
 
         foreach ($nodes as $data) {
             if ($data->isdir) {
@@ -158,9 +163,9 @@ class cronlib_testcase extends basic_testcase {
         // We need to iterate through again since adding a file to a directory will
         // update the modified time of the directory.
         foreach ($nodes as $data) {
-            touch($tmpdir.$data->path, time() + $data->time);
+            touch($tmpdir.$data->path, $time + $data->time);
         }
-        cron_delete_from_temp();
+        cron_delete_from_temp($time);
 
         $dir = new RecursiveDirectoryIterator($tmpdir);
         $iter = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
