LLMS_Date::convert_to_hours_minutes_string( $time )


Source Source

File: includes/class.llms.date.php

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
public static function convert_to_hours_minutes_string( $time ) {
    $decimal_part = $time - floor( $time );
    settype( $time, 'integer' );
    if ( $time < 1 ) {
        return;
    }
    $hours   = floor( $time / 60 );
    $minutes = ( $time % 60 );
    $seconds = ( 60 * $decimal_part );
 
    $hours_string   = '';
    $minutes_string = '';
    $seconds_string = '';
 
    // Determine hours vs hour in string.
    if ( ! empty( $hours ) ) {
        if ( $hours > 1 ) {
            $hour_desc = __( 'hours', 'lifterlms' );
        } else {
            $hour_desc = __( 'hour', 'lifterlms' );
        }
 
        $hours_string = sprintf( __( '%1$d %2$s ', 'lifterlms' ), $hours, $hour_desc );
    } else {
        if ( ! empty( $seconds ) ) {
            if ( $seconds > 1 ) {
                $second_desc = __( 'seconds', 'lifterlms' );
            } else {
                $second_desc = __( 'second', 'lifterlms' );
            }
 
            $seconds_string = sprintf( ' %d %s', $seconds, $second_desc );
 
        }
    }
 
    // Determine minutes vs minute in string.
    if ( ! empty( $minutes ) ) {
        if ( $minutes > 1 ) {
            $minute_desc = __( 'minutes', 'lifterlms' );
        } else {
            $minute_desc = __( 'minute', 'lifterlms' );
        }
 
        $minutes_string = sprintf( ' %d %s', $minutes, $minute_desc );
 
    }
 
    return $hours_string . $minutes_string . $seconds_string;
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.