Time Module

[release]
Time Module v1
Back in the day I used to play Tremulous, and when you banned someone, you could do it by specifying time units with letters, rather than the number of minutes which you have to do in gmod.
To my mind, this makes a lot more sense, as !ban player 2d go away is so much simpler than !ban player 2880 go away.
So, I wrote this module.
There are 4 functions:
[ul]
[li]time.SecondsToTimestring(time): Converts a time into a timestring[/li][li]time.SecondsToUnit(time, unit): Converts a time in seconds into units[/li][li]time.TimestringToSeconds(str): Converts a timestring into seconds[/li][li]time.UnitToSeconds(time, unit): Converts time of one unit to seconds [/li][/ul]
and 5 constants:
[ul]
[li]time.YEAR: Used to specify years in unit conversions[/li][li]time.WEEK: Used to specify weeks in unit conversions[/li][li]time.DAY: Used to specify days in unit conversions[/li][li]time.HOUR: Used to specify hours in unit conversions[/li][li]time.MINUTE: Used to specify minutes in unit conversions[/li][/ul]
Usage is pretty straight forward, so I hope to see more user friendly chat commands in the future. :3:
Please do say if you use it.
Example
[lua]–[[
~ Time Example ~
~ Lexi ~
–]]
require(“time”);
local secs = 1 + time.UnitToSeconds(2, time.MINUTE) + time.UnitToSeconds(3, time.HOUR) + time.UnitToSeconds(4, time.DAY) + time.UnitToSeconds(5, time.WEEK) + time.UnitToSeconds(6, time.YEAR);
print(time.SecondsToTimestring(secs)); – 6y5w4d3h2m1s

function ParsePotentialTimeString(words)
local num = tonumber(words);
return num and num or time.TimestringToSeconds(words);
end[/lua]
Download
[ul]
[li][Module][/li][li][Example][/li][li][Full Documentation][/li][/ul]
[/release]

Thats very useful

This is really cool.

That’s very helpful.