The @calendar
module is just a single class @calendar
which is used to get information about a timestamp with regards to the
Gregorian calendar.
Create a new calendar instance.
Timestamps can be created from date parts with :time().
Get date parts.
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.
Get the month chart as a 2D array.
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.
Shift calendar to first day of next month.
Shift calendar to first day of previous month.
Shift calendar to midnight (12 AM) of current day.
Shift calendar to midnight (12 AM) of next day.
Shift calendar to midnight (12 AM) of previous day.
Convert calendar back into timestamp.
Get month chart as text.
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.
Get month chart as html.
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.
Check if the specified date is a holiday.
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().
Set a custom callback for determining holidays.
If holidays_callback is null, then :default_holidays() is used to determine holidays.
#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()