Indice
Time Object
The TimeObj represent a very handy way to manage dates and times, this object have several methods that will make your life easier when dealing with dates.
- TimeObj:Add(tObj)
- TimeObj:New(timedef)
- TimeObj:NewFileLastChange(filename)
- TimeObj:NewNow()
- TimeObj:Sub(tObj)
- TimeObj:dbgPrint()
- TimeObj:equalTo(tObj, threshold)
- TimeObj:fromSeconds(seconds)
- TimeObj:fromString(s, mode)
- TimeObj:fromUnixTimeStamp(timestamp)
- TimeObj:greaterThan(tObj, threshold)
- TimeObj:lesserThan(tObj, threshold)
- TimeObj:toSeconds()
- TimeObj:toString(fmt)
- TimeObj:toUnixTimeStamp()
TimeObj:Add(tObj)
result = TimeObj:Add(tObj)
Add to the time object the specified tObj.
The result will be returned to a new time object.
INPUT
- tObj : A timeObject to add the time object.
OUTPUT
- result : A new time object representing the result of the addition.
EXAMPLE
Local t1 = TimeObj:NewNow() Local t2 = TimeObj:New("20-00-0000 04:00:00") ; Add t2 from t1, t2 represents 20 days and 4 hours so we are going ; to add 20 days and 4 hours from the current time. Local t3 = t1:Sub(t2) t3:dbgPrint()
TimeObj:New(timedef)
timeObj = TimeObj:New(timeDef)
Returns a new Time object, optionally the object can be initialized with the value passed by the 'timeDef' argument.
INPUT
- timeDef : This argument specify the value we want to use to intialize the object, the following types are recognized:
→ #TABLE : You have to pass a table with the day, month, year, hour, minute, second and millis fields
→ #NUMBER : You have to pass a number of seconds that will be converted in a complete date
→ #STRING : You have to pass a string representing a date with the format dd-mm-yyyy hh:mm:ss
OUTPUT
- timeObj : A new time object
EXAMPLE
Here is how you can create a new time object using a table:
Local myTime = TimeObj:New( { 20, 2, 2016, 18, 44, 20, 0 }) ; d m y h m a mi
Now let's try using a number (of seconds):
Local myTime = TimeObj:New(2736664)
And here is how you can use a string:
Local myTime = TimeObj:New("20-02-2016 18:44:20")
To create and empty object:
Local myTime = TimeObj:New()
TimeObj:NewFileLastChange(filename)
TimeObject = TimeObj:NewFileLastChange(filename)
Create a new time object and load it with the last modify date of the given file.
INPUT
- filename : Where we want to pick the last modify change
OUTPUT
- TimeObject : The new time object or NIL if 'filename' does not exists.
TimeObj:NewNow()
timeObject = TimeObj:NewNow()
Returns a new time object loaded with the current date and time
OUTPUT
- timeObject : New time object
TimeObj:Sub(tObj)
result = TimeObj:Sub(tObj)
Subtract from the time object the specified tObj.
The result will be returned to a new time object.
INPUT
- tObj : A timeObject to subtract from the time object.
OUTPUT
- result : A new time object representing the result of the subtraction.
EXAMPLE
Local t1 = TimeObj:NewNow() Local t2 = TimeObj:New("20-00-0000 04:00:00") ; Subtract t2 from t1, t2 represents 20 days and 4 hours so we are going ; to subtract 20 days and 4 hours from the current time. Local t3 = t1:Sub(t2) t3:dbgPrint()
TimeObj:dbgPrint()
TimeObj:dbgPrint()
Prints to the console the current object value with the format dd-mm-yyyy hh:mm:ss.mmm
TimeObj:equalTo(tObj, threshold)
result = TimeObj:equalThan(tObj, threshold)
Check id the time object is equal to tObj using an optional threshold espressed in seconds.
INPUT
- tObj : Time object
- threshold : threshold value expressed in seconds (optional)
OUTPUT
- result : The result of comparison: True if time object is equal to tObj otherwise False.
TimeObj:fromSeconds(seconds)
TimeObj:fromSeconds(seconds)
Load the time object with the given seconds
INPUT
- seconds : A value expressed in seconds
TimeObj:fromString(s, mode)
TimeObj:fromString(str, format)
Load the time object with the given string using the specified format.
INPUT
- str : The string representing the date and time
- format : the format to use with the given string:
→ 0 (default) : dd-mm-yyyy hh:mm:ss
→ 1 : yyyy-mm-dd hh:mm:ss
→ 2 : dd-mmm-yyyy hh:mm:ss (Hollywood format)
→ 3 : yy-mm-dd hh:mm:ss
→ 4 : dd-mm-yy hh:mm:ss
TimeObj:fromUnixTimeStamp(timestamp)
TimeObj:fromUnixTimeStamp(timeStamp)
Load the time object with the given Unix TimeStamp value
INPUT
- timeStamp : Unix time stamp value
TimeObj:greaterThan(tObj, threshold)
result = TimeObj:greaterThan(tObj, threshold)
Check id the time object is greater than tObj using an optional threshold espressed in seconds.
INPUT
- tObj : Time object
- threshold : threshold value expressed in seconds (optional)
OUTPUT
- result : The result of comparison: True if time object is greater than tObj otherwise False.
TimeObj:lesserThan(tObj, threshold)
result = TimeObj:lesserThan(tObj, threshold)
Check id the time object is lesser than tObj using an optional threshold espressed in seconds.
INPUT
- tObj : Time object
- threshold : threshold value expressed in seconds (optional)
OUTPUT
- result : The result of comparison: True if time object is lesser than tObj otherwise False.
TimeObj:toSeconds()
seconds = TimeObj:toSeconds()
Returns the time object expressed in seconds
OUTPUT
- seconds : The date and time expressed in seconds
TimeObj:toString(fmt)
result = TimeObj:fromUnixTimeStamp(fmt)
Returns the time object with a string notation using the optional format 'fmt'
INPUT
- fmt : The string format you want as result
→ NIL : dd-mm-yyyy hh:mm:ss
→ 1 : dd-mmm-yyyy hh:mm:ss, thisis the standard Hollywood format
OUTPUT
- result : The string representing the date and time
NOTES
You could have also negative dates, in this case the date will be signed with the minus character.
TimeObj:toUnixTimeStamp()
result = TimeObj:toUnixTimeStamp()
Returns the Unix TimeStamp value
OUTPUT
- result : The time converted into the Unix timestamp format