Timestamp Class

From SolarStrike wiki
Revision as of 21:08, 13 October 2015 by Elverion (talk | contribs) (Created page with " = The Timestamp class is an optional library = In order to use this class, you must require it in one of your source files (preferably main.lua) prior to use. It only needs t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Timestamp class is an optional library

In order to use this class, you must require it in one of your source files (preferably main.lua) prior to use. It only needs to be required once in a single file. It is recommended you do this at the top of your file, outside of any functions or other code, and you may do this by using this code:

require('timestamp');


Method Chaining Support

The Timestamp class supports method chaining, but does not modify the base object unless explicitly stated. That is, most functions will return a new Timestamp object with the modification made. For example:

t = Timestamp:now(); -- Assign 'now' to 't'

-- Assigning a value to a timestamp
t:addSeconds(5);     -- Invalid; 't' will not be modified!
t = t:addSeconds(5); -- Valid; 't' now contains 'now' + 5 seconds.

-- Method chaining
t = Timestamp:now():addSeconds(5);  -- Also valid; 't' contains 'now' + 5 seconds.


Supported Methods

Constructor

class Timestamp(number year, number month, number day, number hour, number minutes, number seconds)

class Timestamp(number unixTime)

class Timestamp()

Creates a Timestamp object out of an arbitrarily defined date and time. Any field that is nil should be assumed from the current time. That is, leaving 'year' as nil will assume the real, current year pulled from your computer's clock, while any given fields will be filled with the information you have provided.

You may also pass a UNIX timestamp.


Timestamp:now

class Timestamp:now()

Returns a Timestamp object that contains the current date/time value of your computer's clock.


Timestamp:today

class Timestamp:today()

Returns a Timestamp object that contains the current date with time starting at 12:00AM.


Timestamp:yesterday

class Timestamp:yesterday

Exactly like Timestamp:today() except it is for yesterday's date/time.


Timestamp:tomorrow

class Timestamp:tomorrow

Exactly like Timestamp:today() except it is for tomorrow's date/time.