ID:2129182
 
Pretty simple conversion of Ticks or Seconds into a list of Days, Hours, Minutes and Seconds (and Ticks).

Can be useful for quickly displaying time in a user friendly format while allowing you to work with the smallest measurements.

Lib:
#define TICKS_IN_A_SECOND 10
#define SECONDS_IN_A_MINUTE 60
#define MINUTES_IN_AN_HOUR 60
#define HOURS_IN_A_DAY 24


proc/tickConversion(var/totalTicks as num)
var/ticks = totalTicks % TICKS_IN_A_SECOND
var/totalSeconds = round(totalTicks / TICKS_IN_A_SECOND)
var/seconds = totalSeconds % SECONDS_IN_A_MINUTE
var/totalMinutes = round(totalSeconds / SECONDS_IN_A_MINUTE)
var/minutes = totalMinutes % MINUTES_IN_AN_HOUR
var/totalHours = round(totalMinutes / MINUTES_IN_AN_HOUR)
var/hours = totalHours % HOURS_IN_A_DAY
var/days = round(totalHours / HOURS_IN_A_DAY)
var/list/L = list(ticks,seconds,minutes,hours,days)
return L

proc/secondConversion(var/totalSeconds as num)
var/seconds = totalSeconds % SECONDS_IN_A_MINUTE
var/totalMinutes = round(totalSeconds / SECONDS_IN_A_MINUTE)
var/minutes = totalMinutes % MINUTES_IN_AN_HOUR
var/totalHours = round(totalMinutes / MINUTES_IN_AN_HOUR)
var/hours = totalHours % HOURS_IN_A_DAY
var/days = round(totalHours / HOURS_IN_A_DAY)
var/list/L = list(seconds,minutes,hours,days)
return L


Format:
var/list/L = tickConversion(value)      // L[1] is the ticks
// L[2] is the seconds
// L[3] is the minutes
// L[4] is the hours
// L[5] is the days


var/list/L = secondConversion(value) // L[1] is the seconds
// L[2] is the minutes
// L[3] is the hours
// L[4] is the days
Could have it stored in the list under keys as well, that way we can just call L ["hour"] or even use byonds time2text as a reference for how to name the keys.
You could also use a define as an alias for the keys

#define TIME_TICKS 1
#define TIME_SECONDS 2
#define TIME_MINUTES 3
#define TIME_HOURS 4
#define TIME_DAYS 5

/proc/getCooldown(value)
. = tickConversion(value)
if(.[TIME_TICKS] >= 1)
return .
return null