Module pl.Date

Date and Date Format classes.

See the Guide.

Dependencies: pl.class , pl.stringx

Functions

Date (t) Date constructor.
Date.tzone () get the time zone offset from UTC.
Date:toUTC () convert this date to UTC.
Date:toLocal () convert this UTC date to local.
Date:set (t) set the current time of this Date object.
Date:year (y) set the year.
Date:month (m) set the month.
Date:day (d) set the day.
Date:hour (h) set the hour.
Date:min (min) set the minutes.
Date:sec (sec) set the seconds.
Date:yday (yday) set the day of year.
Date:year (y) get the year.
Date:month () get the month.
Date:day () get the day.
Date:hour () get the hour.
Date:min () get the minutes.
Date:sec () get the seconds.
Date:yday () get the day of year.
Date:weekday_name (full) name of day of week.
Date:month_name (full) name of month.
Date:is_weekend () is this day on a weekend?.
Date:add (t) add to a date object.
Date:last_day () last day of the month.
Date:diff (other) difference between two Date objects.
Date:__tostring () long numerical ISO data format version of this date.
Date:__eq () equality between Date objects.
Date:__lt () equality between Date objects.
Date.Format (fmt.) Date.Format constructor.
Date.Format:parse (str) parse a string into a Date object.
Date.Format:tostring (d) convert a Date object into a string.


Functions

Date (t)
Date constructor.

Parameters:

  • t: this can be either
    • nil – use current date and time
    • number – seconds since epoch (as returned by os.time)
    • Date – copy constructor
    • table – table containing year, month, etc as for os.time() You may leave out year, month or day, in which case current values will be used.
    • two to six numbers: year, month, day, hour, min, sec
Date.tzone ()
get the time zone offset from UTC.

Returns:

  1. hours ahead of UTC
  2. minutes ahead of UTC
Date:toUTC ()
convert this date to UTC.
Date:toLocal ()
convert this UTC date to local.
Date:set (t)
set the current time of this Date object.

Parameters:

  • t: seconds since epoch
Date:year (y)
set the year.

Parameters:

  • y: Four-digit year
Date:month (m)
set the month.

Parameters:

  • m: month
Date:day (d)
set the day.

Parameters:

  • d: day
Date:hour (h)
set the hour.

Parameters:

  • h: hour
Date:min (min)
set the minutes.

Parameters:

  • min: minutes
Date:sec (sec)
set the seconds.

Parameters:

  • sec: seconds
Date:yday (yday)
set the day of year.

Parameters:

  • yday: day of year
Date:year (y)
get the year.

Parameters:

  • y: Four-digit year
Date:month ()
get the month.
Date:day ()
get the day.
Date:hour ()
get the hour.
Date:min ()
get the minutes.
Date:sec ()
get the seconds.
Date:yday ()
get the day of year.
Date:weekday_name (full)
name of day of week.

Parameters:

  • full: abbreviated if true, full otherwise.

Returns:

    string name
Date:month_name (full)
name of month.

Parameters:

  • full: abbreviated if true, full otherwise.

Returns:

    string name
Date:is_weekend ()
is this day on a weekend?.
Date:add (t)
add to a date object.

Parameters:

  • t: a table containing one of the following keys and a value:
    year,month,day,hour,min,sec

Returns:

    this date
Date:last_day ()
last day of the month.

Returns:

    int day
Date:diff (other)
difference between two Date objects. Note: currently the result is a regular ?que object, but also has interval field set, which means a more appropriate string rep is used.

Parameters:

  • other: Date object

Returns:

    a Date object
Date:__tostring ()
long numerical ISO data format version of this date.
Date:__eq ()
equality between Date objects.
Date:__lt ()
equality between Date objects.
Date.Format (fmt.)
Date.Format constructor.

Parameters:

  • fmt.: A string where the following fields are significant:
    • d day (either d or dd)
    • y year (either yy or yyy)
    • m month (either m or mm)
    • H hour (either H or HH)
    • M minute (either M or MM)
    • S second (either S or SS)
    Alternatively, if fmt is nil then this returns a flexible date parser that tries various date/time schemes in turn:
    1. ISO 8601,

      like 2010-05-10 12:35:23Z or 2008-10-03T14:30+02<li>
      

    2. times like 15:30 or 8.05pm (assumed to be today’s date)
    3. dates like 28/10/02 (European order!) or 5 Feb 2012
    4. month name like march or Mar (case-insensitive, first 3 letters); here the day will be 1 and the year this current year
    A date in format 3 can be optionally followed by a time in format 2. Please see test-date.lua in the tests folder for more examples.

Usage:

    df = Date.Format("yyyy-mm-dd HH:MM:SS")
Date.Format:parse (str)
parse a string into a Date object.

Parameters:

  • str: a date string

Returns:

    date object
Date.Format:tostring (d)
convert a Date object into a string.

Parameters:

  • d: a date object, or a time value as returned by os.time

Returns:

    string
generated by LDoc 1.2