1. Post #1
    Gold Member
    Lexic's Avatar
    March 2009
    6,114 Posts
    [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:
    [list][*]time.SecondsToTimestring(time): Converts a time into a timestring[*]time.SecondsToUnit(time, unit): Converts a time in seconds into units[*]time.TimestringToSeconds(str): Converts a timestring into seconds[*]time.UnitToSeconds(time, unit): Converts time of one unit to seconds [/list]and 5 constants:
    [list][*]time.YEAR: Used to specify years in unit conversions[*]time.WEEK: Used to specify weeks in unit conversions[*]time.DAY: Used to specify days in unit conversions[*]time.HOUR: Used to specify hours in unit conversions[*]time.MINUTE: Used to specify minutes in unit conversions[/list]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
    --[[
        ~ 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
    Download
    [list][*][Module][*][Example][*][Full Documentation][/list][/release]
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Useful Useful x 1 (list)

  2. Post #2
    King of the Oil Refinery
    Tobba's Avatar
    December 2008
    6,814 Posts
    Thats very useful

  3. Post #3
    c-unit's Avatar
    March 2010
    1,669 Posts
    This is really cool.

  4. Post #4
    Gold Member
    DiscoBiscut's Avatar
    June 2008
    2,034 Posts
    That's very helpful.