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().

: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.

:midnight() #

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

:tomorrow() #

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

:yesterday() #

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

: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.

Functions

:default_holidays(year,month,day,weekday) #

Check if the specified date is a holiday.

Parameters

Return

Notes

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

New Year's Day              (January 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             (June 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)

The computus is the algorithm for determining Easter. The equinoxes and solstices may be off by one day due to leap years.

This provides a default set of holidays which are used by :text() and :html(). To customize the holidays, see :use_holidays().

:use_holidays(holidays_callback) #

Set a custom callback for determining holidays.

Parameters

Notes

If holidays_callback is null, then :default_holidays() is used to determine holidays.

Example

#add Juneteenth to the calendar
:my_holidays(y,m,d,w)
	if m==6 && d==19
		return 'Juneteenth'
	return calendar.default_holidays(y,m,d,w)

calendar.use_holidays(my_holidays)
print calendar(time(2025,6,1)).text()