]> git.mjollnir.org Git - moodle.git/commitdiff
Timer now uses the client's clock. Patch contributed by Phillip Franks, see bug 4967
authorgustav_delius <gustav_delius>
Thu, 23 Mar 2006 19:32:24 +0000 (19:32 +0000)
committergustav_delius <gustav_delius>
Thu, 23 Mar 2006 19:32:24 +0000 (19:32 +0000)
mod/quiz/jstimer.php
mod/quiz/timer.js

index b88977fe90776f185962730793c8d72d8119eb54..1a0d7641a3956da044578a18227960c769383967 100644 (file)
@@ -12,6 +12,12 @@ var timesup = "<?php print_string("timesup","quiz");?>";
 var quizclose = <?php echo ($quiz->timeclose - time()) - $timerstartvalue; ?>; // in seconds
 var quizTimerValue = <?php echo $timerstartvalue; ?>; // in seconds
 parseInt(quizTimerValue);
+
+// @EC PF : client time when page was opened
+var ec_page_start = new Date().getTime();
+// @EC PF : client time when quiz should end
+var ec_quiz_finish = ec_page_start + <?php echo ($timerstartvalue * 1000); ?>;
+
 // -->
 </script>
 <script language="javascript" type="text/javascript" src="timer.js"></script>
index bdb9e960fe57bdff6aff607dda7f7f951fa098fb..a45284424ab0e5a2e8813200d4ea36fcd9f8973d 100644 (file)
@@ -6,7 +6,12 @@
 //
 function countdown_clock(theTimer) {
     var timeout_id = null;
-    quizTimerValue = quizTimerValue - 1;
+
+       // @EC PF : current client time
+       var ec_now_epoch = new Date().getTime();
+
+       // @EC PF : time left according to client
+       quizTimerValue = Math.floor( (ec_quiz_finish - ec_now_epoch) /1000 );
 
     if(quizTimerValue == 0) {
         clearTimeout(timeout_id);