The @calendar module is just a single class @calendar which is used to get information about a timestamp with regards to the Gregorian calendar.

Methods

:new(timestamp) #

Create a new calendar instance.

Parameters

Return

Notes

Timestamps can be created from date parts with :time(). To deal with time zones, add or subtract the offset from the timestamp.

:parts() #

Get date parts.

Return

Notes

The returned object is like:

{ year : number (negative numbers represent BC), month : number (1-12), day : number (1-31), weekday : number (0-6 starting from Sunday), hour : number (0-23), minute : number (0-59), second : number (0-59) }

If you need to convert a timestamp to a date string, consider using :date() instead.

:chart() #

Get the month chart as a 2D array.

Return

Notes

Each row in the returned array is a week with 7 elements. Each element is a number corresponding to the day number. If the element is not part of the month, the day number is 0.

:next_month() #

Shift calendar to first day of next month.

:prev_month() #

Shift calendar to first day of previous month.

:tomorrow() #

Shift calendar to midnight (12 AM) of next day.

:yesterday() #

Shift calendar to midnight (12 AM) of previous day.

:holiday(day) #

Check if the day is a holiday.

Parameters

Return

Notes

The possible return values (and thus supported holidays) are:

'New Year\'s Day' #janary 1 'Martin Luther King Jr. Day' #third monday in january 'Valentine\'s Day' #february 14 'Presidents\' Day'. #third monday in february 'St. Patrick\'s Day' #march 17 'Spring Equinox' #march 20 'Memorial Day' #last monday in may 'Summer Solstice' #jun 21 'Independence Day' #july 4 'Labor Day' #first monday in september 'Fall Equinox' #september 23 'Columbus Day' #second monday in october 'Halloween' #october 31 'Veteran\'s Day' #november 11 'Thanksgiving Day' #fourth thursday in november 'Winter Solstice' #december 22 'Christmas Day' #december 25 'Easter' #determined by computus 'Mardi Gras' #determined by computus

This is US-centric and not meant to be an exhaustive list. The computus is the algorithm for determining Easter. The equinoxes and solstices may be off by one day due to leap years. If you need to support additional holidays or better accuracy, you should create your own holiday() function.

:time() #

Convert calendar back into timestamp.

Return

:text(colorize,now) #

Get month chart as text.

Parameters

Return

Notes

If colorize is true, the current day is highlighted and holidays are underlined. This imitates the output of the "cal" command-line tool. The current day can be overridden by passing another timestamp as now.

:html(now) #

Get month chart as html.

Parameters

Return

Notes

This is similar to :text() except it places the chart within an HTML <pre> tag. The current day is highlighted, and past days are greyed out. Holidays are underlined and labeled with a tooltip. The current day can be overridden by passing another timestamp as now.