]> git.mjollnir.org Git - moodle.git/commitdiff
format_time() now supports language strings for day(s)/hour(s)/min(s)/sec(s)
authormoodler <moodler>
Thu, 3 Oct 2002 04:04:59 +0000 (04:04 +0000)
committermoodler <moodler>
Thu, 3 Oct 2002 04:04:59 +0000 (04:04 +0000)
String lookups are cached in user/index.php for efficiency

lang/en/moodle.php
lib/moodlelib.php
user/index.php
user/lib.php

index 6bd2a1d58bc69e078287297533e187ebbea33289..22d81cbadaba4a3cf71d2f375be72dcf7c8d27b2 100644 (file)
@@ -79,6 +79,8 @@ $string['databasechecking'] = "Upgrading Moodle database from version \$a->oldve
 $string['databasesetup'] = "Setting up database";
 $string['databasesuccess'] = "Database was successfully upgraded";
 $string['databaseupgrades'] = "Upgrading database";
+$string['day'] = "day";
+$string['days'] = "days";
 $string['defaultcoursefullname'] = "Course Fullname 101";
 $string['defaultcourseshortname'] = "CF101";
 $string['defaultcoursestudent'] = "Student";
@@ -196,6 +198,8 @@ $string['helptext'] = "How to write text";
 $string['helpquestions'] = "How to ask questions";
 $string['hide'] = "Hide";
 $string['home'] = "Home";
+$string['hour'] = "hour";
+$string['hours'] = "hours";
 $string['htmlformat'] = "Pretty HTML format";
 $string['icqnumber'] = "ICQ number";
 $string['idnumber'] = "ID number";
@@ -252,6 +256,8 @@ $string['markthistopic'] = "Mark this topic as the current topic";
 $string['maximumchars'] = "Maximum of \$a characters";
 $string['maximumgrade'] = "Maximum grade";
 $string['maxsize'] = "Max size: \$a";
+$string['min'] = "min";
+$string['mins'] = "mins";
 $string['miscellaneous'] = "Miscellaneous";  // Default course category
 $string['missingcategory'] = "You need to choose a category";
 $string['missingcity'] = "Missing city/town";
@@ -372,6 +378,8 @@ $string['savechanges'] = "Save changes";
 $string['search'] = "Search";
 $string['searchagain'] = "Search again";
 $string['searchresults'] = "Search results";
+$string['sec'] = "sec";
+$string['secs'] = "secs";
 $string['section'] = "Section";
 $string['selectacountry'] = "Select a country";
 $string['senddetails'] = "Send my details via email";
index 594a30b09491688511127575bb99a798592a984b..198e3308266cad7726beb63bf20de78e2b6faf76 100644 (file)
@@ -339,28 +339,39 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0)
    return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year);
 }
 
-function format_time($totalsecs) {
+function format_time($totalsecs, $str=NULL) {
 // Given an amount of time in seconds, prints it 
 // nicely as months, days, hours etc as needed
 
     $totalsecs = abs($totalsecs);
 
-    $days  = floor($totalsecs/86400);
+    if (!$str) {  // Create the str structure the slow way
+        $str->day   = get_string("day");
+        $str->days  = get_string("days");
+        $str->hour  = get_string("hour");
+        $str->hours = get_string("hours");
+        $str->min   = get_string("min");
+        $str->mins  = get_string("mins");
+        $str->sec   = get_string("sec");
+        $str->secs  = get_string("secs");
+    }
+
+    $days      = floor($totalsecs/86400);
     $remainder = $totalsecs - ($days*86400);
-    $hours = floor($remainder/3600);
+    $hours     = floor($remainder/3600);
     $remainder = $remainder - ($hours*3600);
-    $mins  = floor($remainder/60);
-    $secs = $remainder - ($mins*60);
-
-    if ($secs  != 1) $ss = "s";
-    if ($mins  != 1) $ms = "s";
-    if ($hours != 1) $hs = "s";
-    if ($days  != 1) $ds = "s";
-
-    if ($days)  $odays  = "$days day$ds";
-    if ($hours) $ohours = "$hours hr$hs";
-    if ($mins)  $omins  = "$mins min$ms";
-    if ($secs)  $osecs  = "$secs sec$ss";
+    $mins      = floor($remainder/60);
+    $secs      = $remainder - ($mins*60);
+
+    $ss = ($secs == 1)  ? $str->sec  : $str->secs;
+    $sm = ($mins == 1)  ? $str->min  : $str->mins;
+    $sh = ($hours == 1) ? $str->hour : $str->hours;
+    $sd = ($days == 1)  ? $str->day  : $str->days;
+
+    if ($days)  $odays  = "$days $sd";
+    if ($hours) $ohours = "$hours $sh";
+    if ($mins)  $omins  = "$mins $sm";
+    if ($secs)  $osecs  = "$secs $ss";
 
     if ($days)  return "$odays $ohours";
     if ($hours) return "$ohours $omins";
index 6b7f2ca7714032467e01e2d5ecc597c66895fff4..c2126892ed4f8181d8981a844e5480eefec68270 100644 (file)
     $string->role        = get_string("role");
     $string->never       = get_string("never");
     $string->name        = get_string("name");
+    $string->day         = get_string("day");
+    $string->days        = get_string("days");
+    $string->hour        = get_string("hour");
+    $string->hours       = get_string("hours");
+    $string->min         = get_string("min");
+    $string->mins        = get_string("mins");
+    $string->sec         = get_string("sec");
+    $string->secs        = get_string("secs");
 
     if ( $teachers = get_course_teachers($course->id)) {
         echo "<H2 align=center>$course->teachers</H2>";
             
             foreach ($students as $student) {
                 if ($student->lastaccess) {
-                    $lastaccess = format_time(time() - $student->lastaccess);
+                    $lastaccess = format_time(time() - $student->lastaccess, $string);
                 } else {
                     $lastaccess = $string->never;
                 }
index 9af59db867222734090b27f733f926a189c275c1..b867fc9429e2854d67eab87ca4bd24596977676e 100644 (file)
@@ -70,7 +70,7 @@ function print_user($user, $course, $string) {
     echo "$string->location: $user->city, ".$COUNTRIES["$user->country"]."<BR>";
     if ($user->lastaccess) {
         echo "$string->lastaccess: ".userdate($user->lastaccess);
-        echo "&nbsp (".format_time(time() - $user->lastaccess).")";
+        echo "&nbsp (".format_time(time() - $user->lastaccess, $string).")";
     } else {
         echo "$string->lastaccess: $string->never";
     }