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:Japanese calendar/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}} This module is used to calculate dates in the [[Japanese calendar]]. It defines an "era" [[Class (computer programming)|class]] which is designed to be called from other Lua modules, and it also contains several functions to export Japanese calendar data directly to Wikipedia pages through #invoke. == Usage == === Through #invoke === * {{mlx|Japanese calendar|''function_name''|year{{=}}''year''|era{{=}}''article name or kanji''|previous{{=}}''yes''|next{{=}}''yes''}} The function name specifies how the data should be outputted. The <code>''year''</code> and <code>''era''</code> parameters determine what era and year the module outputs. The <code>''next''</code> and <code>''previous''</code> parameters tell the module to return data for the next or previous era, rather than the one specified. If a combination of parameters is invalid the module will usually output nothing. However, if both the <code>''next''</code> and <code>''previous''</code> parameters are specified it will output an error. ==== Year and era ==== The <code>''year''</code> parameter is the year in the [[Gregorian calendar]]. The <code>''era''</code> parameter can either be the article name for that era, or the era's name in [[kanji]]. (Transcribed English era names can usually be used, but will not work if they are ambiguous.) Either <code>''year''</code> or <code>''era''</code> must be specified. If both are specified, the module defaults to using <code>''era''</code> to get the era data. This enables output of the last year of the previous era (for example, Shōwa 64 is the same year as Heisei 1). {| class="wikitable" |- ! Code !! Output |- | <code><nowiki>{{#invoke:Japanese calendar|link|year=1950}}</nowiki></code> || {{#invoke:Japanese calendar|link|year=1950}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|era=Shōwa period}}</nowiki></code> || {{#invoke:Japanese calendar|link|era=Shōwa period}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|era=昭和}}</nowiki></code> || {{#invoke:Japanese calendar|link|era=昭和}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|era=Shōwa}}</nowiki></code> || {{#invoke:Japanese calendar|link|era=Shōwa}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1989}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1989}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1989|era=Shōwa period}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1989|era=Shōwa period}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1990}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1990}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1990|era=Shōwa period}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1990|era=Shōwa period}} |- |} ==== Functions ==== {| class="wikitable" |- ! Code !! Description !! Example |- | <code>baseyear</code> || The first year of the specified era. || <code><nowiki>{{#invoke:Japanese calendar|baseyear|era=Heisei}}</nowiki></code> → {{#invoke:Japanese calendar|baseyear|era=Heisei}} |- | <code>endyear</code> || The last year of the specified era. || <code><nowiki>{{#invoke:Japanese calendar|endyear|era=Shōwa period}}</nowiki></code> → {{#invoke:Japanese calendar|endyear|era=Shōwa period}} |- | <code>year</code> || The year for the specified era, without the era name. Defaults to the newer era, if more than one is applicable. || <code><nowiki>{{#invoke:Japanese calendar|year|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|year|year=1989}} |- | <code>kanjiyear</code> || The same as <code>''year''</code>, but in [[kanji]]. The first year of an era is changed to the kanji 元, and the others are changed to [[Halfwidth and fullwidth forms|full-width]] numbers. || <code><nowiki>{{#invoke:Japanese calendar|kanjiyear|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|kanjiyear|year=1989}} |- | <code>article</code> || The Wikipedia article for the era, unlinked. || <code><nowiki>{{#invoke:Japanese calendar|article|year=1950}}</nowiki></code> → {{#invoke:Japanese calendar|article|year=1950}} |- | <code>label</code> || The name of the era. Same as <code>''article''</code> for [[WP:DAB|undisambiguated]] titles. || <code><nowiki>{{#invoke:Japanese calendar|label|year=1950}}</nowiki></code> → {{#invoke:Japanese calendar|label|year=1950}} |- | <code>link</code> || A link to the Wikipedia article of the specified era. || <code><nowiki>{{#invoke:Japanese calendar|link|year=1950}}</nowiki></code> → {{#invoke:Japanese calendar|link|year=1950}} |- | <code>kanji</code> || The kanji for the specified era. || <code><nowiki>{{#invoke:Japanese calendar|kanji|year=1950}}</nowiki></code> → {{#invoke:Japanese calendar|kanji|year=1950}} |- | <code>label_year</code> || <code>''label''</code> followed by <code>''year''</code> || <code><nowiki>{{#invoke:Japanese calendar|label_year|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|label_year|year=1989}} |- | <code>link_year</code> || <code>''link''</code> followed by <code>''year''</code> || <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|link_year|year=1989}} |- | <code>label_kanjiyear</code> || <code>''label''</code> followed by <code>''kanjiyear''</code> || <code><nowiki>{{#invoke:Japanese calendar|label_kanjiyear|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|label_kanjiyear|year=1989}} |- | <code>link_kanjiyear</code> || <code>''link''</code> followed by <code>''kanjiyear''</code> || <code><nowiki>{{#invoke:Japanese calendar|link_kanjiyear|year=1989}}</nowiki></code> → {{#invoke:Japanese calendar|link_kanjiyear|year=1989}} |- |} ==== Next, previous and old ==== If the <code>''next''</code> parameter is specified, the module outputs the data for the subsequent era; if the <code>''previous''</code> parameter is specified it outputs the data for the previous one. If the <code>''old''</code> parameter is specified, the module outputs the data for the "old" era. This is the same as the current era unless the year is set to the first year of the specified era. If this is the case, then <code>''old''</code> outputs the data for the previous era. However, if the module could not find a valid previous era then the data for the current era is returned. {| class="wikitable" |- ! Code !! Output |- | <code><nowiki>{{#invoke:Japanese calendar|baseyear|era=Shōwa period}}</nowiki></code> || {{#invoke:Japanese calendar|baseyear|era=Shōwa period}} |- | <code><nowiki>{{#invoke:Japanese calendar|baseyear|era=Shōwa period|next=yes}}</nowiki></code> || {{#invoke:Japanese calendar|baseyear|era=Shōwa period|next=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|baseyear|era=Shōwa period|previous=yes}}</nowiki></code> || {{#invoke:Japanese calendar|baseyear|era=Shōwa period|previous=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|baseyear|era=Shōwa period|old=yes}}</nowiki></code> || {{#invoke:Japanese calendar|baseyear|era=Shōwa period|old=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|year=1880}}</nowiki></code> || {{#invoke:Japanese calendar|link|year=1880}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|year=1880|next=yes}}</nowiki></code> || {{#invoke:Japanese calendar|link|year=1880|next=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|year=1880|previous=yes}}</nowiki></code> || {{#invoke:Japanese calendar|link|year=1880|previous=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|link|year=1880|old=yes}}</nowiki></code> || {{#invoke:Japanese calendar|link|year=1880|old=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1926}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1926}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1926|old=yes}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1926|old=yes}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1927}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1927}} |- | <code><nowiki>{{#invoke:Japanese calendar|link_year|year=1927|old=yes}}</nowiki></code> || {{#invoke:Japanese calendar|link_year|year=1927|old=yes}} |- |} === From another Lua module === First of all, the era class must be loaded, like this: * <code lang="lua">local era = require( 'Module:Japanese calendar' ).era</code> Once the class is loaded, you can make a new era object using <code>era:new()</code>: * <code lang="lua>local myEra = era:new{ year = ''year'', era = ''article name or kanji'' }</code> Either <code>''year''</code> or <code>''era''</code> must be specified. It is also possible to use an <code>index</code> field, corresponding to the index of [[Module:Japanese calendar/data]], but this is for internal use only and will change as new eras are added. ==== Properties ==== Era objects have a number of properties. Their values might be <code>nil</code> if the module did not have enough information to process them, or the values could be <code>false</code> if they correspond to an invalid era. You can specify properties with the dot syntax: * <code lang="lua">local article = myEra.article</code> The properties are as follows: * <code>gregorianYear</code>: the year in the [[Gregorian calendar]]. Same as the input year. * <code>startYear</code>: the first year of the specified era. * <code>endYear</code>: the last year of the specified era. * <code>eraYear</code>: the year of the specified era, without the era name. * <code>eraYearKanji</code>: a string representing the era year in [[kanji]]. The first year of an era is changed to the kanji 元, and the others are changed to [[Halfwidth and fullwidth forms|full-width]] numbers. Note: even though the output may often look like a number, it will always be a string value. * <code>article</code>: the Wikipedia article for the era, unlinked. * <code>label</code>: the name of the era. Same as <code>article</code> unless the article title is [[WP:DAB|disambiguated]]. * <code>kanji</code>: the name of the era in kanji. ==== Methods ==== Era objects have three methods. Methods can be specified with the colon syntax: * <code lang="lua">local nextEra = myEra:getNextEra()</code> The methods are as follows: * <code lang="lua">era:getNextEra()</code> - gets the era object for the next era. Returns <code>nil</code> if it doesn't exist. * <code lang="lua">era:getPreviousEra()</code> - gets the era object for the previous era. Returns <code>nil</code> if it doesn't exist. * <code lang="lua">era:getOldEra()</code> - gets the era object for the "old" era. This is the same as the current era object unless eraYear equals 1. If eraYear equals 1 then this returns the era object for the previous era. If the module could not find a valid previous era object then the current era object is returned. <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:Mlx
(
edit
)
Template:Module rating
(
edit
)
Module:Convert character width
(
edit
)
Module:Convert character width/data
(
edit
)
Module:Japanese calendar
(
edit
)
Module:Japanese calendar/data
(
edit
)