Displaying course Dedication time in hours

Re: Displaying course Dedication time in hours

by Vinit Prajapati -
Number of replies: 0

Hello Juan,

I mean to say, instead of 1 day, 20 hours it shold display 44 hours.

So I made new function in moodlelib.php

    function format_hours_time($totalsecs){
        $totalsecs = abs($totalsecs);

        $hours     = floor($totalsecs/HOURSECS);
        $remainder = $totalsecs - ($hours*HOURSECS);
        $mins      = floor($remainder/MINSECS);
        $secs      = $remainder - ($mins*MINSECS);
        
        $ss = ($secs == 1)  ? 'Second'  : 'Seconds';
        $sm = ($mins == 1)  ? 'Minute'  : 'Minutes';
        $sh = ($hours == 1) ? 'Hour' : 'Hours';

        $ohours = '';
        $omins = '';
        $osecs = '';

        if ($hours) $ohours = $hours .' '. $sh;
        if ($mins)  $omins  = $mins .' '. $sm;
        if ($secs)  $osecs  = $secs .' '. $ss;

        if ($hours) return trim($ohours .' '. $omins);
        if ($mins)  return trim($omins .' '. $osecs);
        if ($secs)  return $osecs;
        return get_string('now');
    }

 

And called this function.

Thank you very much.

Vinit