Module:Year in various calendars/doc
![]() | This is a documentation subpage for Module:Year in various calendars. It may contain usage information, categories and other content that is not part of the original module page. |
Script error: No such module "Year in other calendars".
This module produces the sidebar opposite displaying a given Gregorian year in various different calendars.
Syntax
Simple
{{#invoke:Year in various calendars|main}}
All parameters
{{#invoke:Year in various calendars|main |year=(n) |footnotes=(footnotes) |gregcal=(article name)}}
Parameters
- year
- Number specifying the year to be displayed. This can be negative and also can be in the format "n BC" to display BC dates or "AD n" as an alternative to a positive number. If not specified, the current year is used.
- footnotes
- Any footnotes to be placed at the bottom of the sidebar.
- gregcal
- Name of an article to be displayed for Gregorian and Julian years (e.g. "2000 BC"). Do not include square brackets.
Microformat
The HTML mark-up produced by this template includes an hCalendar microformat that makes event/date details readily parsable by computer programs. This aids tasks such as the cataloguing of articles and maintenance of databases. For more information about the use of microformats on Wikipedia, please visit the Microformat WikiProject.
- Classes used
The HTML classes of this microformat include:
- attendee
- description
- dtend
- dtstart
- location
- summary
- url
- vevent
nor collapse nested elements which use them.
Adding new calendars
The module is set up to allow for easy addition of new calendars. Just scroll down to the "Build the box" section of the module code, and add your calendar as follows:
local myCalendar = calendar:new()
myCalendar:setLink( 'My calendar article' ) -- The name of the calendar's Wikipedia article.
myCalendar:setYearFunction(
function( year )
-- Lua code linking the Gregorian calendar year to your calendar's year.
end
)
box:addCalendar( myCalendar )
If you want to display just one year, then the Lua code should return one number value. If you want to display a year range, then the Lua code should return two number values. More complicated calendars can be displayed as text.
Technical details
The module defines three classes which do the work of setting up the sidebar and displaying the data provided by the calendar functions. These are the calendarBox
class, which defines the sidebar; the calendar
class, which holds the data for one calendar; and the calendarGroup
object, which defines a group of calendar objects with a heading.
To load these classes from another module, use the following:
local yearInOtherCalendars = require( 'Module:Year in other calendars' )
local calendarBox = yearInOtherCalendars.calendarBox
local calendarGroup = yearInOtherCalendars.calendarGroup
local calendar = yearInOtherCalendars.calendar
calendarBox class
The calendarBox
class is initiated with:
local myCalendarBox = calendarBox:new{ year = yyyy, footnotes = footnotes, navbar = page name }
year
- sets the Gregorian year to base calendar calculations on. If not specified, the current year is used.footnotes
- sets text to be displayed in a footnotes section at the bottom of the sidebar.navbar
- sets the page name to be used by the navbar.
Calendar box objects have the following methods:
myCalendarBox:addCalendar( obj )
- adds a calendar object or a calendar group object to the calendar box.myCalendarBox:addCalendarGroup( obj )
- an alias formyCalendarBox:addCalendar( obj )
.myCalendarBox:export()
- converts the calendar box object to wikicode. This method does most of the work - it detects whether the objects it processes are calendar objects or calendar group objects, and handles most of their formatting, as well as the formatting of the sidebar itself.
calendar class
The calendar
class is initiated with:
local myCalendar = calendar:new()
Calendar objects have the following methods:
myCalendar:setLink( link, display, italics )
- sets the link name for the calendar object.link
is the name of Wikipedia's article about the calendar,display
is an optional display name for the article link, and ifitalics
evaluates totrue
the link is displayed in italics.myCalendar:setLinkFunction( function( year ) block end )
- sets a function that specifies the link name depending on the Gregorian year value. The output must be a string, or if the output evaluates tonil
the calendar is not displayed.myCalendar:setYearFunction( function( year ) block end )
- sets a function to output the calendar year depending on the Gregorian year value. The function should output a number for a single year value, or two numbers for a year range. It can also output a string value for more complicated calendars. If the function evaluates tonil
then the calendar box will displayN/A
.
calendarGroup class
The calendarGroup
class is initiated with:
local myCalendarGroup = calendarGroup:new{ heading = heading, calendars = { calendar object 1, calendar object 2, ... } }
heading
- the wikitext heading for the calendar group (e.g.[[Hindu calendar]]s
).calendars
- an array containing calendar objects to be passed to a calendar box object.
Calendar group objects have only one method:
myCalendarBox:addCalendar( obj )
- adds a calendar object to the calendar group.