Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Year in various calendars/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{module rating|beta}} {{#invoke:Year in various calendars|main}} {{Year in various calendars/doc|type=module}} === 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: To display one year: <div style="overflow: auto;"><syntaxhighlight lang="lua"> local myCalendar = calendar:new() myCalendar:setLink( 'My calendar article' ) -- The name of the calendar's Wikipedia article. myCalendar:setYear( year + 10 ) -- Lua code linking the Gregorian calendar year to your calendar's year. box:addCalendar( myCalendar ) </syntaxhighlight></div> To display a year range: <div style="overflow: auto;"><syntaxhighlight lang="lua"> local myCalendar = calendar:new() myCalendar:setLink( 'My calendar article' ) -- The name of the calendar's Wikipedia article. myCalendar:setYearRange( year + 10, year + 11 ) -- Lua code outputting the start year and the end year of the year range. box:addCalendar( myCalendar ) </syntaxhighlight></div> More complicated calendars can be passed as a string to <code>calendar:setYear()</code>. === Technical details === The module defines three [[class (programming)|classes]] which do the work of setting up the sidebar and displaying the data provided by the calendar functions. These are the <code>calendarBox</code> class, which defines the sidebar; the <code>calendar</code> class, which holds the data for one calendar; and the <code>calendarGroup</code> object, which defines a group of calendar objects with a heading. To load these classes from another module, use the following: <div style="overflow: auto;"><syntaxhighlight lang="lua"> local yearInOtherCalendars = require( 'Module:Year in various calendars' ) local calendarBox = yearInOtherCalendars.calendarBox local calendarGroup = yearInOtherCalendars.calendarGroup local calendar = yearInOtherCalendars.calendar </syntaxhighlight></div> ==== calendarBox class ==== A <code>calendarBox</code> object is initiated with: {{pre| <nowiki>local myCalendarBox = calendarBox:new{ year = </nowiki>''yyyy''<nowiki>, footnotes = </nowiki>''footnotes''<nowiki>, navbar = </nowiki>''page name''<nowiki> }</nowiki> }} * <code>year</code> - sets the Gregorian year to base calendar calculations on. If not specified, the current year is used. * <code>footnotes</code> - sets text to be displayed in a footnotes section at the bottom of the sidebar. * <code>navbar</code> - sets the page name to be used by the [[Template:Navbar|navbar]]. Calendar box objects have the following properties: * <code>calendarBox.year</code> - the Gregorian year number. This is negative for BC years; for example, for the year 100 BC the value of calendarBox.year is <code>-99</code>. (BC years are calculated by "1 - n" rather than "0 - n", as there is no year zero.) * <code>calendarBox.yearText</code> - the Gregorian year text. This is a string value of the format "n" for AD years and "n BC" for BC years. * <code>calendarBox.caption</code> - the text of the box caption (the bold text that appears directly above the box). The default caption is the value of <code>calendarBox.yearText</code>. * <code>calendarBox.footnotes</code> - the text of the box footnotes. * <code>calendarBox.navbar</code> - the page name used by the navbar. Calendar box objects have the following methods: * <code>calendarBox:setCaption( ''caption'' )</code> - sets the box caption (the bold text that appears directly above the box). The default caption is the value of <code>calendarBox.yearText</code>. * <code>calendarBox:addCalendar( ''obj'' )</code> - adds a calendar object or a calendar group object to the calendar box. * <code>calendarBox:addCalendarGroup( ''obj'' )</code> - an alias for <code>myCalendarBox:addCalendar()</code>. * <code>calendarBox:export()</code> - converts the calendar box object to wikicode. This calls <code>calendar:export()</code> and <code>calendarGroup:export()</code> to export calendar objects and calendar group objects. ==== calendar class ==== A <code>calendar</code> object is initiated with: {{pre| <nowiki>local myCalendar = calendar:new()</nowiki> }} Calendar objects have the following properties: * <code>calendar.link</code> - the link name. * <code>calendar.year</code> - the year value. This is always a string value. Calendar objects have the following methods: * <code>calendar:setLink( ''link'', ''display'' )</code> - sets the link name for the calendar object. <code>''link''</code> is the name of Wikipedia's article about the calendar, and <code>''display''</code> is an optional display name for the article link. * <code>calendar:setRawLink( ''wikitext'' )</code> - sets the calendar link as raw wikitext. * <code>calendar:getLink()</code> - gets the link value. * <code>calendar:setYear( ''year'' )</code> - sets the year value for the calendar. <code>''year''</code> can be a number or a string. * <code>calendar:setYearRange( ''startYear'', ''endYear'' )</code> - sets the year value for the calendar as a year range. Both <code>''startYear''</code> and <code>''endYear''</code> must be number values. * <code>calendar:export()</code> - exports the calendar to wikitext. If no link value was found, this returns <code>nil</code>. If a link was found but no year value was found, the calendar is output with a value of <code>''N/A''</code> for the year. ==== calendarGroup class ==== A <code>calendarGroup</code> object is initiated with: {{pre| <nowiki>local myCalendarGroup = calendarGroup:new{ heading = </nowiki>''heading''<nowiki> }</nowiki> }} * <code>heading</code> - the wikitext heading for the calendar group (e.g. <code><nowiki>[[Hindu calendar]]s</nowiki></code>). Calendar group objects have one property: * <code>calendarGroup.heading</code> - the calendar group heading text. Calendar group objects have the following methods: * <code>calendarGroup:addCalendar( ''obj'' )</code> - adds a calendar object to the calendar group. * <code>calendarGroup:export()</code> - converts a calendar group to wikitext. Calls <code>calendar:export()</code> to export individual calendar objects. === See also === {{tl|Year in various calendars}} <includeonly>{{Sandbox other|| [[Category:Time, date and calendar modules]] }}</includeonly>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Module rating
(
edit
)
Template:Pre
(
edit
)
Template:Tl
(
edit
)
Template:Year in various calendars/doc
(
edit
)
Module:Ancient Egypt era
(
edit
)
Module:Ancient Egypt era/data
(
edit
)
Module:Ancient Egypt kings
(
edit
)
Module:Ancient Egypt kings/data
(
edit
)
Module:Ancient Olympiads
(
edit
)
Module:Ancient Olympiads/data
(
edit
)
Module:Arguments
(
edit
)
Module:Armenian
(
edit
)
Module:British regnal year
(
edit
)
Module:British regnal year/data
(
edit
)
Module:Convert character width
(
edit
)
Module:Convert character width/data
(
edit
)
Module:Japanese calendar
(
edit
)
Module:Japanese calendar/data
(
edit
)
Module:Roman
(
edit
)
Module:TableTools
(
edit
)
Module:Year in various calendars
(
edit
)