Code: Select all
function time_seconds_to_text(s)
{
//2024-05-15; Return seconds in to a text breakdown:
var r;
if (typeof s == 'number')
{
var d = Math.floor(s / (24 * 60 * 60));
s -= d * (24 * 60 * 60);
var h = Math.floor(s / (60 * 60));
s -= h * (60 * 60);
var m = Math.floor(s / (60));
s -= (m * (60));
r = ((d > 0) ? d+' day'+((d != 1) ? 's' : '')+',\ ' : '')+((h > 0) ? h+' hour'+((h != 1) ? 's' : '')+',\ ' : '')+((m > 0) ? m+' minute'+((m != 1) ? 's' : '')+' and ' : '')+s+' second'+((s != 1) ? 's' : '');
}
else {error_report(new Error('The s parameter was not a valid number type.'));}
return r;
}
Code: Select all
time_seconds_to_text(911321)
"10 days,13 hours,8 minutes and 41 seconds"
Now, it's working fine with a proper space:
Code: Select all
time_seconds_to_text(911321)
"10 days, 13 hours, 8 minutes and 41 seconds"