Module:Japanese calendar/doc

This module is used to calculate dates in the Japanese calendar. It defines an "era" 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.

Through #invoke


The function name specifies how the data should be outputted. The  and   parameters determine what era and year the module outputs. The  and   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  and   parameters are specified it will output an error.

Year and era
The  parameter is the year in the Gregorian calendar. The  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  or   must be specified. If both are specified, the module defaults to using  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).

Next, previous and old
If the  parameter is specified, the module outputs the data for the subsequent era; if the   parameter is specified it outputs the data for the previous one. If the  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  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.

From another Lua module
First of all, the era class must be loaded, like this:



Once the class is loaded, you can make a new era object using :



Either  or   must be specified. It is also possible to use an  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  if the module did not have enough information to process them, or the values could be   if they correspond to an invalid era. You can specify properties with the dot syntax:



The properties are as follows:


 * : the year in the Gregorian calendar. Same as the input year.
 * : the first year of the specified era.
 * : the last year of the specified era.
 * : the year of the specified era, without the era name.
 * : 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 full-width numbers. Note: even though the output may often look like a number, it will always be a string value.
 * : the Wikipedia article for the era, unlinked.
 * : the name of the era. Same as  unless the article title is disambiguated.
 * : the name of the era in kanji.

Methods
Era objects have three methods. Methods can be specified with the colon syntax:



The methods are as follows:
 * - gets the era object for the next era. Returns  if it doesn't exist.
 * - gets the era object for the previous era. Returns  if it doesn't exist.
 * - 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.