Naev

Module time

Bindings for interacting with the time.

Usage is generally something as follows:

 time_limit = time.get() + time.create( 0, 5, 0 )
 player.msg( string.format("You only have %s left!", time.str(time.get() - time_limit)) )

-- Do stuff here

if time.get() > time_limit then -- Limit is up end

Functions

create (cycles, periods, seconds) Creates a time.
add (t1, t2) Adds two time metatables.
sub (t1, t2) Subtracts two time metatables.
__eq (t1, t2) Checks to see if two time are equal.
__lt (t1, t2) Checks to see if a time is strictly larger than another.
__le (t1, t2) Checks to see if a time is larger or equal to another.
get () Gets the current time in internal representation time.
str (t[, d=2]) Converts the time to a pretty human readable format.
inc (t) Increases or decreases the time.
tonumber (t) Gets a number representing this time.
fromnumber (num) Creates a time from a number representing it.


Functions

create (cycles, periods, seconds)
Creates a time. This can be absolute or relative. ( cycles, periods, seconds )

Parameters:

  • cycles number Cycles for the new time.
  • periods number Periods for the new time.
  • seconds number Seconds for the new time.

Returns:

    Time A newly created time metatable.

Usage:

    t = time.create( 591, 3271, 12801 ) -- Gets a time near when the incident happened.
add (t1, t2)
Adds two time metatables.

Overrides the addition operator. ( t1, t2)

Parameters:

  • t1 Time Time metatable to add to.
  • t2 Time Time metatable added.

Usage:

    new_time = time.get() + time.create( 0, 5, 0 ) -- Adds 5 periods to the current date
sub (t1, t2)
Subtracts two time metatables.

Overrides the subtraction operator. ( t1, t2)

Parameters:

  • t1 Time Time metatable to subtract from.
  • t2 Time Time metatable subtracted.

Usage:

    new_time = time.get() - time.create( 0, 3, 0 ) -- Subtracts 3 periods from the current date
__eq (t1, t2)
Checks to see if two time are equal.

It is recommended to check with < and <= instead of ==. ( t1, t2 )

Parameters:

  • t1 Time Time to compare for equality.
  • t2 Time Time to compare for equality.

Returns:

    boolean true if they're equal.

Usage:

    if time.create( 630, 5, 78) == time.get() then -- do something if they match
__lt (t1, t2)
Checks to see if a time is strictly larger than another. ( t1, t2 )

Parameters:

  • t1 Time Time to see if is is smaller than t2.
  • t2 Time Time see if is larger than t1.

Returns:

    boolean true if t1 < t2

Usage:

    if time.create( 630, 5, 78) < time.get() then -- do something if time is past UST 630:0005.78
__le (t1, t2)
Checks to see if a time is larger or equal to another. ( t1, t2 )

Parameters:

  • t1 Time Time to see if is is smaller or equal to than t2.
  • t2 Time Time see if is larger or equal to than t1.

Returns:

    boolean true if t1 <= t2

Usage:

    if time.create( 630, 5, 78) <= time.get() then -- do something if time is past UST 630:0005.78
get ()
Gets the current time in internal representation time. ()

Returns:

    Time Time in internal representation time.

Usage:

    t = time.get()
str (t[, d=2])
Converts the time to a pretty human readable format. ( t, d )

Parameters:

  • t Time Time to convert to pretty format. If omitted, current time is used.
  • d number Decimals to use for displaying seconds (should be between 0 and 5). (default 2)

Returns:

    string The time in human readable format.

Usage:

  • strt = time.str() -- Gets current time
  • strt = time.str( nil, 5 ) -- Gets current time with full decimals
  • strt = time.str( time.get() + time.create(0,5,0) ) -- Gets time in 5 periods
  • strt = t:str() -- Gets the string of t
inc (t)
Increases or decreases the time. ( t )

Parameters:

  • t Time Amount to increment or decrement the time by.

Usage:

    time.inc( time.create(0,0,100) ) -- Increments the time by 100 seconds.
tonumber (t)
Gets a number representing this time.

The best usage for this currently is mission variables. ( t )

Parameters:

  • t Time Time to get number of.

Returns:

    number Number representing time.

Usage:

    num = t:tonumber() -- Getting the number from a time t
fromnumber (num)
Creates a time from a number representing it.

The best usage for this currently is mission variables. ( num )

Parameters:

  • num number Number to get time from.

Returns:

    Time Time representing number.

Usage:

    t = time.fromnumber( t:tonumber() ) -- Should get the time t again
generated by LDoc 1.4.6 Last updated 2020-11-30 06:21:28