mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
format_time() now supports language strings for day(s)/hour(s)/min(s)/sec(s)
String lookups are cached in user/index.php for efficiency
This commit is contained in:
parent
05d09aa1f9
commit
8dbed6be60
@ -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";
|
||||
|
@ -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);
|
||||
$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";
|
||||
$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 day$ds";
|
||||
if ($hours) $ohours = "$hours hr$hs";
|
||||
if ($mins) $omins = "$mins min$ms";
|
||||
if ($secs) $osecs = "$secs sec$ss";
|
||||
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";
|
||||
|
@ -37,6 +37,14 @@
|
||||
$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>";
|
||||
@ -101,7 +109,7 @@
|
||||
|
||||
foreach ($students as $student) {
|
||||
if ($student->lastaccess) {
|
||||
$lastaccess = format_time(time() - $student->lastaccess);
|
||||
$lastaccess = format_time(time() - $student->lastaccess, $string);
|
||||
} else {
|
||||
$lastaccess = $string->never;
|
||||
}
|
||||
|
@ -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 "  (".format_time(time() - $user->lastaccess).")";
|
||||
echo "  (".format_time(time() - $user->lastaccess, $string).")";
|
||||
} else {
|
||||
echo "$string->lastaccess: $string->never";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user