ID:195106
 
//Title: Human-Readable Time
//Credit to: Foomer
//Contributed by: Jtgibson

/*
This is just for anyone who might want to use it. Could be useful in some text-
based games where everything is better when it's in flashy word-written format
and uses proper grammar. So, what this does is it accepts a single number of
seconds as an argument and outputs that number in days, hours, minutes and
seconds. As an example: num2time(50332) would return this: "13 hours, 58 minutes
and 52 seconds." If anyone wants it, you're free to use it in whatever you want.

(Special thanks to Jtgibson, since I butchered part of his ThingyList proc for
this.)
--Foomer

(Thingylist's current incarnation is found under the name
"Sentence-Formatted List Output Proc" on the Snippets Database. --Jtgibson.)
*/



proc/num2time(time, list/list=list())
var/seconds = time % 60
var/minutes = round(time/60) % 60
var/hours = round(time/3600) % 24
var/days = round(time/86400)

if(days) list += "[days] day\s"
if(hours) list += "[hours] hour\s"
if(minutes) list += "[minutes] minute\s"
if(seconds) list += "[seconds] second\s"

if(list.len > 2)
var/message
for(var/cycle = 1, cycle < list.len, cycle++)
message += "[list[cycle]], "
return "[message], and [list[list.len]]"
else if(list.len == 2) return "[list[1]] and [list[2]]"
else if(list.len == 1) return "[list[1]]"
else return


///*
//Testing code/sample implementation:
mob/verb/test_num2time()
usr << "The world has been running for [num2time(world.time/10)]."
//*/