Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replaced time related "magic numbers" with constants, what are hopefully

more easier to read.
  • Loading branch information...
commit 7a5672c90cdfe182a6bfd8141fa290b73335c51e 1 parent 77439ab
authored September 28, 2004
4  lib/datalib.php
@@ -2589,7 +2589,7 @@ function get_logs_usercourse($userid, $courseid, $coursestart) {
2589 2589
         $courseselect = '';
2590 2590
     }
2591 2591
 
2592  
-    return get_records_sql("SELECT floor((`time` - $coursestart)/86400) as day, count(*) as num
  2592
+    return get_records_sql("SELECT floor((`time` - $coursestart)/".DAYSECS."86400) as day, count(*) as num
2593 2593
                             FROM {$CFG->prefix}log
2594 2594
                            WHERE userid = '$userid'
2595 2595
                              AND `time` > '$coursestart' $courseselect
@@ -2615,7 +2615,7 @@ function get_logs_userday($userid, $courseid, $daystart) {
2615 2615
         $courseselect = '';
2616 2616
     }
2617 2617
 
2618  
-    return get_records_sql("SELECT floor((`time` - $daystart)/3600) as hour, count(*) as num
  2618
+    return get_records_sql("SELECT floor((`time` - $daystart)/".HOURSECS.") as hour, count(*) as num
2619 2619
                             FROM {$CFG->prefix}log
2620 2620
                            WHERE userid = '$userid'
2621 2621
                              AND `time` > '$daystart' $courseselect
36  lib/moodlelib.php
@@ -52,6 +52,16 @@
52 52
  */
53 53
 define('VISIBLEGROUPS', 2);
54 54
 
  55
+/**
  56
+ * Time constants
  57
+ */
  58
+
  59
+define('WEEKSECS', 604800); 
  60
+define('DAYSECS', 86400);
  61
+define('HOURSECS', 3600);
  62
+define('MINSECS', 60);
  63
+define('DAYMINS', 1440);
  64
+define('HOURMINS', 60);
55 65
 
56 66
 /// PARAMETER HANDLING ////////////////////////////////////////////////////
57 67
 
@@ -320,12 +330,12 @@ function format_time($totalsecs, $str=NULL) {
320 330
         $str->secs  = get_string('secs');
321 331
     }
322 332
 
323  
-    $days      = floor($totalsecs/86400);
324  
-    $remainder = $totalsecs - ($days*86400);
325  
-    $hours     = floor($remainder/3600);
326  
-    $remainder = $remainder - ($hours*3600);
327  
-    $mins      = floor($remainder/60);
328  
-    $secs      = $remainder - ($mins*60);
  333
+    $days      = floor($totalsecs/DAYSECS);
  334
+    $remainder = $totalsecs - ($days*DAYSECS);
  335
+    $hours     = floor($remainder/HOURSECS);
  336
+    $remainder = $remainder - ($hours*HOURSECS);
  337
+    $mins      = floor($remainder/MINSECS);
  338
+    $secs      = $remainder - ($mins*MINSECS);
329 339
 
330 340
     $ss = ($secs == 1)  ? $str->sec  : $str->secs;
331 341
     $sm = ($mins == 1)  ? $str->min  : $str->mins;
@@ -390,7 +400,7 @@ function userdate($date, $format='', $timezone=99, $fixday = true) {
390 400
             $datestring = strftime($format, $date);
391 401
         }
392 402
     } else {
393  
-        $date = $date + (int)($timezone * 3600);
  403
+        $date = $date + (int)($timezone * HOURSECS);
394 404
         if ($fixday) {
395 405
             $datestring = gmstrftime($formatnoday, $date);
396 406
             $daystring  = str_replace(' 0', '', gmstrftime(" %d", $date));
@@ -420,7 +430,7 @@ function usergetdate($date, $timezone=99) {
420 430
         return getdate($date);
421 431
     }
422 432
     //There is no gmgetdate so I have to fake it...
423  
-    $date = $date + (int)($timezone * 3600);
  433
+    $date = $date + (int)($timezone * HOURSECS);
424 434
     $getdate['seconds'] = gmstrftime("%S", $date);
425 435
     $getdate['minutes'] = gmstrftime("%M", $date);
426 436
     $getdate['hours']   = gmstrftime("%H", $date);
@@ -449,7 +459,7 @@ function usertime($date, $timezone=99) {
449 459
     if (abs($timezone) > 13) {
450 460
         return $date;
451 461
     }
452  
-    return $date - (int)($timezone * 3600);
  462
+    return $date - (int)($timezone * HOURSECS);
453 463
 }
454 464
 
455 465
 /**
@@ -1015,9 +1025,9 @@ function set_moodle_cookie($thing) {
1015 1025
     $cookiename = 'MOODLEID_'.$CFG->sessioncookie;
1016 1026
 
1017 1027
     $days = 60;
1018  
-    $seconds = 60*60*24*$days;
  1028
+    $seconds = DAYSECS*$days;
1019 1029
 
1020  
-    setCookie($cookiename, '', time() - 3600, '/');
  1030
+    setCookie($cookiename, '', time() - HOURSECS, '/');
1021 1031
     setCookie($cookiename, rc4encrypt($thing), time()+$seconds, '/');
1022 1032
 }
1023 1033
 
@@ -3525,7 +3535,7 @@ function notify_login_failures() {
3525 3535
                  : ((strlen($ipstr) != 0) ? ' AND ip IN ('. $ipstr .') ' : ' AND info IN ('. $userstr .') ')), 'l.time DESC', '', '', $count);
3526 3536
 
3527 3537
         // if we haven't run in the last hour and we have something useful to report and we are actually supposed to be reporting to somebody
3528  
-        if (is_array($recip) and count($recip) > 0 and ((time() - (60 * 60)) > $CFG->lastnotifyfailure)
  3538
+        if (is_array($recip) and count($recip) > 0 and ((time() - HOURSECS) > $CFG->lastnotifyfailure)
3529 3539
             and is_array($logs) and count($logs) > 0) {
3530 3540
 
3531 3541
             $message = '';
@@ -3656,7 +3666,7 @@ function getweek ($startdate, $thedate) {
3656 3666
         return 0;
3657 3667
     }
3658 3668
 
3659  
-    return floor(($thedate - $startdate) / 604800.0) + 1;
  3669
+    return floor(($thedate - $startdate) / WEEKSECS) + 1;
3660 3670
 }
3661 3671
 
3662 3672
 /**

0 notes on commit 7a5672c

Please sign in to comment.
Something went wrong with that request. Please try again.