<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hant-TW">
	<id>https://encyclo-sanctum.encyclato.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DC</id>
	<title>眾神廳 - 使用者貢獻 [zh-tw]</title>
	<link rel="self" type="application/atom+xml" href="https://encyclo-sanctum.encyclato.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DC"/>
	<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php/%E7%89%B9%E6%AE%8A:%E4%BD%BF%E7%94%A8%E8%80%85%E8%B2%A2%E7%8D%BB/DC"/>
	<updated>2026-11-16T06:13:49Z</updated>
	<subtitle>使用者貢獻</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Documentation/config&amp;diff=1337</id>
		<title>模組:Documentation/config</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Documentation/config&amp;diff=1337"/>
		<updated>2026-10-04T16:05:59Z</updated>

		<summary type="html">&lt;p&gt;DC：​&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;----------------------------------------------------------------------------------------------------&lt;br /&gt;
--&lt;br /&gt;
--                               Configuration for Module:Documentation&lt;br /&gt;
--&lt;br /&gt;
-- Here you can set the values of the parameters and messages used in Module:Documentation to&lt;br /&gt;
-- localise it to your wiki and your language. Unless specified otherwise, values given here&lt;br /&gt;
-- should be string values.&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local cfg = {} -- Do not edit this line.&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Protection template configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;protection-reason-edit&#039;]&lt;br /&gt;
-- The protection reason for edit-protected templates to pass to&lt;br /&gt;
-- [[Module:Protection banner]].&lt;br /&gt;
cfg[&#039;protection-reason-edit&#039;] = &#039;template&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Sandbox notice configuration&lt;br /&gt;
--&lt;br /&gt;
-- On sandbox pages the module can display a template notifying users that the current page is a&lt;br /&gt;
-- sandbox, and the location of test cases pages, etc. The module decides whether the page is a&lt;br /&gt;
-- sandbox or not based on the value of cfg[&#039;sandbox-subpage&#039;]. The following settings configure the&lt;br /&gt;
-- messages that the notices contains.&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-notice-image&#039;]&lt;br /&gt;
-- The image displayed in the sandbox notice.&lt;br /&gt;
cfg[&#039;sandbox-notice-image&#039;] = &#039;[[File:Sandbox.svg|50px|alt=|link=]]&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;sandbox-notice-pagetype-template&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-pagetype-module&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-pagetype-other&#039;]&lt;br /&gt;
-- The page type of the sandbox page. The message that is displayed depends on the current subject&lt;br /&gt;
-- namespace. This message is used in either cfg[&#039;sandbox-notice-blurb&#039;] or&lt;br /&gt;
-- cfg[&#039;sandbox-notice-diff-blurb&#039;].&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;sandbox-notice-pagetype-template&#039;] = &#039;沙盒&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-pagetype-module&#039;] = &#039;沙盒&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-pagetype-other&#039;] = &#039;沙盒&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;sandbox-notice-blurb&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-diff-blurb&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-diff-display&#039;]&lt;br /&gt;
-- Either cfg[&#039;sandbox-notice-blurb&#039;] or cfg[&#039;sandbox-notice-diff-blurb&#039;] is the opening sentence&lt;br /&gt;
-- of the sandbox notice. The latter has a diff link, but the former does not. $1 is the page&lt;br /&gt;
-- type, which is either cfg[&#039;sandbox-notice-pagetype-template&#039;],&lt;br /&gt;
-- cfg[&#039;sandbox-notice-pagetype-module&#039;] or cfg[&#039;sandbox-notice-pagetype-other&#039;] depending what&lt;br /&gt;
-- namespace we are in. $2 is a link to the main template page, and $3 is a diff link between&lt;br /&gt;
-- the sandbox and the main template. The display value of the diff link is set by &lt;br /&gt;
-- cfg[&#039;sandbox-notice-compare-link-display&#039;].&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;sandbox-notice-blurb&#039;] = &#039;這是$2的$1。&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-diff-blurb&#039;] = &#039;這是$2（$3）的$1。&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-compare-link-display&#039;] = &#039;差異&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-blurb&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-link-display&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-run-blurb&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-run-link-display&#039;]&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-blurb&#039;] is a sentence notifying the user that there is a test cases page&lt;br /&gt;
-- corresponding to this sandbox that they can edit. $1 is a link to the test cases page.&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-link-display&#039;] is the display value for that link.&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-run-blurb&#039;] is a sentence notifying the user that there is a test cases page&lt;br /&gt;
-- corresponding to this sandbox that they can edit, along with a link to run it. $1 is a link to the test&lt;br /&gt;
-- cases page, and $2 is a link to the page to run it.&lt;br /&gt;
-- cfg[&#039;sandbox-notice-testcases-run-link-display&#039;] is the display value for the link to run the test&lt;br /&gt;
-- cases.&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;sandbox-notice-testcases-blurb&#039;] = &#039;參見本$1的$2。&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-testcases-link-display&#039;] = &#039;測試樣例&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-testcases-run-blurb&#039;] = &#039;參見本$1的$2（$3）。&#039;&lt;br /&gt;
cfg[&#039;sandbox-notice-testcases-run-link-display&#039;] = &#039;執行-&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-category&#039;] - A category to add to all template sandboxes.&lt;br /&gt;
-- cfg[&#039;module-sandbox-category&#039;] - A category to add to all module sandboxes.&lt;br /&gt;
-- cfg[&#039;module-sandbox-category&#039;] - A category to add to all sandboxe not in templates or modules.&lt;br /&gt;
cfg[&#039;sandbox-category&#039;] = &#039;模板沙盒&#039;&lt;br /&gt;
cfg[&#039;module-sandbox-category&#039;] = &#039;模組沙盒&#039;&lt;br /&gt;
cfg[&#039;other-sandbox-category&#039;] = &#039;模板或模組命名空間之外的沙盒&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Start box configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;documentation-icon-wikitext&#039;]&lt;br /&gt;
-- The wikitext for the icon shown at the top of the template.&lt;br /&gt;
cfg[&#039;documentation-icon-wikitext&#039;] = &#039;[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=]]&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;template-namespace-heading&#039;]&lt;br /&gt;
-- The heading shown in the template namespace.&lt;br /&gt;
cfg[&#039;template-namespace-heading&#039;] = &#039;模板文件&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;module-namespace-heading&#039;]&lt;br /&gt;
-- The heading shown in the module namespace.&lt;br /&gt;
cfg[&#039;module-namespace-heading&#039;] = &#039;模組文件&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;file-namespace-heading&#039;]&lt;br /&gt;
-- The heading shown in the file namespace.&lt;br /&gt;
cfg[&#039;file-namespace-heading&#039;] = &#039;摘要&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;other-namespaces-heading&#039;]&lt;br /&gt;
-- The heading shown in other namespaces.&lt;br /&gt;
cfg[&#039;other-namespaces-heading&#039;] = &#039;文件&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;view-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;view&amp;quot; links.&lt;br /&gt;
cfg[&#039;view-link-display&#039;] = &#039;檢視&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;edit-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;edit&amp;quot; links.&lt;br /&gt;
cfg[&#039;edit-link-display&#039;] = &#039;編輯&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;history-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;history&amp;quot; links.&lt;br /&gt;
cfg[&#039;history-link-display&#039;] = &#039;歷史&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;purge-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;purge&amp;quot; links.&lt;br /&gt;
cfg[&#039;purge-link-display&#039;] = &#039;清除快取&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;create-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;create&amp;quot; links.&lt;br /&gt;
cfg[&#039;create-link-display&#039;] = &#039;建立&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Link box (end box) configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;transcluded-from-blurb&#039;]&lt;br /&gt;
-- Notice displayed when the docs are transcluded from another page. $1 is a wikilink to that page.&lt;br /&gt;
cfg[&#039;transcluded-from-blurb&#039;] = &#039;上述文件嵌入自$1。&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;create-module-doc-blurb&#039;]&lt;br /&gt;
-- Notice displayed in the module namespace when the documentation subpage does not exist.&lt;br /&gt;
-- $1 is a link to create the documentation page with the preload cfg[&#039;module-preload&#039;] and the&lt;br /&gt;
-- display cfg[&#039;create-link-display&#039;].&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;create-module-doc-blurb&#039;] = &#039;您可能想要$1本Scribunto模組的文件。&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Experiment blurb configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;experiment-blurb-template&#039;]&lt;br /&gt;
-- cfg[&#039;experiment-blurb-module&#039;]&lt;br /&gt;
-- The experiment blurb is the text inviting editors to experiment in sandbox and test cases pages.&lt;br /&gt;
-- It is only shown in the template and module namespaces. With the default English settings, it&lt;br /&gt;
-- might look like this:&lt;br /&gt;
--&lt;br /&gt;
-- Editors can experiment in this template&#039;s sandbox (edit | diff) and testcases (edit) pages.&lt;br /&gt;
--&lt;br /&gt;
-- In this example, &amp;quot;sandbox&amp;quot;, &amp;quot;edit&amp;quot;, &amp;quot;diff&amp;quot;, &amp;quot;testcases&amp;quot;, and &amp;quot;edit&amp;quot; would all be links.&lt;br /&gt;
--&lt;br /&gt;
-- There are two versions, cfg[&#039;experiment-blurb-template&#039;] and cfg[&#039;experiment-blurb-module&#039;], depending&lt;br /&gt;
-- on what namespace we are in.&lt;br /&gt;
-- &lt;br /&gt;
-- Parameters:&lt;br /&gt;
--&lt;br /&gt;
-- $1 is a link to the sandbox page. If the sandbox exists, it is in the following format:&lt;br /&gt;
--&lt;br /&gt;
--     cfg[&#039;sandbox-link-display&#039;] (cfg[&#039;sandbox-edit-link-display&#039;] | cfg[&#039;compare-link-display&#039;])&lt;br /&gt;
-- &lt;br /&gt;
-- If the sandbox doesn&#039;t exist, it is in the format:&lt;br /&gt;
--&lt;br /&gt;
--     cfg[&#039;sandbox-link-display&#039;] (cfg[&#039;sandbox-create-link-display&#039;] | cfg[&#039;mirror-link-display&#039;])&lt;br /&gt;
-- &lt;br /&gt;
-- The link for cfg[&#039;sandbox-create-link-display&#039;] link preloads the page with cfg[&#039;template-sandbox-preload&#039;]&lt;br /&gt;
-- or cfg[&#039;module-sandbox-preload&#039;], depending on the current namespace. The link for cfg[&#039;mirror-link-display&#039;]&lt;br /&gt;
-- loads a default edit summary of cfg[&#039;mirror-edit-summary&#039;].&lt;br /&gt;
--&lt;br /&gt;
-- $2 is a link to the test cases page. If the test cases page exists, it is in the following format:&lt;br /&gt;
--&lt;br /&gt;
--     cfg[&#039;testcases-link-display&#039;] (cfg[&#039;testcases-edit-link-display&#039;] | cfg[&#039;testcases-run-link-display&#039;])&lt;br /&gt;
--&lt;br /&gt;
-- If the test cases page doesn&#039;t exist, it is in the format:&lt;br /&gt;
-- &lt;br /&gt;
--     cfg[&#039;testcases-link-display&#039;] (cfg[&#039;testcases-create-link-display&#039;])&lt;br /&gt;
--&lt;br /&gt;
-- If the test cases page doesn&#039;t exist, the link for cfg[&#039;testcases-create-link-display&#039;] preloads the&lt;br /&gt;
-- page with cfg[&#039;template-testcases-preload&#039;] or cfg[&#039;module-testcases-preload&#039;], depending on the current&lt;br /&gt;
-- namespace.&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;experiment-blurb-template&#039;] = &amp;quot;編者可以在本模板的$1和$2頁面進行實驗。&amp;quot;&lt;br /&gt;
cfg[&#039;experiment-blurb-module&#039;] = &amp;quot;編编者可以在本模組的$1和$2頁面進行實驗。&amp;quot;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Sandbox link configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-subpage&#039;]&lt;br /&gt;
-- The name of the template subpage typically used for sandboxes.&lt;br /&gt;
cfg[&#039;sandbox-subpage&#039;] = &#039;sandbox&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;template-sandbox-preload&#039;]&lt;br /&gt;
-- Preload file for template sandbox pages.&lt;br /&gt;
cfg[&#039;template-sandbox-preload&#039;] = &#039;Template:Documentation/preload-sandbox&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;module-sandbox-preload&#039;]&lt;br /&gt;
-- Preload file for Lua module sandbox pages.&lt;br /&gt;
cfg[&#039;module-sandbox-preload&#039;] = &#039;Template:Documentation/preload-module-sandbox&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;sandbox&amp;quot; links.&lt;br /&gt;
cfg[&#039;sandbox-link-display&#039;] = &#039;沙盒&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-edit-link-display&#039;]&lt;br /&gt;
-- The text to display for sandbox &amp;quot;edit&amp;quot; links.&lt;br /&gt;
cfg[&#039;sandbox-edit-link-display&#039;] = &#039;編輯&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;sandbox-create-link-display&#039;]&lt;br /&gt;
-- The text to display for sandbox &amp;quot;create&amp;quot; links.&lt;br /&gt;
cfg[&#039;sandbox-create-link-display&#039;] = &#039;建立&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;compare-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;compare&amp;quot; links.&lt;br /&gt;
cfg[&#039;compare-link-display&#039;] = &#039;差異&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;mirror-edit-summary&#039;]&lt;br /&gt;
-- The default edit summary to use when a user clicks the &amp;quot;mirror&amp;quot; link. $1 is a wikilink to the&lt;br /&gt;
-- template page.&lt;br /&gt;
cfg[&#039;mirror-edit-summary&#039;] = &#039;建立$1的沙盒版本&#039; -- 本訊息無法使用轉換&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;mirror-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;mirror&amp;quot; links.&lt;br /&gt;
cfg[&#039;mirror-link-display&#039;] = &#039;鏡像&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;mirror-link-preload&#039;]&lt;br /&gt;
-- The page to preload when a user clicks the &amp;quot;mirror&amp;quot; link.&lt;br /&gt;
cfg[&#039;mirror-link-preload&#039;] = &#039;Template:Documentation/mirror&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Test cases link configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;testcases-subpage&#039;]&lt;br /&gt;
-- The name of the template subpage typically used for test cases.&lt;br /&gt;
cfg[&#039;testcases-subpage&#039;] = &#039;testcases&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;template-testcases-preload&#039;]&lt;br /&gt;
-- Preload file for template test cases pages.&lt;br /&gt;
cfg[&#039;template-testcases-preload&#039;] = &#039;Template:Documentation/preload-testcases&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;module-testcases-preload&#039;]&lt;br /&gt;
-- Preload file for Lua module test cases pages.&lt;br /&gt;
cfg[&#039;module-testcases-preload&#039;] = &#039;Template:Documentation/preload-module-testcases&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;testcases-link-display&#039;]&lt;br /&gt;
-- The text to display for &amp;quot;testcases&amp;quot; links.&lt;br /&gt;
cfg[&#039;testcases-link-display&#039;] = &#039;測試樣例&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;testcases-edit-link-display&#039;]&lt;br /&gt;
-- The text to display for test cases &amp;quot;edit&amp;quot; links.&lt;br /&gt;
cfg[&#039;testcases-edit-link-display&#039;] = &#039;編輯&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;testcases-run-link-display&#039;]&lt;br /&gt;
-- The text to display for test cases &amp;quot;run&amp;quot; links.&lt;br /&gt;
cfg[&#039;testcases-run-link-display&#039;] = &#039;執行&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;testcases-create-link-display&#039;]&lt;br /&gt;
-- The text to display for test cases &amp;quot;create&amp;quot; links.&lt;br /&gt;
cfg[&#039;testcases-create-link-display&#039;] = &#039;建立&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Add categories blurb configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;add-categories-blurb&#039;]&lt;br /&gt;
-- Text to direct users to add categories to the /doc subpage. Not used if the &amp;quot;content&amp;quot; or&lt;br /&gt;
-- &amp;quot;docname fed&amp;quot; arguments are set, as then it is not clear where to add the categories. $1 is a&lt;br /&gt;
-- link to the /doc subpage with a display value of cfg[&#039;doc-link-display&#039;].&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;add-categories-blurb&#039;] = &#039;請在$1子頁面中添加分類。&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;doc-link-display&#039;]&lt;br /&gt;
-- The text to display when linking to the /doc subpage.&lt;br /&gt;
cfg[&#039;doc-link-display&#039;] = &#039;/doc&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Subpages link configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;subpages-blurb&#039;]&lt;br /&gt;
-- The &amp;quot;Subpages of this template&amp;quot; blurb. $1 is a link to the main template&#039;s subpages with a&lt;br /&gt;
-- display value of cfg[&#039;subpages-link-display&#039;]. In the English version this blurb is simply&lt;br /&gt;
-- the link followed by a period, and the link display provides the actual text.&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;subpages-blurb&#039;] = &#039;$1。&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- cfg[&#039;subpages-link-display&#039;]&lt;br /&gt;
-- The text to display for the &amp;quot;subpages of this page&amp;quot; link. $1 is cfg[&#039;template-pagetype&#039;],&lt;br /&gt;
-- cfg[&#039;module-pagetype&#039;] or cfg[&#039;default-pagetype&#039;], depending on whether the current page is in&lt;br /&gt;
-- the template namespace, the module namespace, or another namespace.&lt;br /&gt;
--]]&lt;br /&gt;
cfg[&#039;subpages-link-display&#039;] = &#039;本$1的子頁面&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;template-pagetype&#039;]&lt;br /&gt;
-- The pagetype to display for template pages.&lt;br /&gt;
cfg[&#039;template-pagetype&#039;] = &#039;模板&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;module-pagetype&#039;]&lt;br /&gt;
-- The pagetype to display for Lua module pages.&lt;br /&gt;
cfg[&#039;module-pagetype&#039;] = &#039;模組&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;default-pagetype&#039;]&lt;br /&gt;
-- The pagetype to display for pages other than templates or Lua modules.&lt;br /&gt;
cfg[&#039;default-pagetype&#039;] = &#039;頁&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Doc link configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;doc-subpage&#039;]&lt;br /&gt;
-- The name of the subpage typically used for documentation pages.&lt;br /&gt;
cfg[&#039;doc-subpage&#039;] = &#039;doc&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;docpage-preload&#039;]&lt;br /&gt;
-- Preload file for template documentation pages in all namespaces.&lt;br /&gt;
cfg[&#039;docpage-preload&#039;] = &#039;Template:Documentation/preload&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;module-preload&#039;]&lt;br /&gt;
-- Preload file for Lua module documentation pages.&lt;br /&gt;
cfg[&#039;module-preload&#039;] = &#039;Template:Documentation/preload-module-doc&#039;&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- HTML and CSS configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;templatestyles&#039;]&lt;br /&gt;
-- The name of the TemplateStyles page where CSS is kept.&lt;br /&gt;
-- Sandbox CSS will be at Module:Documentation/sandbox/styles.css when needed.&lt;br /&gt;
cfg[&#039;templatestyles&#039;] = &#039;Module:Documentation/styles.css&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;container&#039;]&lt;br /&gt;
-- Class which can be used to set flex or grid CSS on the&lt;br /&gt;
-- two child divs documentation and documentation-metadata&lt;br /&gt;
cfg[&#039;container&#039;] = &#039;documentation-container&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;main-div-classes&#039;]&lt;br /&gt;
-- Classes added to the main HTML &amp;quot;div&amp;quot; tag.&lt;br /&gt;
cfg[&#039;main-div-classes&#039;] = &#039;documentation&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;main-div-heading-class&#039;]&lt;br /&gt;
-- Class for the main heading for templates and modules and assoc. talk spaces&lt;br /&gt;
cfg[&#039;main-div-heading-class&#039;] = &#039;documentation-heading&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;start-box-class&#039;]&lt;br /&gt;
-- Class for the start box&lt;br /&gt;
cfg[&#039;start-box-class&#039;] = &#039;documentation-startbox&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;start-box-link-classes&#039;]&lt;br /&gt;
-- Classes used for the [view][edit][history] or [create] links in the start box.&lt;br /&gt;
-- mw-editsection-like is per [[Wikipedia:Village pump (technical)/Archive 117]]&lt;br /&gt;
cfg[&#039;start-box-link-classes&#039;] = &#039;mw-editsection-like plainlinks&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;end-box-class&#039;]&lt;br /&gt;
-- Class for the end box.&lt;br /&gt;
cfg[&#039;end-box-class&#039;] = &#039;documentation-metadata&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;end-box-plainlinks&#039;]&lt;br /&gt;
-- Plainlinks&lt;br /&gt;
cfg[&#039;end-box-plainlinks&#039;] = &#039;plainlinks&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;toolbar-class&#039;]&lt;br /&gt;
-- Class added for toolbar links.&lt;br /&gt;
cfg[&#039;toolbar-class&#039;] = &#039;documentation-toolbar&#039;&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;clear&#039;]&lt;br /&gt;
-- Just used to clear things.&lt;br /&gt;
cfg[&#039;clear&#039;] = &#039;documentation-clear&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- Tracking category configuration&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;display-strange-usage-category&#039;]&lt;br /&gt;
-- Set to true to enable output of cfg[&#039;strange-usage-category&#039;] if the module is used on a /doc subpage&lt;br /&gt;
-- or a /testcases subpage. This should be a boolean value (either true or false).&lt;br /&gt;
cfg[&#039;display-strange-usage-category&#039;] = true&lt;br /&gt;
&lt;br /&gt;
-- cfg[&#039;strange-usage-category&#039;]&lt;br /&gt;
-- Category to output if cfg[&#039;display-strange-usage-category&#039;] is set to true and the module is used on a&lt;br /&gt;
-- /doc subpage or a /testcases subpage.&lt;br /&gt;
cfg[&#039;strange-usage-category&#039;] = &#039;異常使用((documentation))的頁面&#039;&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
-- End configuration&lt;br /&gt;
--&lt;br /&gt;
-- Don&#039;t edit anything below this line.&lt;br /&gt;
----------------------------------------------------------------------------------------------------&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
return cfg&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Date&amp;diff=1336</id>
		<title>模組:Date</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Date&amp;diff=1336"/>
		<updated>2026-10-04T16:01:45Z</updated>

		<summary type="html">&lt;p&gt;DC：​&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;-- Date functions for use by other modules.&lt;br /&gt;
-- I18N and time zones are not supported.&lt;br /&gt;
&lt;br /&gt;
local MINUS = &#039;−&#039;  -- Unicode U+2212 MINUS SIGN&lt;br /&gt;
local floor = math.floor&lt;br /&gt;
&lt;br /&gt;
local Date, DateDiff, diffmt  -- forward declarations&lt;br /&gt;
local uniq = { &#039;unique identifier&#039; }&lt;br /&gt;
&lt;br /&gt;
local function is_date(t)&lt;br /&gt;
	-- The system used to make a date read-only means there is no unique&lt;br /&gt;
	-- metatable that is conveniently accessible to check.&lt;br /&gt;
	return type(t) == &#039;table&#039; and t._id == uniq&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_diff(t)&lt;br /&gt;
	return type(t) == &#039;table&#039; and getmetatable(t) == diffmt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _list_join(list, sep)&lt;br /&gt;
	return table.concat(list, sep)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function collection()&lt;br /&gt;
	-- Return a table to hold items.&lt;br /&gt;
	return {&lt;br /&gt;
		n = 0,&lt;br /&gt;
		add = function (self, item)&lt;br /&gt;
			self.n = self.n + 1&lt;br /&gt;
			self[self.n] = item&lt;br /&gt;
		end,&lt;br /&gt;
		join = _list_join,&lt;br /&gt;
	}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function strip_to_nil(text)&lt;br /&gt;
	-- If text is a string, return its trimmed content, or nil if empty.&lt;br /&gt;
	-- Otherwise return text (convenient when Date fields are provided from&lt;br /&gt;
	-- another module which may pass a string, a number, or another type).&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		text = text:match(&#039;(%S.-)%s*$&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_leap_year(year, calname)&lt;br /&gt;
	-- Return true if year is a leap year.&lt;br /&gt;
	if calname == &#039;Julian&#039; then&lt;br /&gt;
		return year % 4 == 0&lt;br /&gt;
	end&lt;br /&gt;
	return (year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function days_in_month(year, month, calname)&lt;br /&gt;
	-- Return number of days (1..31) in given month (1..12).&lt;br /&gt;
	if month == 2 and is_leap_year(year, calname) then&lt;br /&gt;
		return 29&lt;br /&gt;
	end&lt;br /&gt;
	return ({ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 })[month]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function h_m_s(time)&lt;br /&gt;
	-- Return hour, minute, second extracted from fraction of a day.&lt;br /&gt;
	time = floor(time * 24 * 3600 + 0.5)  -- number of seconds&lt;br /&gt;
	local second = time % 60&lt;br /&gt;
	time = floor(time / 60)&lt;br /&gt;
	return floor(time / 60), time % 60, second&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hms(date)&lt;br /&gt;
	-- Return fraction of a day from date&#039;s time, where (0 &amp;lt;= fraction &amp;lt; 1)&lt;br /&gt;
	-- if the values are valid, but could be anything if outside range.&lt;br /&gt;
	return (date.hour + (date.minute + date.second / 60) / 60) / 24&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function julian_date(date)&lt;br /&gt;
	-- Return jd, jdz from a Julian or Gregorian calendar date where&lt;br /&gt;
	--   jd = Julian date and its fractional part is zero at noon&lt;br /&gt;
	--   jdz = same, but assume time is 00:00:00 if no time given&lt;br /&gt;
	-- http://www.tondering.dk/claus/cal/julperiod.php#formula&lt;br /&gt;
	-- Testing shows this works for all dates from year -9999 to 9999!&lt;br /&gt;
	-- JDN 0 is the 24-hour period starting at noon UTC on Monday&lt;br /&gt;
	--    1 January 4713 BC  = (-4712, 1, 1)   Julian calendar&lt;br /&gt;
	--   24 November 4714 BC = (-4713, 11, 24) Gregorian calendar&lt;br /&gt;
	local offset&lt;br /&gt;
	local a = floor((14 - date.month)/12)&lt;br /&gt;
	local y = date.year + 4800 - a&lt;br /&gt;
	if date.calendar == &#039;Julian&#039; then&lt;br /&gt;
		offset = floor(y/4) - 32083&lt;br /&gt;
	else&lt;br /&gt;
		offset = floor(y/4) - floor(y/100) + floor(y/400) - 32045&lt;br /&gt;
	end&lt;br /&gt;
	local m = date.month + 12*a - 3&lt;br /&gt;
	local jd = date.day + floor((153*m + 2)/5) + 365*y + offset&lt;br /&gt;
	if date.hastime then&lt;br /&gt;
		jd = jd + hms(date) - 0.5&lt;br /&gt;
		return jd, jd&lt;br /&gt;
	end&lt;br /&gt;
	return jd, jd - 0.5&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function set_date_from_jd(date)&lt;br /&gt;
	-- Set the fields of table date from its Julian date field.&lt;br /&gt;
	-- Return true if date is valid.&lt;br /&gt;
	-- http://www.tondering.dk/claus/cal/julperiod.php#formula&lt;br /&gt;
	-- This handles the proleptic Julian and Gregorian calendars.&lt;br /&gt;
	-- Negative Julian dates are not defined but they work.&lt;br /&gt;
	local calname = date.calendar&lt;br /&gt;
	local low, high  -- min/max limits for date ranges −9999-01-01 to 9999-12-31&lt;br /&gt;
	if calname == &#039;Gregorian&#039; then&lt;br /&gt;
		low, high = -1930999.5, 5373484.49999&lt;br /&gt;
	elseif calname == &#039;Julian&#039; then&lt;br /&gt;
		low, high = -1931076.5, 5373557.49999&lt;br /&gt;
	else&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local jd = date.jd&lt;br /&gt;
	if not (type(jd) == &#039;number&#039; and low &amp;lt;= jd and jd &amp;lt;= high) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local jdn = floor(jd)&lt;br /&gt;
	if date.hastime then&lt;br /&gt;
		local time = jd - jdn  -- 0 &amp;lt;= time &amp;lt; 1&lt;br /&gt;
		if time &amp;gt;= 0.5 then    -- if at or after midnight of next day&lt;br /&gt;
			jdn = jdn + 1&lt;br /&gt;
			time = time - 0.5&lt;br /&gt;
		else&lt;br /&gt;
			time = time + 0.5&lt;br /&gt;
		end&lt;br /&gt;
		date.hour, date.minute, date.second = h_m_s(time)&lt;br /&gt;
	else&lt;br /&gt;
		date.second = 0&lt;br /&gt;
		date.minute = 0&lt;br /&gt;
		date.hour = 0&lt;br /&gt;
	end&lt;br /&gt;
	local b, c&lt;br /&gt;
	if calname == &#039;Julian&#039; then&lt;br /&gt;
		b = 0&lt;br /&gt;
		c = jdn + 32082&lt;br /&gt;
	else  -- Gregorian&lt;br /&gt;
		local a = jdn + 32044&lt;br /&gt;
		b = floor((4*a + 3)/146097)&lt;br /&gt;
		c = a - floor(146097*b/4)&lt;br /&gt;
	end&lt;br /&gt;
	local d = floor((4*c + 3)/1461)&lt;br /&gt;
	local e = c - floor(1461*d/4)&lt;br /&gt;
	local m = floor((5*e + 2)/153)&lt;br /&gt;
	date.day = e - floor((153*m + 2)/5) + 1&lt;br /&gt;
	date.month = m + 3 - 12*floor(m/10)&lt;br /&gt;
	date.year = 100*b + d - 4800 + floor(m/10)&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function fix_numbers(numbers, y, m, d, H, M, S, partial, hastime, calendar)&lt;br /&gt;
	-- Put the result of normalizing the given values in table numbers.&lt;br /&gt;
	-- The result will have valid m, d values if y is valid; caller checks y.&lt;br /&gt;
	-- The logic of PHP mktime is followed where m or d can be zero to mean&lt;br /&gt;
	-- the previous unit, and -1 is the one before that, etc.&lt;br /&gt;
	-- Positive values carry forward.&lt;br /&gt;
	local date&lt;br /&gt;
	if not (1 &amp;lt;= m and m &amp;lt;= 12) then&lt;br /&gt;
		date = Date(y, 1, 1)&lt;br /&gt;
		if not date then return end&lt;br /&gt;
		date = date + ((m - 1) .. &#039;m&#039;)&lt;br /&gt;
		y, m = date.year, date.month&lt;br /&gt;
	end&lt;br /&gt;
	local days_hms&lt;br /&gt;
	if not partial then&lt;br /&gt;
		if hastime and H and M and S then&lt;br /&gt;
			if not (0 &amp;lt;= H and H &amp;lt;= 23 and&lt;br /&gt;
					0 &amp;lt;= M and M &amp;lt;= 59 and&lt;br /&gt;
					0 &amp;lt;= S and S &amp;lt;= 59) then&lt;br /&gt;
				days_hms = hms({ hour = H, minute = M, second = S })&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if days_hms or not (1 &amp;lt;= d and d &amp;lt;= days_in_month(y, m, calendar)) then&lt;br /&gt;
			date = date or Date(y, m, 1)&lt;br /&gt;
			if not date then return end&lt;br /&gt;
			date = date + (d - 1 + (days_hms or 0))&lt;br /&gt;
			y, m, d = date.year, date.month, date.day&lt;br /&gt;
			if days_hms then&lt;br /&gt;
				H, M, S = date.hour, date.minute, date.second&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	numbers.year = y&lt;br /&gt;
	numbers.month = m&lt;br /&gt;
	numbers.day = d&lt;br /&gt;
	if days_hms then&lt;br /&gt;
		-- Don&#039;t set H unless it was valid because a valid H will set hastime.&lt;br /&gt;
		numbers.hour = H&lt;br /&gt;
		numbers.minute = M&lt;br /&gt;
		numbers.second = S&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function set_date_from_numbers(date, numbers, options)&lt;br /&gt;
	-- Set the fields of table date from numeric values.&lt;br /&gt;
	-- Return true if date is valid.&lt;br /&gt;
	if type(numbers) ~= &#039;table&#039; then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local y = numbers.year   or date.year&lt;br /&gt;
	local m = numbers.month  or date.month&lt;br /&gt;
	local d = numbers.day    or date.day&lt;br /&gt;
	local H = numbers.hour&lt;br /&gt;
	local M = numbers.minute or date.minute or 0&lt;br /&gt;
	local S = numbers.second or date.second or 0&lt;br /&gt;
	local need_fix&lt;br /&gt;
	if y and m and d then&lt;br /&gt;
		date.partial = nil&lt;br /&gt;
		if not (-9999 &amp;lt;= y and y &amp;lt;= 9999 and&lt;br /&gt;
			1 &amp;lt;= m and m &amp;lt;= 12 and&lt;br /&gt;
			1 &amp;lt;= d and d &amp;lt;= days_in_month(y, m, date.calendar)) then&lt;br /&gt;
				if not date.want_fix then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				need_fix = true&lt;br /&gt;
		end&lt;br /&gt;
	elseif y and date.partial then&lt;br /&gt;
		if d or not (-9999 &amp;lt;= y and y &amp;lt;= 9999) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
		if m and not (1 &amp;lt;= m and m &amp;lt;= 12) then&lt;br /&gt;
			if not date.want_fix then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			need_fix = true&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		H = nil  -- ignore any time&lt;br /&gt;
		M = nil&lt;br /&gt;
		S = nil&lt;br /&gt;
	else&lt;br /&gt;
		if H then&lt;br /&gt;
			-- It is not possible to set M or S without also setting H.&lt;br /&gt;
			date.hastime = true&lt;br /&gt;
		else&lt;br /&gt;
			H = 0&lt;br /&gt;
		end&lt;br /&gt;
		if not (0 &amp;lt;= H and H &amp;lt;= 23 and&lt;br /&gt;
				0 &amp;lt;= M and M &amp;lt;= 59 and&lt;br /&gt;
				0 &amp;lt;= S and S &amp;lt;= 59) then&lt;br /&gt;
			if date.want_fix then&lt;br /&gt;
				need_fix = true&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	date.want_fix = nil&lt;br /&gt;
	if need_fix then&lt;br /&gt;
		fix_numbers(numbers, y, m, d, H, M, S, date.partial, date.hastime, date.calendar)&lt;br /&gt;
		return set_date_from_numbers(date, numbers, options)&lt;br /&gt;
	end&lt;br /&gt;
	date.year = y    -- -9999 to 9999 (&#039;n BC&#039; → year = 1 - n)&lt;br /&gt;
	date.month = m   -- 1 to 12 (may be nil if partial)&lt;br /&gt;
	date.day = d     -- 1 to 31 (* = nil if partial)&lt;br /&gt;
	date.hour = H    -- 0 to 59 (*)&lt;br /&gt;
	date.minute = M  -- 0 to 59 (*)&lt;br /&gt;
	date.second = S  -- 0 to 59 (*)&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		for _, k in ipairs({ &#039;am&#039;, &#039;era&#039;, &#039;format&#039; }) do&lt;br /&gt;
			if options[k] then&lt;br /&gt;
				date.options[k] = options[k]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function make_option_table(options1, options2)&lt;br /&gt;
	-- If options1 is a string, return a table with its settings, or&lt;br /&gt;
	-- if it is a table, use its settings.&lt;br /&gt;
	-- Missing options are set from table options2 or defaults.&lt;br /&gt;
	-- If a default is used, a flag is set so caller knows the value was not intentionally set.&lt;br /&gt;
	-- Valid option settings are:&lt;br /&gt;
	-- am: &#039;am&#039;, &#039;a.m.&#039;, &#039;AM&#039;, &#039;A.M.&#039;&lt;br /&gt;
	--     &#039;pm&#039;, &#039;p.m.&#039;, &#039;PM&#039;, &#039;P.M.&#039; (each has same meaning as corresponding item above)&lt;br /&gt;
	-- era: &#039;BCMINUS&#039;, &#039;BCNEGATIVE&#039;, &#039;BC&#039;, &#039;B.C.&#039;, &#039;BCE&#039;, &#039;B.C.E.&#039;, &#039;AD&#039;, &#039;A.D.&#039;, &#039;CE&#039;, &#039;C.E.&#039;&lt;br /&gt;
	-- Option am = &#039;am&#039; does not mean the hour is AM; it means &#039;am&#039; or &#039;pm&#039; is used, depending on the hour,&lt;br /&gt;
	--    and am = &#039;pm&#039; has the same meaning.&lt;br /&gt;
	-- Similarly, era = &#039;BC&#039; means &#039;BC&#039; is used if year &amp;lt;= 0.&lt;br /&gt;
	-- BCMINUS displays a MINUS if year &amp;lt; 0 and the display format does not include %{era}.&lt;br /&gt;
	-- BCNEGATIVE is similar but displays a hyphen.&lt;br /&gt;
	local result = { bydefault = {} }&lt;br /&gt;
	if type(options1) == &#039;table&#039; then&lt;br /&gt;
		result.am = options1.am&lt;br /&gt;
		result.era = options1.era&lt;br /&gt;
	elseif type(options1) == &#039;string&#039; then&lt;br /&gt;
		-- Example: &#039;am:AM era:BC&#039; or &#039;am=AM era=BC&#039;.&lt;br /&gt;
		for item in options1:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
			local lhs, rhs = item:match(&#039;^(%w+)[:=](.+)$&#039;)&lt;br /&gt;
			if lhs then&lt;br /&gt;
				result[lhs] = rhs&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	options2 = type(options2) == &#039;table&#039; and options2 or {}&lt;br /&gt;
	local defaults = { am = &#039;am&#039;, era = &#039;BC&#039; }&lt;br /&gt;
	for k, v in pairs(defaults) do&lt;br /&gt;
		if not result[k] then&lt;br /&gt;
			if options2[k] then&lt;br /&gt;
				result[k] = options2[k]&lt;br /&gt;
			else&lt;br /&gt;
				result[k] = v&lt;br /&gt;
				result.bydefault[k] = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local ampm_options = {&lt;br /&gt;
	-- lhs = input text accepted as an am/pm option&lt;br /&gt;
	-- rhs = code used internally&lt;br /&gt;
	[&#039;am&#039;]   = &#039;am&#039;,&lt;br /&gt;
	[&#039;AM&#039;]   = &#039;AM&#039;,&lt;br /&gt;
	[&#039;a.m.&#039;] = &#039;a.m.&#039;,&lt;br /&gt;
	[&#039;A.M.&#039;] = &#039;A.M.&#039;,&lt;br /&gt;
	[&#039;pm&#039;]   = &#039;am&#039;,  -- same as am&lt;br /&gt;
	[&#039;PM&#039;]   = &#039;AM&#039;,&lt;br /&gt;
	[&#039;p.m.&#039;] = &#039;a.m.&#039;,&lt;br /&gt;
	[&#039;P.M.&#039;] = &#039;A.M.&#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local era_text = {&lt;br /&gt;
	-- Text for displaying an era with a positive year (after adjusting&lt;br /&gt;
	-- by replacing year with 1 - year if date.year &amp;lt;= 0).&lt;br /&gt;
	-- options.era = { year&amp;lt;=0 , year&amp;gt;0 }&lt;br /&gt;
	[&#039;BCMINUS&#039;]    = { &#039;BC&#039;    , &#039;&#039;    , isbc = true, sign = MINUS },&lt;br /&gt;
	[&#039;BCNEGATIVE&#039;] = { &#039;BC&#039;    , &#039;&#039;    , isbc = true, sign = &#039;-&#039;   },&lt;br /&gt;
	[&#039;BC&#039;]         = { &#039;BC&#039;    , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;B.C.&#039;]       = { &#039;B.C.&#039;  , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;BCE&#039;]        = { &#039;BCE&#039;   , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;B.C.E.&#039;]     = { &#039;B.C.E.&#039;, &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;AD&#039;]         = { &#039;BC&#039;    , &#039;AD&#039;   },&lt;br /&gt;
	[&#039;A.D.&#039;]       = { &#039;B.C.&#039;  , &#039;A.D.&#039; },&lt;br /&gt;
	[&#039;CE&#039;]         = { &#039;BCE&#039;   , &#039;CE&#039;   },&lt;br /&gt;
	[&#039;C.E.&#039;]       = { &#039;B.C.E.&#039;, &#039;C.E.&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function get_era_for_year(era, year)&lt;br /&gt;
	return (era_text[era] or era_text[&#039;BC&#039;])[year &amp;gt; 0 and 2 or 1] or &#039;&#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function strftime(date, format, options)&lt;br /&gt;
	-- Return date formatted as a string using codes similar to those&lt;br /&gt;
	-- in the C strftime library function.&lt;br /&gt;
	local sformat = string.format&lt;br /&gt;
	local shortcuts = {&lt;br /&gt;
		[&#039;%c&#039;] = &#039;%-I:%M %p %-d %B %-Y %{era}&#039;,  -- date and time: 2:30 pm 1 April 2016&lt;br /&gt;
		[&#039;%x&#039;] = &#039;%-d %B %-Y %{era}&#039;,            -- date:          1 April 2016&lt;br /&gt;
		[&#039;%X&#039;] = &#039;%-I:%M %p&#039;,                    -- time:          2:30 pm&lt;br /&gt;
	}&lt;br /&gt;
	if shortcuts[format] then&lt;br /&gt;
		format = shortcuts[format]&lt;br /&gt;
	end&lt;br /&gt;
	local codes = {&lt;br /&gt;
		a = { field = &#039;dayabbr&#039; },&lt;br /&gt;
		A = { field = &#039;dayname&#039; },&lt;br /&gt;
		b = { field = &#039;monthabbr&#039; },&lt;br /&gt;
		B = { field = &#039;monthname&#039; },&lt;br /&gt;
		u = { fmt = &#039;%d&#039;  , field = &#039;dowiso&#039; },&lt;br /&gt;
		w = { fmt = &#039;%d&#039;  , field = &#039;dow&#039; },&lt;br /&gt;
		d = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;day&#039; },&lt;br /&gt;
		m = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;month&#039; },&lt;br /&gt;
		Y = { fmt = &#039;%04d&#039;, fmt2 = &#039;%d&#039;, field = &#039;year&#039; },&lt;br /&gt;
		H = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;hour&#039; },&lt;br /&gt;
		M = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;minute&#039; },&lt;br /&gt;
		S = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;second&#039; },&lt;br /&gt;
		j = { fmt = &#039;%03d&#039;, fmt2 = &#039;%d&#039;, field = &#039;dayofyear&#039; },&lt;br /&gt;
		I = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;hour&#039;, special = &#039;hour12&#039; },&lt;br /&gt;
		p = { field = &#039;hour&#039;, special = &#039;am&#039; },&lt;br /&gt;
	}&lt;br /&gt;
	options = make_option_table(options, date.options)&lt;br /&gt;
	local amopt = options.am&lt;br /&gt;
	local eraopt = options.era&lt;br /&gt;
	local function replace_code(spaces, modifier, id)&lt;br /&gt;
		local code = codes[id]&lt;br /&gt;
		if code then&lt;br /&gt;
			local fmt = code.fmt&lt;br /&gt;
			if modifier == &#039;-&#039; and code.fmt2 then&lt;br /&gt;
				fmt = code.fmt2&lt;br /&gt;
			end&lt;br /&gt;
			local value = date[code.field]&lt;br /&gt;
			if not value then&lt;br /&gt;
				return nil  -- an undefined field in a partial date&lt;br /&gt;
			end&lt;br /&gt;
			local special = code.special&lt;br /&gt;
			if special then&lt;br /&gt;
				if special == &#039;hour12&#039; then&lt;br /&gt;
					value = value % 12&lt;br /&gt;
					value = value == 0 and 12 or value&lt;br /&gt;
				elseif special == &#039;am&#039; then&lt;br /&gt;
					local ap = ({&lt;br /&gt;
						[&#039;a.m.&#039;] = { &#039;a.m.&#039;, &#039;p.m.&#039; },&lt;br /&gt;
						[&#039;AM&#039;] = { &#039;AM&#039;, &#039;PM&#039; },&lt;br /&gt;
						[&#039;A.M.&#039;] = { &#039;A.M.&#039;, &#039;P.M.&#039; },&lt;br /&gt;
					})[ampm_options[amopt]] or { &#039;am&#039;, &#039;pm&#039; }&lt;br /&gt;
					return (spaces == &#039;&#039; and &#039;&#039; or &#039;&amp;amp;nbsp;&#039;) .. (value &amp;lt; 12 and ap[1] or ap[2])&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			if code.field == &#039;year&#039; then&lt;br /&gt;
				local sign = (era_text[eraopt] or {}).sign&lt;br /&gt;
				if not sign or format:find(&#039;%{era}&#039;, 1, true) then&lt;br /&gt;
					sign = &#039;&#039;&lt;br /&gt;
					if value &amp;lt;= 0 then&lt;br /&gt;
						value = 1 - value&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					if value &amp;gt;= 0 then&lt;br /&gt;
						sign = &#039;&#039;&lt;br /&gt;
					else&lt;br /&gt;
						value = -value&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				return spaces .. sign .. sformat(fmt, value)&lt;br /&gt;
			end&lt;br /&gt;
			return spaces .. (fmt and sformat(fmt, value) or value)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function replace_property(spaces, id)&lt;br /&gt;
		if id == &#039;era&#039; then&lt;br /&gt;
			-- Special case so can use local era option.&lt;br /&gt;
			local result = get_era_for_year(eraopt, date.year)&lt;br /&gt;
			if result == &#039;&#039; then&lt;br /&gt;
				return &#039;&#039;&lt;br /&gt;
			end&lt;br /&gt;
			return (spaces == &#039;&#039; and &#039;&#039; or &#039;&amp;amp;nbsp;&#039;) .. result&lt;br /&gt;
		end&lt;br /&gt;
		local result = date[id]&lt;br /&gt;
		if type(result) == &#039;string&#039; then&lt;br /&gt;
			return spaces .. result&lt;br /&gt;
		end&lt;br /&gt;
		if type(result) == &#039;number&#039; then&lt;br /&gt;
			return  spaces .. tostring(result)&lt;br /&gt;
		end&lt;br /&gt;
		if type(result) == &#039;boolean&#039; then&lt;br /&gt;
			return  spaces .. (result and &#039;1&#039; or &#039;0&#039;)&lt;br /&gt;
		end&lt;br /&gt;
		-- This occurs if id is an undefined field in a partial date, or is the name of a function.&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local PERCENT = &#039;\127PERCENT\127&#039;&lt;br /&gt;
	return (format&lt;br /&gt;
		:gsub(&#039;%%%%&#039;, PERCENT)&lt;br /&gt;
		:gsub(&#039;(%s*)%%{(%w+)}&#039;, replace_property)&lt;br /&gt;
		:gsub(&#039;(%s*)%%(%-?)(%a)&#039;, replace_code)&lt;br /&gt;
		:gsub(PERCENT, &#039;%%&#039;)&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _date_text(date, fmt, options)&lt;br /&gt;
	-- Return a formatted string representing the given date.&lt;br /&gt;
	if not is_date(date) then&lt;br /&gt;
		error(&#039;date:text: need a date (use &amp;quot;date:text()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if type(fmt) == &#039;string&#039; and fmt:match(&#039;%S&#039;) then&lt;br /&gt;
		if fmt:find(&#039;%&#039;, 1, true) then&lt;br /&gt;
			return strftime(date, fmt, options)&lt;br /&gt;
		end&lt;br /&gt;
	elseif date.partial then&lt;br /&gt;
		fmt = date.month and &#039;my&#039; or &#039;y&#039;&lt;br /&gt;
	else&lt;br /&gt;
		fmt = &#039;dmy&#039;&lt;br /&gt;
		if date.hastime then&lt;br /&gt;
			fmt = (date.second &amp;gt; 0 and &#039;hms &#039; or &#039;hm &#039;) .. fmt&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function bad_format()&lt;br /&gt;
		-- For consistency with other format processing, return given format&lt;br /&gt;
		-- (or cleaned format if original was not a string) if invalid.&lt;br /&gt;
		return mw.text.nowiki(fmt)&lt;br /&gt;
	end&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		-- Ignore days in standard formats like &#039;ymd&#039;.&lt;br /&gt;
		if fmt == &#039;ym&#039; or fmt == &#039;ymd&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%Y-%m %{era}&#039; or &#039;%Y %{era}&#039;&lt;br /&gt;
		elseif fmt == &#039;my&#039; or fmt == &#039;dmy&#039; or fmt == &#039;mdy&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%B %-Y %{era}&#039; or &#039;%-Y %{era}&#039;&lt;br /&gt;
		elseif fmt == &#039;y&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%-Y %{era}&#039; or &#039;%-Y %{era}&#039;&lt;br /&gt;
		else&lt;br /&gt;
			return bad_format()&lt;br /&gt;
		end&lt;br /&gt;
		return strftime(date, fmt, options)&lt;br /&gt;
	end&lt;br /&gt;
	local function hm_fmt()&lt;br /&gt;
		local plain = make_option_table(options, date.options).bydefault.am&lt;br /&gt;
		return plain and &#039;%H:%M&#039; or &#039;%-I:%M %p&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local need_time = date.hastime&lt;br /&gt;
	local t = collection()&lt;br /&gt;
	for item in fmt:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
		local f&lt;br /&gt;
		if item == &#039;hm&#039; then&lt;br /&gt;
			f = hm_fmt()&lt;br /&gt;
			need_time = false&lt;br /&gt;
		elseif item == &#039;hms&#039; then&lt;br /&gt;
			f = &#039;%H:%M:%S&#039;&lt;br /&gt;
			need_time = false&lt;br /&gt;
		elseif item == &#039;ymd&#039; then&lt;br /&gt;
			f = &#039;%Y-%m-%d %{era}&#039;&lt;br /&gt;
		elseif item == &#039;mdy&#039; then&lt;br /&gt;
			f = &#039;%B %-d, %-Y %{era}&#039;&lt;br /&gt;
		elseif item == &#039;dmy&#039; then&lt;br /&gt;
			f = &#039;%-d %B %-Y %{era}&#039;&lt;br /&gt;
		else&lt;br /&gt;
			return bad_format()&lt;br /&gt;
		end&lt;br /&gt;
		t:add(f)&lt;br /&gt;
	end&lt;br /&gt;
	fmt = t:join(&#039; &#039;)&lt;br /&gt;
	if need_time then&lt;br /&gt;
		fmt = hm_fmt() .. &#039; &#039; .. fmt&lt;br /&gt;
	end&lt;br /&gt;
	return strftime(date, fmt, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local day_info = {&lt;br /&gt;
	-- 0=Sun to 6=Sat&lt;br /&gt;
	[0] = { &#039;Sun&#039;, &#039;Sunday&#039; },&lt;br /&gt;
	{ &#039;Mon&#039;, &#039;Monday&#039; },&lt;br /&gt;
	{ &#039;Tue&#039;, &#039;Tuesday&#039; },&lt;br /&gt;
	{ &#039;Wed&#039;, &#039;Wednesday&#039; },&lt;br /&gt;
	{ &#039;Thu&#039;, &#039;Thursday&#039; },&lt;br /&gt;
	{ &#039;Fri&#039;, &#039;Friday&#039; },&lt;br /&gt;
	{ &#039;Sat&#039;, &#039;Saturday&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local month_info = {&lt;br /&gt;
	-- 1=Jan to 12=Dec&lt;br /&gt;
	{ &#039;Jan&#039;, &#039;January&#039; },&lt;br /&gt;
	{ &#039;Feb&#039;, &#039;February&#039; },&lt;br /&gt;
	{ &#039;Mar&#039;, &#039;March&#039; },&lt;br /&gt;
	{ &#039;Apr&#039;, &#039;April&#039; },&lt;br /&gt;
	{ &#039;May&#039;, &#039;May&#039; },&lt;br /&gt;
	{ &#039;Jun&#039;, &#039;June&#039; },&lt;br /&gt;
	{ &#039;Jul&#039;, &#039;July&#039; },&lt;br /&gt;
	{ &#039;Aug&#039;, &#039;August&#039; },&lt;br /&gt;
	{ &#039;Sep&#039;, &#039;September&#039; },&lt;br /&gt;
	{ &#039;Oct&#039;, &#039;October&#039; },&lt;br /&gt;
	{ &#039;Nov&#039;, &#039;November&#039; },&lt;br /&gt;
	{ &#039;Dec&#039;, &#039;December&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function name_to_number(text, translate)&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		return translate[text:lower()]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function day_number(text)&lt;br /&gt;
	return name_to_number(text, {&lt;br /&gt;
		sun = 0, sunday = 0,&lt;br /&gt;
		mon = 1, monday = 1,&lt;br /&gt;
		tue = 2, tuesday = 2,&lt;br /&gt;
		wed = 3, wednesday = 3,&lt;br /&gt;
		thu = 4, thursday = 4,&lt;br /&gt;
		fri = 5, friday = 5,&lt;br /&gt;
		sat = 6, saturday = 6,&lt;br /&gt;
	})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function month_number(text)&lt;br /&gt;
	return name_to_number(text, {&lt;br /&gt;
		jan = 1, january = 1,&lt;br /&gt;
		feb = 2, february = 2,&lt;br /&gt;
		mar = 3, march = 3,&lt;br /&gt;
		apr = 4, april = 4,&lt;br /&gt;
		may = 5,&lt;br /&gt;
		jun = 6, june = 6,&lt;br /&gt;
		jul = 7, july = 7,&lt;br /&gt;
		aug = 8, august = 8,&lt;br /&gt;
		sep = 9, september = 9, sept = 9,&lt;br /&gt;
		oct = 10, october = 10,&lt;br /&gt;
		nov = 11, november = 11,&lt;br /&gt;
		dec = 12, december = 12,&lt;br /&gt;
	})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _list_text(list, fmt)&lt;br /&gt;
	-- Return a list of formatted strings from a list of dates.&lt;br /&gt;
	if not type(list) == &#039;table&#039; then&lt;br /&gt;
		error(&#039;date:list:text: need &amp;quot;list:text()&amp;quot; with a colon&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	local result = { join = _list_join }&lt;br /&gt;
	for i, date in ipairs(list) do&lt;br /&gt;
		result[i] = date:text(fmt)&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _date_list(date, spec)&lt;br /&gt;
	-- Return a possibly empty numbered table of dates meeting the specification.&lt;br /&gt;
	-- Dates in the list are in ascending order (oldest date first).&lt;br /&gt;
	-- The spec should be a string of form &amp;quot;&amp;lt;count&amp;gt; &amp;lt;day&amp;gt; &amp;lt;op&amp;gt;&amp;quot;&lt;br /&gt;
	-- where each item is optional and&lt;br /&gt;
	--   count = number of items wanted in list&lt;br /&gt;
	--   day = abbreviation or name such as Mon or Monday&lt;br /&gt;
	--   op = &amp;gt;, &amp;gt;=, &amp;lt;, &amp;lt;= (default is &amp;gt; meaning after date)&lt;br /&gt;
	-- If no count is given, the list is for the specified days in date&#039;s month.&lt;br /&gt;
	-- The default day is date&#039;s day.&lt;br /&gt;
	-- The spec can also be a positive or negative number:&lt;br /&gt;
	--   -5 is equivalent to &#039;5 &amp;lt;&#039;&lt;br /&gt;
	--   5  is equivalent to &#039;5&#039; which is &#039;5 &amp;gt;&#039;&lt;br /&gt;
	if not is_date(date) then&lt;br /&gt;
		error(&#039;date:list: need a date (use &amp;quot;date:list()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	local list = { text = _list_text }&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		return list&lt;br /&gt;
	end&lt;br /&gt;
	local count, offset, operation&lt;br /&gt;
	local ops = {&lt;br /&gt;
		[&#039;&amp;gt;=&#039;] = { before = false, include = true  },&lt;br /&gt;
		[&#039;&amp;gt;&#039;]  = { before = false, include = false },&lt;br /&gt;
		[&#039;&amp;lt;=&#039;] = { before = true , include = true  },&lt;br /&gt;
		[&#039;&amp;lt;&#039;]  = { before = true , include = false },&lt;br /&gt;
	}&lt;br /&gt;
	if spec then&lt;br /&gt;
		if type(spec) == &#039;number&#039; then&lt;br /&gt;
			count = floor(spec + 0.5)&lt;br /&gt;
			if count &amp;lt; 0 then&lt;br /&gt;
				count = -count&lt;br /&gt;
				operation = ops[&#039;&amp;lt;&#039;]&lt;br /&gt;
			end&lt;br /&gt;
		elseif type(spec) == &#039;string&#039; then&lt;br /&gt;
			local num, day, op = spec:match(&#039;^%s*(%d*)%s*(%a*)%s*([&amp;lt;&amp;gt;=]*)%s*$&#039;)&lt;br /&gt;
			if not num then&lt;br /&gt;
				return list&lt;br /&gt;
			end&lt;br /&gt;
			if num ~= &#039;&#039; then&lt;br /&gt;
				count = tonumber(num)&lt;br /&gt;
			end&lt;br /&gt;
			if day ~= &#039;&#039; then&lt;br /&gt;
				local dow = day_number(day:gsub(&#039;[sS]$&#039;, &#039;&#039;))  -- accept plural days&lt;br /&gt;
				if not dow then&lt;br /&gt;
					return list&lt;br /&gt;
				end&lt;br /&gt;
				offset = dow - date.dow&lt;br /&gt;
			end&lt;br /&gt;
			operation = ops[op]&lt;br /&gt;
		else&lt;br /&gt;
			return list&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	offset = offset or 0&lt;br /&gt;
	operation = operation or ops[&#039;&amp;gt;&#039;]&lt;br /&gt;
	local datefrom, dayfirst, daylast&lt;br /&gt;
	if operation.before then&lt;br /&gt;
		if offset &amp;gt; 0 or (offset == 0 and not operation.include) then&lt;br /&gt;
			offset = offset - 7&lt;br /&gt;
		end&lt;br /&gt;
		if count then&lt;br /&gt;
			if count &amp;gt; 1 then&lt;br /&gt;
				offset = offset - 7*(count - 1)&lt;br /&gt;
			end&lt;br /&gt;
			datefrom = date + offset&lt;br /&gt;
		else&lt;br /&gt;
			daylast = date.day + offset&lt;br /&gt;
			dayfirst = daylast % 7&lt;br /&gt;
			if dayfirst == 0 then&lt;br /&gt;
				dayfirst = 7&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if offset &amp;lt; 0 or (offset == 0 and not operation.include) then&lt;br /&gt;
			offset = offset + 7&lt;br /&gt;
		end&lt;br /&gt;
		if count then&lt;br /&gt;
			datefrom = date + offset&lt;br /&gt;
		else&lt;br /&gt;
			dayfirst = date.day + offset&lt;br /&gt;
			daylast = date.monthdays&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not count then&lt;br /&gt;
		if daylast &amp;lt; dayfirst then&lt;br /&gt;
			return list&lt;br /&gt;
		end&lt;br /&gt;
		count = floor((daylast - dayfirst)/7) + 1&lt;br /&gt;
		datefrom = Date(date, {day = dayfirst})&lt;br /&gt;
	end&lt;br /&gt;
	for i = 1, count do&lt;br /&gt;
		if not datefrom then break end  -- exceeds date limits&lt;br /&gt;
		list[i] = datefrom&lt;br /&gt;
		datefrom = datefrom + 7&lt;br /&gt;
	end&lt;br /&gt;
	return list&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- A table to get the current date/time (UTC), but only if needed.&lt;br /&gt;
local current = setmetatable({}, {&lt;br /&gt;
	__index = function (self, key)&lt;br /&gt;
		local d = os.date(&#039;!*t&#039;)&lt;br /&gt;
		self.year = d.year&lt;br /&gt;
		self.month = d.month&lt;br /&gt;
		self.day = d.day&lt;br /&gt;
		self.hour = d.hour&lt;br /&gt;
		self.minute = d.min&lt;br /&gt;
		self.second = d.sec&lt;br /&gt;
		return rawget(self, key)&lt;br /&gt;
	end })&lt;br /&gt;
&lt;br /&gt;
local function extract_date(newdate, text)&lt;br /&gt;
	-- Parse the date/time in text and return n, o where&lt;br /&gt;
	--   n = table of numbers with date/time fields&lt;br /&gt;
	--   o = table of options for AM/PM or AD/BC or format, if any&lt;br /&gt;
	-- or return nothing if date is known to be invalid.&lt;br /&gt;
	-- Caller determines if the values in n are valid.&lt;br /&gt;
	-- A year must be positive (&#039;1&#039; to &#039;9999&#039;); use &#039;BC&#039; for BC.&lt;br /&gt;
	-- In a y-m-d string, the year must be four digits to avoid ambiguity&lt;br /&gt;
	-- (&#039;0001&#039; to &#039;9999&#039;). The only way to enter year &amp;lt;= 0 is by specifying&lt;br /&gt;
	-- the date as three numeric parameters like ymd Date(-1, 1, 1).&lt;br /&gt;
	-- Dates of form d/m/y, m/d/y, y/m/d are rejected as potentially ambiguous.&lt;br /&gt;
	local date, options = {}, {}&lt;br /&gt;
	if text:sub(-1) == &#039;Z&#039; then&lt;br /&gt;
		-- Extract date/time from a Wikidata timestamp.&lt;br /&gt;
		-- The year can be 1 to 16 digits but this module handles 1 to 4 digits only.&lt;br /&gt;
		-- Examples: &#039;+2016-06-21T14:30:00Z&#039;, &#039;-0000000180-00-00T00:00:00Z&#039;.&lt;br /&gt;
		local sign, y, m, d, H, M, S = text:match(&#039;^([+%-])(%d+)%-(%d%d)%-(%d%d)T(%d%d):(%d%d):(%d%d)Z$&#039;)&lt;br /&gt;
		if sign then&lt;br /&gt;
			y = tonumber(y)&lt;br /&gt;
			if sign == &#039;-&#039; and y &amp;gt; 0 then&lt;br /&gt;
				y = -y&lt;br /&gt;
			end&lt;br /&gt;
			if y &amp;lt;= 0 then&lt;br /&gt;
				options.era = &#039;BCE&#039;&lt;br /&gt;
			end&lt;br /&gt;
			date.year = y&lt;br /&gt;
			m = tonumber(m)&lt;br /&gt;
			d = tonumber(d)&lt;br /&gt;
			H = tonumber(H)&lt;br /&gt;
			M = tonumber(M)&lt;br /&gt;
			S = tonumber(S)&lt;br /&gt;
			if m == 0 then&lt;br /&gt;
				newdate.partial = true&lt;br /&gt;
				return date, options&lt;br /&gt;
			end&lt;br /&gt;
			date.month = m&lt;br /&gt;
			if d == 0 then&lt;br /&gt;
				newdate.partial = true&lt;br /&gt;
				return date, options&lt;br /&gt;
			end&lt;br /&gt;
			date.day = d&lt;br /&gt;
			if H &amp;gt; 0 or M &amp;gt; 0 or S &amp;gt; 0 then&lt;br /&gt;
				date.hour = H&lt;br /&gt;
				date.minute = M&lt;br /&gt;
				date.second = S&lt;br /&gt;
			end&lt;br /&gt;
			return date, options&lt;br /&gt;
		end&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_ymd(item)&lt;br /&gt;
		-- Called when no day or month has been set.&lt;br /&gt;
		local y, m, d = item:match(&#039;^(%d%d%d%d)%-(%w+)%-(%d%d?)$&#039;)&lt;br /&gt;
		if y then&lt;br /&gt;
			if date.year then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if m:match(&#039;^%d%d?$&#039;) then&lt;br /&gt;
				m = tonumber(m)&lt;br /&gt;
			else&lt;br /&gt;
				m = month_number(m)&lt;br /&gt;
			end&lt;br /&gt;
			if m then&lt;br /&gt;
				date.year = tonumber(y)&lt;br /&gt;
				date.month = m&lt;br /&gt;
				date.day = tonumber(d)&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_day_or_year(item)&lt;br /&gt;
		-- Called when a day would be valid, or&lt;br /&gt;
		-- when a year would be valid if no year has been set and partial is set.&lt;br /&gt;
		local number, suffix = item:match(&#039;^(%d%d?%d?%d?)(.*)$&#039;)&lt;br /&gt;
		if number then&lt;br /&gt;
			local n = tonumber(number)&lt;br /&gt;
			if #number &amp;lt;= 2 and n &amp;lt;= 31 then&lt;br /&gt;
				suffix = suffix:lower()&lt;br /&gt;
				if suffix == &#039;&#039; or suffix == &#039;st&#039; or suffix == &#039;nd&#039; or suffix == &#039;rd&#039; or suffix == &#039;th&#039; then&lt;br /&gt;
					date.day = n&lt;br /&gt;
					return true&lt;br /&gt;
				end&lt;br /&gt;
			elseif suffix == &#039;&#039; and newdate.partial and not date.year then&lt;br /&gt;
				date.year = n&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_month(item)&lt;br /&gt;
		-- A month must be given as a name or abbreviation; a number could be ambiguous.&lt;br /&gt;
		local m = month_number(item)&lt;br /&gt;
		if m then&lt;br /&gt;
			date.month = m&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_time(item)&lt;br /&gt;
		local h, m, s = item:match(&#039;^(%d%d?):(%d%d)(:?%d*)$&#039;)&lt;br /&gt;
		if date.hour or not h then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
		if s ~= &#039;&#039; then&lt;br /&gt;
			s = s:match(&#039;^:(%d%d)$&#039;)&lt;br /&gt;
			if not s then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		date.hour = tonumber(h)&lt;br /&gt;
		date.minute = tonumber(m)&lt;br /&gt;
		date.second = tonumber(s)  -- nil if empty string&lt;br /&gt;
		return true&lt;br /&gt;
	end&lt;br /&gt;
	local item_count = 0&lt;br /&gt;
	local index_time&lt;br /&gt;
	local function set_ampm(item)&lt;br /&gt;
		local H = date.hour&lt;br /&gt;
		if H and not options.am and index_time + 1 == item_count then&lt;br /&gt;
			options.am = ampm_options[item]  -- caller checked this is not nil&lt;br /&gt;
			if item:match(&#039;^[Aa]&#039;) then&lt;br /&gt;
				if not (1 &amp;lt;= H and H &amp;lt;= 12) then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				if H == 12 then&lt;br /&gt;
					date.hour = 0&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				if not (1 &amp;lt;= H and H &amp;lt;= 23) then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				if H &amp;lt;= 11 then&lt;br /&gt;
					date.hour = H + 12&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for item in text:gsub(&#039;,&#039;, &#039; &#039;):gsub(&#039;&amp;amp;nbsp;&#039;, &#039; &#039;):gmatch(&#039;%S+&#039;) do&lt;br /&gt;
		item_count = item_count + 1&lt;br /&gt;
		if era_text[item] then&lt;br /&gt;
			-- Era is accepted in peculiar places.&lt;br /&gt;
			if options.era then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			options.era = item&lt;br /&gt;
		elseif ampm_options[item] then&lt;br /&gt;
			if not set_ampm(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif item:find(&#039;:&#039;, 1, true) then&lt;br /&gt;
			if not extract_time(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			index_time = item_count&lt;br /&gt;
		elseif date.day and date.month then&lt;br /&gt;
			if date.year then&lt;br /&gt;
				return  -- should be nothing more so item is invalid&lt;br /&gt;
			end&lt;br /&gt;
			if not item:match(&#039;^(%d%d?%d?%d?)$&#039;) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			date.year = tonumber(item)&lt;br /&gt;
		elseif date.day then&lt;br /&gt;
			if not extract_month(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif date.month then&lt;br /&gt;
			if not extract_day_or_year(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif extract_month(item) then&lt;br /&gt;
			options.format = &#039;mdy&#039;&lt;br /&gt;
		elseif extract_ymd(item) then&lt;br /&gt;
			options.format = &#039;ymd&#039;&lt;br /&gt;
		elseif extract_day_or_year(item) then&lt;br /&gt;
			if date.day then&lt;br /&gt;
				options.format = &#039;dmy&#039;&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not date.year or date.year == 0 then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local era = era_text[options.era]&lt;br /&gt;
	if era and era.isbc then&lt;br /&gt;
		date.year = 1 - date.year&lt;br /&gt;
	end&lt;br /&gt;
	return date, options&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function autofill(date1, date2)&lt;br /&gt;
	-- Fill any missing month or day in each date using the&lt;br /&gt;
	-- corresponding component from the other date, if present,&lt;br /&gt;
	-- or with 1 if both dates are missing the month or day.&lt;br /&gt;
	-- This gives a good result for calculating the difference&lt;br /&gt;
	-- between two partial dates when no range is wanted.&lt;br /&gt;
	-- Return filled date1, date2 (two full dates).&lt;br /&gt;
	local function filled(a, b)&lt;br /&gt;
		local fillmonth, fillday&lt;br /&gt;
		if not a.month then&lt;br /&gt;
			fillmonth = b.month or 1&lt;br /&gt;
		end&lt;br /&gt;
		if not a.day then&lt;br /&gt;
			fillday = b.day or 1&lt;br /&gt;
		end&lt;br /&gt;
		if fillmonth or fillday then  -- need to create a new date&lt;br /&gt;
			a = Date(a, { month = fillmonth, day = fillday })&lt;br /&gt;
		end&lt;br /&gt;
		return a&lt;br /&gt;
	end&lt;br /&gt;
	return filled(date1, date2), filled(date2, date1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function date_add_sub(lhs, rhs, is_sub)&lt;br /&gt;
	-- Return a new date from calculating (lhs + rhs) or (lhs - rhs),&lt;br /&gt;
	-- or return nothing if invalid.&lt;br /&gt;
	-- The result is nil if the calculated date exceeds allowable limits.&lt;br /&gt;
	-- Caller ensures that lhs is a date; its properties are copied for the new date.&lt;br /&gt;
	if lhs.partial then&lt;br /&gt;
		-- Adding to a partial is not supported.&lt;br /&gt;
		-- Can subtract a date or partial from a partial, but this is not called for that.&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local function is_prefix(text, word, minlen)&lt;br /&gt;
		local n = #text&lt;br /&gt;
		return (minlen or 1) &amp;lt;= n and n &amp;lt;= #word and text == word:sub(1, n)&lt;br /&gt;
	end&lt;br /&gt;
	local function do_days(n)&lt;br /&gt;
		local forcetime, jd&lt;br /&gt;
		if floor(n) == n then&lt;br /&gt;
			jd = lhs.jd&lt;br /&gt;
		else&lt;br /&gt;
			forcetime = not lhs.hastime&lt;br /&gt;
			jd = lhs.jdz&lt;br /&gt;
		end&lt;br /&gt;
		jd = jd + (is_sub and -n or n)&lt;br /&gt;
		if forcetime then&lt;br /&gt;
			jd = tostring(jd)&lt;br /&gt;
			if not jd:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
				jd = jd .. &#039;.0&#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return Date(lhs, &#039;juliandate&#039;, jd)&lt;br /&gt;
	end&lt;br /&gt;
	if type(rhs) == &#039;number&#039; then&lt;br /&gt;
		-- Add/subtract days, including fractional days.&lt;br /&gt;
		return do_days(rhs)&lt;br /&gt;
	end&lt;br /&gt;
	if type(rhs) == &#039;string&#039; then&lt;br /&gt;
		-- rhs is a single component like &#039;26m&#039; or &#039;26 months&#039; (with optional sign).&lt;br /&gt;
		-- Fractions like &#039;3.25d&#039; are accepted for the units which are handled as days.&lt;br /&gt;
		local sign, numstr, id = rhs:match(&#039;^%s*([+-]?)([%d%.]+)%s*(%a+)$&#039;)&lt;br /&gt;
		if sign then&lt;br /&gt;
			if sign == &#039;-&#039; then&lt;br /&gt;
				is_sub = not (is_sub and true or false)&lt;br /&gt;
			end&lt;br /&gt;
			local y, m, days&lt;br /&gt;
			local num = tonumber(numstr)&lt;br /&gt;
			if not num then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			id = id:lower()&lt;br /&gt;
			if is_prefix(id, &#039;years&#039;) then&lt;br /&gt;
				y = num&lt;br /&gt;
				m = 0&lt;br /&gt;
			elseif is_prefix(id, &#039;months&#039;) then&lt;br /&gt;
				y = floor(num / 12)&lt;br /&gt;
				m = num % 12&lt;br /&gt;
			elseif is_prefix(id, &#039;weeks&#039;) then&lt;br /&gt;
				days = num * 7&lt;br /&gt;
			elseif is_prefix(id, &#039;days&#039;) then&lt;br /&gt;
				days = num&lt;br /&gt;
			elseif is_prefix(id, &#039;hours&#039;) then&lt;br /&gt;
				days = num / 24&lt;br /&gt;
			elseif is_prefix(id, &#039;minutes&#039;, 3) then&lt;br /&gt;
				days = num / (24 * 60)&lt;br /&gt;
			elseif is_prefix(id, &#039;seconds&#039;) then&lt;br /&gt;
				days = num / (24 * 3600)&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if days then&lt;br /&gt;
				return do_days(days)&lt;br /&gt;
			end&lt;br /&gt;
			if numstr:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if is_sub then&lt;br /&gt;
				y = -y&lt;br /&gt;
				m = -m&lt;br /&gt;
			end&lt;br /&gt;
			assert(-11 &amp;lt;= m and m &amp;lt;= 11)&lt;br /&gt;
			y = lhs.year + y&lt;br /&gt;
			m = lhs.month + m&lt;br /&gt;
			if m &amp;gt; 12 then&lt;br /&gt;
				y = y + 1&lt;br /&gt;
				m = m - 12&lt;br /&gt;
			elseif m &amp;lt; 1 then&lt;br /&gt;
				y = y - 1&lt;br /&gt;
				m = m + 12&lt;br /&gt;
			end&lt;br /&gt;
			local d = math.min(lhs.day, days_in_month(y, m, lhs.calendar))&lt;br /&gt;
			return Date(lhs, y, m, d)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if is_diff(rhs) then&lt;br /&gt;
		local days = rhs.age_days&lt;br /&gt;
		if (is_sub or false) ~= (rhs.isnegative or false) then&lt;br /&gt;
			days = -days&lt;br /&gt;
		end&lt;br /&gt;
		return lhs + days&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local full_date_only = {&lt;br /&gt;
	dayabbr = true,&lt;br /&gt;
	dayname = true,&lt;br /&gt;
	dow = true,&lt;br /&gt;
	dayofweek = true,&lt;br /&gt;
	dowiso = true,&lt;br /&gt;
	dayofweekiso = true,&lt;br /&gt;
	dayofyear = true,&lt;br /&gt;
	gsd = true,&lt;br /&gt;
	juliandate = true,&lt;br /&gt;
	jd = true,&lt;br /&gt;
	jdz = true,&lt;br /&gt;
	jdnoon = true,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Metatable for a date&#039;s calculated fields.&lt;br /&gt;
local datemt = {&lt;br /&gt;
	__index = function (self, key)&lt;br /&gt;
		if rawget(self, &#039;partial&#039;) then&lt;br /&gt;
			if full_date_only[key] then return end&lt;br /&gt;
			if key == &#039;monthabbr&#039; or key == &#039;monthdays&#039; or key == &#039;monthname&#039; then&lt;br /&gt;
				if not self.month then return end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local value&lt;br /&gt;
		if key == &#039;dayabbr&#039; then&lt;br /&gt;
			value = day_info[self.dow][1]&lt;br /&gt;
		elseif key == &#039;dayname&#039; then&lt;br /&gt;
			value = day_info[self.dow][2]&lt;br /&gt;
		elseif key == &#039;dow&#039; then&lt;br /&gt;
			value = (self.jdnoon + 1) % 7  -- day-of-week 0=Sun to 6=Sat&lt;br /&gt;
		elseif key == &#039;dayofweek&#039; then&lt;br /&gt;
			value = self.dow&lt;br /&gt;
		elseif key == &#039;dowiso&#039; then&lt;br /&gt;
			value = (self.jdnoon % 7) + 1  -- ISO day-of-week 1=Mon to 7=Sun&lt;br /&gt;
		elseif key == &#039;dayofweekiso&#039; then&lt;br /&gt;
			value = self.dowiso&lt;br /&gt;
		elseif key == &#039;dayofyear&#039; then&lt;br /&gt;
			local first = Date(self.year, 1, 1, self.calendar).jdnoon&lt;br /&gt;
			value = self.jdnoon - first + 1  -- day-of-year 1 to 366&lt;br /&gt;
		elseif key == &#039;era&#039; then&lt;br /&gt;
			-- Era text (never a negative sign) from year and options.&lt;br /&gt;
			value = get_era_for_year(self.options.era, self.year)&lt;br /&gt;
		elseif key == &#039;format&#039; then&lt;br /&gt;
			value = self.options.format or &#039;dmy&#039;&lt;br /&gt;
		elseif key == &#039;gsd&#039; then&lt;br /&gt;
			-- GSD = 1 from 00:00:00 to 23:59:59 on 1 January 1 AD Gregorian calendar,&lt;br /&gt;
			-- which is from jd 1721425.5 to 1721426.49999.&lt;br /&gt;
			value = floor(self.jd - 1721424.5)&lt;br /&gt;
		elseif key == &#039;juliandate&#039; or key == &#039;jd&#039; or key == &#039;jdz&#039; then&lt;br /&gt;
			local jd, jdz = julian_date(self)&lt;br /&gt;
			rawset(self, &#039;juliandate&#039;, jd)&lt;br /&gt;
			rawset(self, &#039;jd&#039;, jd)&lt;br /&gt;
			rawset(self, &#039;jdz&#039;, jdz)&lt;br /&gt;
			return key == &#039;jdz&#039; and jdz or jd&lt;br /&gt;
		elseif key == &#039;jdnoon&#039; then&lt;br /&gt;
			-- Julian date at noon (an integer) on the calendar day when jd occurs.&lt;br /&gt;
			value = floor(self.jd + 0.5)&lt;br /&gt;
		elseif key == &#039;isleapyear&#039; then&lt;br /&gt;
			value = is_leap_year(self.year, self.calendar)&lt;br /&gt;
		elseif key == &#039;monthabbr&#039; then&lt;br /&gt;
			value = month_info[self.month][1]&lt;br /&gt;
		elseif key == &#039;monthdays&#039; then&lt;br /&gt;
			value = days_in_month(self.year, self.month, self.calendar)&lt;br /&gt;
		elseif key == &#039;monthname&#039; then&lt;br /&gt;
			value = month_info[self.month][2]&lt;br /&gt;
		end&lt;br /&gt;
		if value ~= nil then&lt;br /&gt;
			rawset(self, key, value)&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Date operators.&lt;br /&gt;
local function mt_date_add(lhs, rhs)&lt;br /&gt;
	if not is_date(lhs) then&lt;br /&gt;
		lhs, rhs = rhs, lhs  -- put date on left (it must be a date for this to have been called)&lt;br /&gt;
	end&lt;br /&gt;
	return date_add_sub(lhs, rhs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_sub(lhs, rhs)&lt;br /&gt;
	if is_date(lhs) then&lt;br /&gt;
		if is_date(rhs) then&lt;br /&gt;
			return DateDiff(lhs, rhs)&lt;br /&gt;
		end&lt;br /&gt;
		return date_add_sub(lhs, rhs, true)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_concat(lhs, rhs)&lt;br /&gt;
	return tostring(lhs) .. tostring(rhs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_tostring(self)&lt;br /&gt;
	return self:text()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_eq(lhs, rhs)&lt;br /&gt;
	-- Return true if dates identify same date/time where, for example,&lt;br /&gt;
	-- Date(-4712, 1, 1, &#039;Julian&#039;) == Date(-4713, 11, 24, &#039;Gregorian&#039;) is true.&lt;br /&gt;
	-- This is called only if lhs and rhs have the same type and the same metamethod.&lt;br /&gt;
	if lhs.partial or rhs.partial then&lt;br /&gt;
		-- One date is partial; the other is a partial or a full date.&lt;br /&gt;
		-- The months may both be nil, but must be the same.&lt;br /&gt;
		return lhs.year == rhs.year and lhs.month == rhs.month and lhs.calendar == rhs.calendar&lt;br /&gt;
	end&lt;br /&gt;
	return lhs.jdz == rhs.jdz&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_lt(lhs, rhs)&lt;br /&gt;
	-- Return true if lhs &amp;lt; rhs, for example,&lt;br /&gt;
	-- Date(&#039;1 Jan 2016&#039;) &amp;lt; Date(&#039;06:00 1 Jan 2016&#039;) is true.&lt;br /&gt;
	-- This is called only if lhs and rhs have the same type and the same metamethod.&lt;br /&gt;
	if lhs.partial or rhs.partial then&lt;br /&gt;
		-- One date is partial; the other is a partial or a full date.&lt;br /&gt;
		if lhs.calendar ~= rhs.calendar then&lt;br /&gt;
			return lhs.calendar == &#039;Julian&#039;&lt;br /&gt;
		end&lt;br /&gt;
		if lhs.partial then&lt;br /&gt;
			lhs = lhs.partial.first&lt;br /&gt;
		end&lt;br /&gt;
		if rhs.partial then&lt;br /&gt;
			rhs = rhs.partial.first&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return lhs.jdz &amp;lt; rhs.jdz&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Examples of syntax to construct a date:&lt;br /&gt;
Date(y, m, d, &#039;julian&#039;)             default calendar is &#039;gregorian&#039;&lt;br /&gt;
Date(y, m, d, H, M, S, &#039;julian&#039;)&lt;br /&gt;
Date(&#039;juliandate&#039;, jd, &#039;julian&#039;)    if jd contains &amp;quot;.&amp;quot; text output includes H:M:S&lt;br /&gt;
Date(&#039;currentdate&#039;)&lt;br /&gt;
Date(&#039;currentdatetime&#039;)&lt;br /&gt;
Date(&#039;1 April 1995&#039;, &#039;julian&#039;)      parse date from text&lt;br /&gt;
Date(&#039;1 April 1995 AD&#039;, &#039;julian&#039;)   using an era sets a flag to do the same for output&lt;br /&gt;
Date(&#039;04:30:59 1 April 1995&#039;, &#039;julian&#039;)&lt;br /&gt;
Date(date)                          copy of an existing date&lt;br /&gt;
Date(date, t)                       same, updated with y,m,d,H,M,S fields from table t&lt;br /&gt;
Date(t)                       		date with y,m,d,H,M,S fields from table t&lt;br /&gt;
]]&lt;br /&gt;
function Date(...)  -- for forward declaration above&lt;br /&gt;
	-- Return a table holding a date assuming a uniform calendar always applies&lt;br /&gt;
	-- (proleptic Gregorian calendar or proleptic Julian calendar), or&lt;br /&gt;
	-- return nothing if date is invalid.&lt;br /&gt;
	-- A partial date has a valid year, however its month may be nil, and&lt;br /&gt;
	-- its day and time fields are nil.&lt;br /&gt;
	-- Field partial is set to false (if a full date) or a table (if a partial date).&lt;br /&gt;
	local calendars = { julian = &#039;Julian&#039;, gregorian = &#039;Gregorian&#039; }&lt;br /&gt;
	local newdate = {&lt;br /&gt;
		_id = uniq,&lt;br /&gt;
		calendar = &#039;Gregorian&#039;,  -- default is Gregorian calendar&lt;br /&gt;
		hastime = false,  -- true if input sets a time&lt;br /&gt;
		hour = 0,  -- always set hour/minute/second so don&#039;t have to handle nil&lt;br /&gt;
		minute = 0,&lt;br /&gt;
		second = 0,&lt;br /&gt;
		options = {},&lt;br /&gt;
		list = _date_list,&lt;br /&gt;
		subtract = function (self, rhs, options)&lt;br /&gt;
			return DateDiff(self, rhs, options)&lt;br /&gt;
		end,&lt;br /&gt;
		text = _date_text,&lt;br /&gt;
	}&lt;br /&gt;
	local argtype, datetext, is_copy, jd_number, tnums&lt;br /&gt;
	local numindex = 0&lt;br /&gt;
	local numfields = { &#039;year&#039;, &#039;month&#039;, &#039;day&#039;, &#039;hour&#039;, &#039;minute&#039;, &#039;second&#039; }&lt;br /&gt;
	local numbers = {}&lt;br /&gt;
	for _, v in ipairs({...}) do&lt;br /&gt;
		v = strip_to_nil(v)&lt;br /&gt;
		local vlower = type(v) == &#039;string&#039; and v:lower() or nil&lt;br /&gt;
		if v == nil then&lt;br /&gt;
			-- Ignore empty arguments after stripping so modules can directly pass template parameters.&lt;br /&gt;
		elseif calendars[vlower] then&lt;br /&gt;
			newdate.calendar = calendars[vlower]&lt;br /&gt;
		elseif vlower == &#039;partial&#039; then&lt;br /&gt;
			newdate.partial = true&lt;br /&gt;
		elseif vlower == &#039;fix&#039; then&lt;br /&gt;
			newdate.want_fix = true&lt;br /&gt;
		elseif is_date(v) then&lt;br /&gt;
			-- Copy existing date (items can be overridden by other arguments).&lt;br /&gt;
			if is_copy or tnums then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			is_copy = true&lt;br /&gt;
			newdate.calendar = v.calendar&lt;br /&gt;
			newdate.partial = v.partial&lt;br /&gt;
			newdate.hastime = v.hastime&lt;br /&gt;
			newdate.options = v.options&lt;br /&gt;
			newdate.year = v.year&lt;br /&gt;
			newdate.month = v.month&lt;br /&gt;
			newdate.day = v.day&lt;br /&gt;
			newdate.hour = v.hour&lt;br /&gt;
			newdate.minute = v.minute&lt;br /&gt;
			newdate.second = v.second&lt;br /&gt;
		elseif type(v) == &#039;table&#039; then&lt;br /&gt;
			if tnums then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			tnums = {}&lt;br /&gt;
			local tfields = { year=1, month=1, day=1, hour=2, minute=2, second=2 }&lt;br /&gt;
			for tk, tv in pairs(v) do&lt;br /&gt;
				if tfields[tk] then&lt;br /&gt;
					tnums[tk] = tonumber(tv)&lt;br /&gt;
				end&lt;br /&gt;
				if tfields[tk] == 2 then&lt;br /&gt;
					newdate.hastime = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			local num = tonumber(v)&lt;br /&gt;
			if not num and argtype == &#039;setdate&#039; and numindex == 1 then&lt;br /&gt;
				num = month_number(v)&lt;br /&gt;
			end&lt;br /&gt;
			if num then&lt;br /&gt;
				if not argtype then&lt;br /&gt;
					argtype = &#039;setdate&#039;&lt;br /&gt;
				end&lt;br /&gt;
				if argtype == &#039;setdate&#039; and numindex &amp;lt; 6 then&lt;br /&gt;
					numindex = numindex + 1&lt;br /&gt;
					numbers[numfields[numindex]] = num&lt;br /&gt;
				elseif argtype == &#039;juliandate&#039; and not jd_number then&lt;br /&gt;
					jd_number = num&lt;br /&gt;
					if type(v) == &#039;string&#039; then&lt;br /&gt;
						if v:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
							newdate.hastime = true&lt;br /&gt;
						end&lt;br /&gt;
					elseif num ~= floor(num) then&lt;br /&gt;
						-- The given value was a number. The time will be used&lt;br /&gt;
						-- if the fractional part is nonzero.&lt;br /&gt;
						newdate.hastime = true&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
			elseif argtype then&lt;br /&gt;
				return&lt;br /&gt;
			elseif type(v) == &#039;string&#039; then&lt;br /&gt;
				if v == &#039;currentdate&#039; or v == &#039;currentdatetime&#039; or v == &#039;juliandate&#039; then&lt;br /&gt;
					argtype = v&lt;br /&gt;
				else&lt;br /&gt;
					argtype = &#039;datetext&#039;&lt;br /&gt;
					datetext = v&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if argtype == &#039;datetext&#039; then&lt;br /&gt;
		if tnums or not set_date_from_numbers(newdate, extract_date(newdate, datetext)) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif argtype == &#039;juliandate&#039; then&lt;br /&gt;
		newdate.partial = nil&lt;br /&gt;
		newdate.jd = jd_number&lt;br /&gt;
		if not set_date_from_jd(newdate) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif argtype == &#039;currentdate&#039; or argtype == &#039;currentdatetime&#039; then&lt;br /&gt;
		newdate.partial = nil&lt;br /&gt;
		newdate.year = current.year&lt;br /&gt;
		newdate.month = current.month&lt;br /&gt;
		newdate.day = current.day&lt;br /&gt;
		if argtype == &#039;currentdatetime&#039; then&lt;br /&gt;
			newdate.hour = current.hour&lt;br /&gt;
			newdate.minute = current.minute&lt;br /&gt;
			newdate.second = current.second&lt;br /&gt;
			newdate.hastime = true&lt;br /&gt;
		end&lt;br /&gt;
		newdate.calendar = &#039;Gregorian&#039;  -- ignore any given calendar name&lt;br /&gt;
	elseif argtype == &#039;setdate&#039; then&lt;br /&gt;
		if tnums or not set_date_from_numbers(newdate, numbers) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif not (is_copy or tnums) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	if tnums then&lt;br /&gt;
		newdate.jd = nil  -- force recalculation in case jd was set before changes from tnums&lt;br /&gt;
		if not set_date_from_numbers(newdate, tnums) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if newdate.partial then&lt;br /&gt;
		local year = newdate.year&lt;br /&gt;
		local month = newdate.month&lt;br /&gt;
		local first = Date(year, month or 1, 1, newdate.calendar)&lt;br /&gt;
		month = month or 12&lt;br /&gt;
		local last = Date(year, month, days_in_month(year, month), newdate.calendar)&lt;br /&gt;
		newdate.partial = { first = first, last = last }&lt;br /&gt;
	else&lt;br /&gt;
		newdate.partial = false  -- avoid index lookup&lt;br /&gt;
	end&lt;br /&gt;
	setmetatable(newdate, datemt)&lt;br /&gt;
	local readonly = {}&lt;br /&gt;
	local mt = {&lt;br /&gt;
		__index = newdate,&lt;br /&gt;
		__newindex = function(t, k, v) error(&#039;date.&#039; .. tostring(k) .. &#039; is read-only&#039;, 2) end,&lt;br /&gt;
		__add = mt_date_add,&lt;br /&gt;
		__sub = mt_date_sub,&lt;br /&gt;
		__concat = mt_date_concat,&lt;br /&gt;
		__tostring = mt_date_tostring,&lt;br /&gt;
		__eq = mt_date_eq,&lt;br /&gt;
		__lt = mt_date_lt,&lt;br /&gt;
	}&lt;br /&gt;
	return setmetatable(readonly, mt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _diff_age(diff, code, options)&lt;br /&gt;
	-- Return a tuple of integer values from diff as specified by code, except that&lt;br /&gt;
	-- each integer may be a list of two integers for a diff with a partial date, or&lt;br /&gt;
	-- return nil if the code is not supported.&lt;br /&gt;
	-- If want round, the least significant unit is rounded to nearest whole unit.&lt;br /&gt;
	-- For a duration, an extra day is added.&lt;br /&gt;
	local wantround, wantduration, wantrange&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		wantround = options.round&lt;br /&gt;
		wantduration = options.duration&lt;br /&gt;
		wantrange = options.range&lt;br /&gt;
	else&lt;br /&gt;
		wantround = options&lt;br /&gt;
	end&lt;br /&gt;
	if not is_diff(diff) then&lt;br /&gt;
		local f = wantduration and &#039;duration&#039; or &#039;age&#039;&lt;br /&gt;
		error(f .. &#039;: need a date difference (use &amp;quot;diff:&#039; .. f .. &#039;()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if diff.partial then&lt;br /&gt;
		-- Ignore wantround, wantduration.&lt;br /&gt;
		local function choose(v)&lt;br /&gt;
			if type(v) == &#039;table&#039; then&lt;br /&gt;
				if not wantrange or v[1] == v[2] then&lt;br /&gt;
					-- Example: Date(&#039;partial&#039;, 2005) - Date(&#039;partial&#039;, 2001) gives&lt;br /&gt;
					-- diff.years = { 3, 4 } to show the range of possible results.&lt;br /&gt;
					-- If do not want a range, choose the second value as more expected.&lt;br /&gt;
					return v[2]&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return v&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;ym&#039; or code == &#039;ymd&#039; then&lt;br /&gt;
			if not wantrange and diff.iszero then&lt;br /&gt;
				-- This avoids an unexpected result such as&lt;br /&gt;
				-- Date(&#039;partial&#039;, 2001) - Date(&#039;partial&#039;, 2001)&lt;br /&gt;
				-- giving diff = { years = 0, months = { 0, 11 } }&lt;br /&gt;
				-- which would be reported as 0 years and 11 months.&lt;br /&gt;
				return 0, 0&lt;br /&gt;
			end&lt;br /&gt;
			return choose(diff.partial.years), choose(diff.partial.months)&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;y&#039; then&lt;br /&gt;
			return choose(diff.partial.years)&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;m&#039; or code == &#039;w&#039; or code == &#039;d&#039; then&lt;br /&gt;
			return choose({ diff.partial.mindiff:age(code), diff.partial.maxdiff:age(code) })&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local extra_days = wantduration and 1 or 0&lt;br /&gt;
	if code == &#039;wd&#039; or code == &#039;w&#039; or code == &#039;d&#039; then&lt;br /&gt;
		local offset = wantround and 0.5 or 0&lt;br /&gt;
		local days = diff.age_days + extra_days&lt;br /&gt;
		if code == &#039;wd&#039; or code == &#039;d&#039; then&lt;br /&gt;
			days = floor(days + offset)&lt;br /&gt;
			if code == &#039;d&#039; then&lt;br /&gt;
				return days&lt;br /&gt;
			end&lt;br /&gt;
			return floor(days/7), days % 7&lt;br /&gt;
		end&lt;br /&gt;
		return floor(days/7 + offset)&lt;br /&gt;
	end&lt;br /&gt;
	local H, M, S = diff.hours, diff.minutes, diff.seconds&lt;br /&gt;
	if code == &#039;dh&#039; or code == &#039;dhm&#039; or code == &#039;dhms&#039; or code == &#039;h&#039; or code == &#039;hm&#039; or code == &#039;hms&#039; then&lt;br /&gt;
		local days = floor(diff.age_days + extra_days)&lt;br /&gt;
		local inc_hour&lt;br /&gt;
		if wantround then&lt;br /&gt;
			if code == &#039;dh&#039; or code == &#039;h&#039; then&lt;br /&gt;
				if M &amp;gt;= 30 then&lt;br /&gt;
					inc_hour = true&lt;br /&gt;
				end&lt;br /&gt;
			elseif code == &#039;dhm&#039; or code == &#039;hm&#039; then&lt;br /&gt;
				if S &amp;gt;= 30 then&lt;br /&gt;
					M = M + 1&lt;br /&gt;
					if M &amp;gt;= 60 then&lt;br /&gt;
						M = 0&lt;br /&gt;
						inc_hour = true&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				-- Nothing needed because S is an integer.&lt;br /&gt;
			end&lt;br /&gt;
			if inc_hour then&lt;br /&gt;
				H = H + 1&lt;br /&gt;
				if H &amp;gt;= 24 then&lt;br /&gt;
					H = 0&lt;br /&gt;
					days = days + 1&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;dh&#039; or code == &#039;dhm&#039; or code == &#039;dhms&#039; then&lt;br /&gt;
			if code == &#039;dh&#039; then&lt;br /&gt;
				return days, H&lt;br /&gt;
			elseif code == &#039;dhm&#039; then&lt;br /&gt;
				return days, H, M&lt;br /&gt;
			else&lt;br /&gt;
				return days, H, M, S&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local hours = days * 24 + H&lt;br /&gt;
		if code == &#039;h&#039; then&lt;br /&gt;
			return hours&lt;br /&gt;
		elseif code == &#039;hm&#039; then&lt;br /&gt;
			return hours, M&lt;br /&gt;
		end&lt;br /&gt;
		return hours, M, S&lt;br /&gt;
	end&lt;br /&gt;
	if wantround then&lt;br /&gt;
		local inc_hour&lt;br /&gt;
		if code == &#039;ymdh&#039; or code == &#039;ymwdh&#039; then&lt;br /&gt;
			if M &amp;gt;= 30 then&lt;br /&gt;
				inc_hour = true&lt;br /&gt;
			end&lt;br /&gt;
		elseif code == &#039;ymdhm&#039; or code == &#039;ymwdhm&#039; then&lt;br /&gt;
			if S &amp;gt;= 30 then&lt;br /&gt;
				M = M + 1&lt;br /&gt;
				if M &amp;gt;= 60 then&lt;br /&gt;
					M = 0&lt;br /&gt;
					inc_hour = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		elseif code == &#039;ymd&#039; or code == &#039;ymwd&#039; or code == &#039;yd&#039; or code == &#039;md&#039; then&lt;br /&gt;
			if H &amp;gt;= 12 then&lt;br /&gt;
				extra_days = extra_days + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if inc_hour then&lt;br /&gt;
			H = H + 1&lt;br /&gt;
			if H &amp;gt;= 24 then&lt;br /&gt;
				H = 0&lt;br /&gt;
				extra_days = extra_days + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local y, m, d = diff.years, diff.months, diff.days&lt;br /&gt;
	if extra_days &amp;gt; 0 then&lt;br /&gt;
		d = d + extra_days&lt;br /&gt;
		if d &amp;gt; 28 or code == &#039;yd&#039; then&lt;br /&gt;
			-- Recalculate in case have passed a month.&lt;br /&gt;
			diff = diff.date1 + extra_days - diff.date2&lt;br /&gt;
			y, m, d = diff.years, diff.months, diff.days&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if code == &#039;ymd&#039; then&lt;br /&gt;
		return y, m, d&lt;br /&gt;
	elseif code == &#039;yd&#039; then&lt;br /&gt;
		if y &amp;gt; 0 then&lt;br /&gt;
			-- It is known that diff.date1 &amp;gt; diff.date2.&lt;br /&gt;
			diff = diff.date1 - (diff.date2 + (y .. &#039;y&#039;))&lt;br /&gt;
		end&lt;br /&gt;
		return y, floor(diff.age_days)&lt;br /&gt;
	elseif code == &#039;md&#039; then&lt;br /&gt;
		return y * 12 + m, d&lt;br /&gt;
	elseif code == &#039;ym&#039; or code == &#039;m&#039; then&lt;br /&gt;
		if wantround then&lt;br /&gt;
			if d &amp;gt;= 16 then&lt;br /&gt;
				m = m + 1&lt;br /&gt;
				if m &amp;gt;= 12 then&lt;br /&gt;
					m = 0&lt;br /&gt;
					y = y + 1&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;ym&#039; then&lt;br /&gt;
			return y, m&lt;br /&gt;
		end&lt;br /&gt;
		return y * 12 + m&lt;br /&gt;
	elseif code == &#039;ymw&#039; then&lt;br /&gt;
		local weeks = floor(d/7)&lt;br /&gt;
		if wantround then&lt;br /&gt;
			local days = d % 7&lt;br /&gt;
			if days &amp;gt; 3 or (days == 3 and H &amp;gt;= 12) then&lt;br /&gt;
				weeks = weeks + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return y, m, weeks&lt;br /&gt;
	elseif code == &#039;ymwd&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7&lt;br /&gt;
	elseif code == &#039;ymdh&#039; then&lt;br /&gt;
		return y, m, d, H&lt;br /&gt;
	elseif code == &#039;ymwdh&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7, H&lt;br /&gt;
	elseif code == &#039;ymdhm&#039; then&lt;br /&gt;
		return y, m, d, H, M&lt;br /&gt;
	elseif code == &#039;ymwdhm&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7, H, M&lt;br /&gt;
	end&lt;br /&gt;
	if code == &#039;y&#039; then&lt;br /&gt;
		if wantround and m &amp;gt;= 6 then&lt;br /&gt;
			y = y + 1&lt;br /&gt;
		end&lt;br /&gt;
		return y&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _diff_duration(diff, code, options)&lt;br /&gt;
	if type(options) ~= &#039;table&#039; then&lt;br /&gt;
		options = { round = options }&lt;br /&gt;
	end&lt;br /&gt;
	options.duration = true&lt;br /&gt;
	return _diff_age(diff, code, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Metatable for some operations on date differences.&lt;br /&gt;
diffmt = {  -- for forward declaration above&lt;br /&gt;
	__concat = function (lhs, rhs)&lt;br /&gt;
		return tostring(lhs) .. tostring(rhs)&lt;br /&gt;
	end,&lt;br /&gt;
	__tostring = function (self)&lt;br /&gt;
		return tostring(self.age_days)&lt;br /&gt;
	end,&lt;br /&gt;
	__index = function (self, key)&lt;br /&gt;
		local value&lt;br /&gt;
		if key == &#039;age_days&#039; then&lt;br /&gt;
			if rawget(self, &#039;partial&#039;) then&lt;br /&gt;
				local function jdz(date)&lt;br /&gt;
					return (date.partial and date.partial.first or date).jdz&lt;br /&gt;
				end&lt;br /&gt;
				value = jdz(self.date1) - jdz(self.date2)&lt;br /&gt;
			else&lt;br /&gt;
				value = self.date1.jdz - self.date2.jdz&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if value ~= nil then&lt;br /&gt;
			rawset(self, key, value)&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function DateDiff(date1, date2, options)  -- for forward declaration above&lt;br /&gt;
	-- Return a table with the difference between two dates (date1 - date2).&lt;br /&gt;
	-- The difference is negative if date1 is older than date2.&lt;br /&gt;
	-- Return nothing if invalid.&lt;br /&gt;
	-- If d = date1 - date2 then&lt;br /&gt;
	--     date1 = date2 + d&lt;br /&gt;
	-- If date1 &amp;gt;= date2 and the dates have no H:M:S time specified then&lt;br /&gt;
	--     date1 = date2 + (d.years..&#039;y&#039;) + (d.months..&#039;m&#039;) + d.days&lt;br /&gt;
	-- where the larger time units are added first.&lt;br /&gt;
	-- The result of Date(2015,1,x) + &#039;1m&#039; is Date(2015,2,28) for&lt;br /&gt;
	-- x = 28, 29, 30, 31. That means, for example,&lt;br /&gt;
	--     d = Date(2015,3,3) - Date(2015,1,31)&lt;br /&gt;
	-- gives d.years, d.months, d.days = 0, 1, 3 (excluding date1).&lt;br /&gt;
	if not (is_date(date1) and is_date(date2) and date1.calendar == date2.calendar) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local wantfill&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		wantfill = options.fill&lt;br /&gt;
	end&lt;br /&gt;
	local isnegative = false&lt;br /&gt;
	local iszero = false&lt;br /&gt;
	if date1 &amp;lt; date2 then&lt;br /&gt;
		isnegative = true&lt;br /&gt;
		date1, date2 = date2, date1&lt;br /&gt;
	elseif date1 == date2 then&lt;br /&gt;
		iszero = true&lt;br /&gt;
	end&lt;br /&gt;
	-- It is known that date1 &amp;gt;= date2 (period is from date2 to date1).&lt;br /&gt;
	if date1.partial or date2.partial then&lt;br /&gt;
		-- Two partial dates might have timelines:&lt;br /&gt;
		---------------------A=================B--- date1 is from A to B inclusive&lt;br /&gt;
		--------C=======D-------------------------- date2 is from C to D inclusive&lt;br /&gt;
		-- date1 &amp;gt; date2 iff A &amp;gt; C (date1.partial.first &amp;gt; date2.partial.first)&lt;br /&gt;
		-- The periods can overlap (&#039;April 2001&#039; - &#039;2001&#039;):&lt;br /&gt;
		-------------A===B------------------------- A=2001-04-01  B=2001-04-30&lt;br /&gt;
		--------C=====================D------------ C=2001-01-01  D=2001-12-31&lt;br /&gt;
		if wantfill then&lt;br /&gt;
			date1, date2 = autofill(date1, date2)&lt;br /&gt;
		else&lt;br /&gt;
			local function zdiff(date1, date2)&lt;br /&gt;
				local diff = date1 - date2&lt;br /&gt;
				if diff.isnegative then&lt;br /&gt;
					return date1 - date1  -- a valid diff in case we call its methods&lt;br /&gt;
				end&lt;br /&gt;
				return diff&lt;br /&gt;
			end&lt;br /&gt;
			local function getdate(date, which)&lt;br /&gt;
				return date.partial and date.partial[which] or date&lt;br /&gt;
			end&lt;br /&gt;
			local maxdiff = zdiff(getdate(date1, &#039;last&#039;), getdate(date2, &#039;first&#039;))&lt;br /&gt;
			local mindiff = zdiff(getdate(date1, &#039;first&#039;), getdate(date2, &#039;last&#039;))&lt;br /&gt;
			local years, months&lt;br /&gt;
			if maxdiff.years == mindiff.years then&lt;br /&gt;
				years = maxdiff.years&lt;br /&gt;
				if maxdiff.months == mindiff.months then&lt;br /&gt;
					months = maxdiff.months&lt;br /&gt;
				else&lt;br /&gt;
					months = { mindiff.months, maxdiff.months }&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				years = { mindiff.years, maxdiff.years }&lt;br /&gt;
			end&lt;br /&gt;
			return setmetatable({&lt;br /&gt;
				date1 = date1,&lt;br /&gt;
				date2 = date2,&lt;br /&gt;
				partial = {&lt;br /&gt;
					years = years,&lt;br /&gt;
					months = months,&lt;br /&gt;
					maxdiff = maxdiff,&lt;br /&gt;
					mindiff = mindiff,&lt;br /&gt;
				},&lt;br /&gt;
				isnegative = isnegative,&lt;br /&gt;
				iszero = iszero,&lt;br /&gt;
				age = _diff_age,&lt;br /&gt;
				duration = _diff_duration,&lt;br /&gt;
			}, diffmt)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local y1, m1 = date1.year, date1.month&lt;br /&gt;
	local y2, m2 = date2.year, date2.month&lt;br /&gt;
	local years = y1 - y2&lt;br /&gt;
	local months = m1 - m2&lt;br /&gt;
	local d1 = date1.day + hms(date1)&lt;br /&gt;
	local d2 = date2.day + hms(date2)&lt;br /&gt;
	local days, time&lt;br /&gt;
	if d1 &amp;gt;= d2 then&lt;br /&gt;
		days = d1 - d2&lt;br /&gt;
	else&lt;br /&gt;
		months = months - 1&lt;br /&gt;
		-- Get days in previous month (before the &amp;quot;to&amp;quot; date) given December has 31 days.&lt;br /&gt;
		local dpm = m1 &amp;gt; 1 and days_in_month(y1, m1 - 1, date1.calendar) or 31&lt;br /&gt;
		if d2 &amp;gt;= dpm then&lt;br /&gt;
			days = d1 - hms(date2)&lt;br /&gt;
		else&lt;br /&gt;
			days = dpm - d2 + d1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if months &amp;lt; 0 then&lt;br /&gt;
		years = years - 1&lt;br /&gt;
		months = months + 12&lt;br /&gt;
	end&lt;br /&gt;
	days, time = math.modf(days)&lt;br /&gt;
	local H, M, S = h_m_s(time)&lt;br /&gt;
	return setmetatable({&lt;br /&gt;
		date1 = date1,&lt;br /&gt;
		date2 = date2,&lt;br /&gt;
		partial = false,  -- avoid index lookup&lt;br /&gt;
		years = years,&lt;br /&gt;
		months = months,&lt;br /&gt;
		days = days,&lt;br /&gt;
		hours = H,&lt;br /&gt;
		minutes = M,&lt;br /&gt;
		seconds = S,&lt;br /&gt;
		isnegative = isnegative,&lt;br /&gt;
		iszero = iszero,&lt;br /&gt;
		age = _diff_age,&lt;br /&gt;
		duration = _diff_duration,&lt;br /&gt;
	}, diffmt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	_current = current,&lt;br /&gt;
	_Date = Date,&lt;br /&gt;
	_days_in_month = days_in_month,&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Age&amp;diff=1335</id>
		<title>模組:Age</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Age&amp;diff=1335"/>
		<updated>2026-10-04T16:01:23Z</updated>

		<summary type="html">&lt;p&gt;DC：​&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;-- Implement various &amp;quot;age of&amp;quot; and other date-related templates.&lt;br /&gt;
&lt;br /&gt;
local _Date, _currentDate&lt;br /&gt;
local function getExports(frame)&lt;br /&gt;
	-- Return objects exported from the date module or its sandbox.&lt;br /&gt;
	if not _Date then&lt;br /&gt;
		local sandbox = frame:getTitle():find(&#039;sandbox&#039;, 1, true) and &#039;/sandbox&#039; or &#039;&#039;&lt;br /&gt;
		local datemod = require(&#039;Module:Date&#039; .. sandbox)&lt;br /&gt;
		_Date = datemod._Date&lt;br /&gt;
		_currentDate = datemod._current&lt;br /&gt;
	end&lt;br /&gt;
	return _Date, _currentDate&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local Collection  -- a table to hold items&lt;br /&gt;
Collection = {&lt;br /&gt;
	add = function (self, item)&lt;br /&gt;
		if item ~= nil then&lt;br /&gt;
			self.n = self.n + 1&lt;br /&gt;
			self[self.n] = item&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
	join = function (self, sep)&lt;br /&gt;
		return table.concat(self, sep)&lt;br /&gt;
	end,&lt;br /&gt;
	remove = function (self, pos)&lt;br /&gt;
		if self.n &amp;gt; 0 and (pos == nil or (0 &amp;lt; pos and pos &amp;lt;= self.n)) then&lt;br /&gt;
			self.n = self.n - 1&lt;br /&gt;
			return table.remove(self, pos)&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
	sort = function (self, comp)&lt;br /&gt;
		table.sort(self, comp)&lt;br /&gt;
	end,&lt;br /&gt;
	new = function ()&lt;br /&gt;
		return setmetatable({n = 0}, Collection)&lt;br /&gt;
	end&lt;br /&gt;
}&lt;br /&gt;
Collection.__index = Collection&lt;br /&gt;
&lt;br /&gt;
local function stripToNil(text)&lt;br /&gt;
	-- If text is a string, return its trimmed content, or nil if empty.&lt;br /&gt;
	-- Otherwise return text (which may, for example, be nil).&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		text = text:match(&#039;(%S.-)%s*$&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local yes = require(&#039;Module:Yesno&#039;)&lt;br /&gt;
&lt;br /&gt;
local function message(msg, id)&lt;br /&gt;
	-- Return formatted message text for an error or warning.&lt;br /&gt;
	local categories = {&lt;br /&gt;
		error = &#039;[[Category:Age模組錯誤]]&#039;,&lt;br /&gt;
		warning = &#039;[[Category:Age模組錯誤]]&#039;,  -- same as error until determine whether &#039;Age warning&#039; would be worthwhile&lt;br /&gt;
	}&lt;br /&gt;
	local a, b, category&lt;br /&gt;
	if id == &#039;warning&#039; then&lt;br /&gt;
		a = &#039;&amp;lt;sup&amp;gt;[&amp;lt;i&amp;gt;&#039;&lt;br /&gt;
		b = &#039;&amp;lt;/i&amp;gt;]&amp;lt;/sup&amp;gt;&#039;&lt;br /&gt;
	else&lt;br /&gt;
		a = &#039;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;錯誤：&#039;&lt;br /&gt;
		b = &#039;&amp;lt;/strong&amp;gt;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	if mw.title.getCurrentTitle():inNamespaces(0) then&lt;br /&gt;
		-- Category only in namespaces: 0=article.&lt;br /&gt;
		category = categories[id or &#039;error&#039;]&lt;br /&gt;
	end&lt;br /&gt;
	return&lt;br /&gt;
		a ..&lt;br /&gt;
		mw.text.nowiki(msg) ..&lt;br /&gt;
		b ..&lt;br /&gt;
		(category or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function formatNumber(number)&lt;br /&gt;
	-- Return the given number formatted with commas as group separators,&lt;br /&gt;
	-- given that the number is an integer.&lt;br /&gt;
	local numstr = tostring(number)&lt;br /&gt;
	local length = #numstr&lt;br /&gt;
	local places = Collection.new()&lt;br /&gt;
	local pos = 0&lt;br /&gt;
	repeat&lt;br /&gt;
		places:add(pos)&lt;br /&gt;
		pos = pos + 3&lt;br /&gt;
	until pos &amp;gt;= length&lt;br /&gt;
	places:add(length)&lt;br /&gt;
	local groups = Collection.new()&lt;br /&gt;
	for i = places.n, 2, -1 do&lt;br /&gt;
		local p1 = length - places[i] + 1&lt;br /&gt;
		local p2 = length - places[i - 1]&lt;br /&gt;
		groups:add(numstr:sub(p1, p2))&lt;br /&gt;
	end&lt;br /&gt;
	return groups:join(&#039;,&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function spellNumber(number, options, i)&lt;br /&gt;
	-- Return result of spelling number, or&lt;br /&gt;
	-- return number (as a string) if cannot spell it.&lt;br /&gt;
	-- i == 1 for the first number which can optionally start with an uppercase letter.&lt;br /&gt;
	number = tostring(number)&lt;br /&gt;
	return require(&#039;Module:ConvertNumeric&#039;).spell_number(&lt;br /&gt;
		number,&lt;br /&gt;
		nil,                       -- fraction numerator&lt;br /&gt;
		nil,                       -- fraction denominator&lt;br /&gt;
		i == 1 and options.upper,  -- true: &#039;One&#039; instead of &#039;one&#039;&lt;br /&gt;
		not options.us,            -- true: use &#039;and&#039; between tens/ones etc&lt;br /&gt;
		options.adj,               -- true: hyphenated&lt;br /&gt;
		options.ordinal            -- true: &#039;first&#039; instead of &#039;one&#039;&lt;br /&gt;
	) or number&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeSort(value, sortable)&lt;br /&gt;
	-- Return a sort key if requested.&lt;br /&gt;
	-- Assume value is a valid number which has not overflowed.&lt;br /&gt;
	if sortable == &#039;sortable_table&#039; or sortable == &#039;sortable_on&#039; or sortable == &#039;sortable_debug&#039; then&lt;br /&gt;
		local sortkey&lt;br /&gt;
		if value == 0 then&lt;br /&gt;
			sortkey = &#039;5000000000000000000&#039;&lt;br /&gt;
		else&lt;br /&gt;
			local mag = math.floor(math.log10(math.abs(value)) + 1e-14)&lt;br /&gt;
			local prefix&lt;br /&gt;
			if value &amp;gt; 0 then&lt;br /&gt;
				prefix = 7000 + mag&lt;br /&gt;
			else&lt;br /&gt;
				prefix = 2999 - mag&lt;br /&gt;
				value = value + 10^(mag+1)&lt;br /&gt;
			end&lt;br /&gt;
			sortkey = string.format(&#039;%d&#039;, prefix) .. string.format(&#039;%015.0f&#039;, math.floor(value * 10^(14-mag)))&lt;br /&gt;
		end&lt;br /&gt;
		local lhs, rhs&lt;br /&gt;
		if sortable == &#039;sortable_table&#039; then&lt;br /&gt;
			lhs = &#039;data-sort-value=&amp;quot;&#039;&lt;br /&gt;
			rhs = &#039;&amp;quot;|&#039;&lt;br /&gt;
		else&lt;br /&gt;
			lhs = sortable == &#039;sortable_debug&#039; and&lt;br /&gt;
				&#039;&amp;lt;span style=&amp;quot;border:1px solid;display:inline;&amp;quot; class=&amp;quot;sortkey&amp;quot;&amp;gt;&#039; or&lt;br /&gt;
				&#039;&amp;lt;span style=&amp;quot;display:none&amp;quot; class=&amp;quot;sortkey&amp;quot;&amp;gt;&#039;&lt;br /&gt;
			rhs = &#039;♠&amp;lt;/span&amp;gt;&#039;&lt;br /&gt;
		end&lt;br /&gt;
		return lhs .. sortkey .. rhs&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local translateParameters = {&lt;br /&gt;
	abbr = {&lt;br /&gt;
		off = &#039;abbr_off&#039;,&lt;br /&gt;
		on = &#039;abbr_on&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	disp = {&lt;br /&gt;
		age = &#039;disp_age&#039;,&lt;br /&gt;
		raw = &#039;disp_raw&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	format = {&lt;br /&gt;
		raw = &#039;format_raw&#039;,&lt;br /&gt;
		commas = &#039;format_commas&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	round = {&lt;br /&gt;
		on = &#039;on&#039;,&lt;br /&gt;
		yes = &#039;on&#039;,&lt;br /&gt;
		months = &#039;ym&#039;,&lt;br /&gt;
		weeks = &#039;ymw&#039;,&lt;br /&gt;
		days = &#039;ymd&#039;,&lt;br /&gt;
		hours = &#039;ymdh&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	sep = {&lt;br /&gt;
		comma = &#039;sep_comma&#039;,&lt;br /&gt;
		[&#039;,&#039;] = &#039;sep_comma&#039;,&lt;br /&gt;
		serialcomma = &#039;sep_serialcomma&#039;,&lt;br /&gt;
		space = &#039;sep_space&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	show = {&lt;br /&gt;
		hide = { id = &#039;hide&#039; },&lt;br /&gt;
		y = { &#039;y&#039;, id = &#039;y&#039; },&lt;br /&gt;
		ym = { &#039;y&#039;, &#039;m&#039;, id = &#039;ym&#039; },&lt;br /&gt;
		ymd = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, id = &#039;ymd&#039; },&lt;br /&gt;
		ymw = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, id = &#039;ymw&#039; },&lt;br /&gt;
		ymwd = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, id = &#039;ymwd&#039; },&lt;br /&gt;
		yd = { &#039;y&#039;, &#039;d&#039;, id = &#039;yd&#039;, keepZero = true },&lt;br /&gt;
		m = { &#039;m&#039;, id = &#039;m&#039; },&lt;br /&gt;
		md = { &#039;m&#039;, &#039;d&#039;, id = &#039;md&#039; },&lt;br /&gt;
		w = { &#039;w&#039;, id = &#039;w&#039; },&lt;br /&gt;
		wd = { &#039;w&#039;, &#039;d&#039;, id = &#039;wd&#039; },&lt;br /&gt;
		h = { &#039;H&#039;, id = &#039;h&#039; },&lt;br /&gt;
		hm = { &#039;H&#039;, &#039;M&#039;, id = &#039;hm&#039; },&lt;br /&gt;
		hms = { &#039;H&#039;, &#039;M&#039;, &#039;S&#039;, id = &#039;hms&#039; },&lt;br /&gt;
		d = { &#039;d&#039;, id = &#039;d&#039; },&lt;br /&gt;
		dh = { &#039;d&#039;, &#039;H&#039;, id = &#039;dh&#039; },&lt;br /&gt;
		dhm = { &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;dhm&#039; },&lt;br /&gt;
		dhms = { &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, &#039;S&#039;, id = &#039;dhms&#039; },&lt;br /&gt;
		ymdh = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, &#039;H&#039;, id = &#039;ymdh&#039; },&lt;br /&gt;
		ymdhm = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;ymdhm&#039; },&lt;br /&gt;
		ymwdh = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, &#039;H&#039;, id = &#039;ymwdh&#039; },&lt;br /&gt;
		ymwdhm = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;ymwdhm&#039; },&lt;br /&gt;
	},&lt;br /&gt;
	sortable = {&lt;br /&gt;
		off = false,&lt;br /&gt;
		on = &#039;sortable_on&#039;,&lt;br /&gt;
		table = &#039;sortable_table&#039;,&lt;br /&gt;
		debug = &#039;sortable_debug&#039;,&lt;br /&gt;
	},&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local spellOptions = {&lt;br /&gt;
	cardinal = {},&lt;br /&gt;
	Cardinal = { upper = true },&lt;br /&gt;
	cardinal_us = { us = true },&lt;br /&gt;
	Cardinal_us = { us = true, upper = true },&lt;br /&gt;
	ordinal = { ordinal = true },&lt;br /&gt;
	Ordinal = { ordinal = true, upper = true },&lt;br /&gt;
	ordinal_us = { ordinal = true, us = true },&lt;br /&gt;
	Ordinal_us = { ordinal = true, us = true, upper = true },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function dateExtract(frame)&lt;br /&gt;
	-- Return part of a date after performing an optional operation.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local parms = {}&lt;br /&gt;
	for i, v in ipairs(args) do&lt;br /&gt;
		parms[i] = v&lt;br /&gt;
	end&lt;br /&gt;
	if yes(args.fix) then&lt;br /&gt;
		table.insert(parms, &#039;fix&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if yes(args.partial) then&lt;br /&gt;
		table.insert(parms, &#039;partial&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local show = stripToNil(args.show) or &#039;dmy&#039;&lt;br /&gt;
	local date = Date(unpack(parms))&lt;br /&gt;
	if not date then&lt;br /&gt;
		if show == &#039;format&#039; then&lt;br /&gt;
			return &#039;error&#039;&lt;br /&gt;
		end&lt;br /&gt;
		return message(&#039;需要有效的日期&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local add = stripToNil(args.add)&lt;br /&gt;
	if add then&lt;br /&gt;
		for item in add:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
			date = date + item&lt;br /&gt;
			if not date then&lt;br /&gt;
				return message(&#039;無法添加“&#039; .. item .. &#039;”&#039;)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local prefix, result&lt;br /&gt;
	local sortable = translateParameters.sortable[args.sortable]&lt;br /&gt;
	if sortable then&lt;br /&gt;
		local value = (date.partial and date.partial.first or date).jdz&lt;br /&gt;
		prefix = makeSort(value, sortable)&lt;br /&gt;
	end&lt;br /&gt;
	if show ~= &#039;hide&#039; then&lt;br /&gt;
		result = date[show]&lt;br /&gt;
		if result == nil then&lt;br /&gt;
			result = date:text(show)&lt;br /&gt;
		elseif type(result) == &#039;boolean&#039; then&lt;br /&gt;
			result = result and &#039;1&#039; or &#039;0&#039;&lt;br /&gt;
		else&lt;br /&gt;
			result = tostring(result)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return (prefix or &#039;&#039;) .. (result or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rangeJoin(range)&lt;br /&gt;
	-- Return text to be used between a range of ages.&lt;br /&gt;
	return range == &#039;dash&#039; and &#039;–&#039; or &#039;或&#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeText(values, components, names, options, noUpper)&lt;br /&gt;
	-- Return wikitext representing an age or duration.&lt;br /&gt;
	local text = Collection.new()&lt;br /&gt;
	local count = #values&lt;br /&gt;
	local sep = names.sep or &#039;&#039;&lt;br /&gt;
	for i, v in ipairs(values) do&lt;br /&gt;
		-- v is a number (say 4 for 4 years), or a table ({4,5} for 4 or 5 years).&lt;br /&gt;
		local islist = type(v) == &#039;table&#039;&lt;br /&gt;
		if (islist or v &amp;gt; 0) or (text.n == 0 and i == count) or (text.n &amp;gt; 0 and components.keepZero) then&lt;br /&gt;
			local fmt, vstr&lt;br /&gt;
			if options.spell then&lt;br /&gt;
				fmt = function(number)&lt;br /&gt;
					return spellNumber(number, options.spell, noUpper or i)&lt;br /&gt;
				end&lt;br /&gt;
			elseif i == 1 and options.format == &#039;format_commas&#039; then&lt;br /&gt;
				-- Numbers after the first should be small and not need formatting.&lt;br /&gt;
				fmt = formatNumber&lt;br /&gt;
			else&lt;br /&gt;
				fmt = tostring&lt;br /&gt;
			end&lt;br /&gt;
			if islist then&lt;br /&gt;
				vstr = fmt(v[1]) .. rangeJoin(options.range)&lt;br /&gt;
				noUpper = true&lt;br /&gt;
				vstr = vstr .. fmt(v[2])&lt;br /&gt;
			else&lt;br /&gt;
				vstr = fmt(v)&lt;br /&gt;
			end&lt;br /&gt;
			local name = names[components[i]]&lt;br /&gt;
			if name then&lt;br /&gt;
				local plural = names.plural&lt;br /&gt;
				if not plural or (islist and v[2] or v) == 1 then&lt;br /&gt;
					plural = &#039;&#039;&lt;br /&gt;
				end&lt;br /&gt;
				text:add(vstr .. sep .. name .. plural)&lt;br /&gt;
			else&lt;br /&gt;
				text:add(vstr)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local first, last&lt;br /&gt;
	-- hh mm ss&lt;br /&gt;
	if options.join == &#039;sep_space&#039; then&lt;br /&gt;
		first = &#039; &#039;&lt;br /&gt;
		last = &#039; &#039;&lt;br /&gt;
	-- hh时，mm分，ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_comma&#039; then&lt;br /&gt;
		first = &#039;，&#039;&lt;br /&gt;
		last = &#039;，&#039;&lt;br /&gt;
	-- hh时，mm分又ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_serialcomma&#039; then&lt;br /&gt;
		first = &#039;，&#039;&lt;br /&gt;
		last = text.n &amp;gt; 2 and (names.y == &#039;年&#039; and &#039;又&#039; or &#039;零&#039;) or &#039;，&#039;&lt;br /&gt;
	-- hh时mm分ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_none&#039; then&lt;br /&gt;
		first = &#039;&#039;&lt;br /&gt;
		last = &#039;&#039;&lt;br /&gt;
	-- hh时mm分又ss秒&lt;br /&gt;
	else  -- &#039;sep_serial&#039;&lt;br /&gt;
		first = &#039;&#039;&lt;br /&gt;
		last = text.n &amp;gt; 2 and (names.y == &#039;年&#039; and &#039;又&#039; or &#039;零&#039;) or &#039;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	if yes(options.range, true) and options.join ~= &#039;sep_space&#039; and string.sub(last, 1, 1) ~= &#039;，&#039; then&lt;br /&gt;
		last = &#039;，&#039; .. last&lt;br /&gt;
	end&lt;br /&gt;
	for i, v in ipairs(text) do&lt;br /&gt;
		if i &amp;lt; text.n then&lt;br /&gt;
			text[i] = v .. (i + 1 &amp;lt; text.n and first or last)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local sign = &#039;&#039;&lt;br /&gt;
	if options.isnegative then&lt;br /&gt;
		-- Do not display negative zero.&lt;br /&gt;
		if text.n &amp;gt; 1 or (text.n == 1 and text[1]:sub(1, 1) ~= &#039;0&#039; ) then&lt;br /&gt;
			if options.format == &#039;format_raw&#039; then&lt;br /&gt;
				sign = &#039;-&#039;  -- plain hyphen so result can be used in a calculation&lt;br /&gt;
			else&lt;br /&gt;
				sign = &#039;−&#039;  -- Unicode U+2212 MINUS SIGN&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return&lt;br /&gt;
		(options.prefix or &#039;&#039;) ..&lt;br /&gt;
		(options.extra or &#039;&#039;) ..&lt;br /&gt;
		sign ..&lt;br /&gt;
		text:join() ..&lt;br /&gt;
		(options.suffix or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateDifference(parms)&lt;br /&gt;
	-- Return a formatted date difference using the given parameters&lt;br /&gt;
	-- which have been validated.&lt;br /&gt;
	local names = {&lt;br /&gt;
		abbr_off = {&lt;br /&gt;
			plural = &#039;&#039;,&lt;br /&gt;
			sep = &#039;&#039;,&lt;br /&gt;
			y = &#039;年&#039;,&lt;br /&gt;
			m = &#039;個月&#039;,&lt;br /&gt;
			w = &#039;週&#039;,&lt;br /&gt;
			d = &#039;天&#039;,&lt;br /&gt;
			H = &#039;小時&#039;,&lt;br /&gt;
			M = &#039;分&#039;,&lt;br /&gt;
			S = &#039;秒&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_on = {&lt;br /&gt;
			y = &#039;y&#039;,&lt;br /&gt;
			m = &#039;m&#039;,&lt;br /&gt;
			w = &#039;w&#039;,&lt;br /&gt;
			d = &#039;d&#039;,&lt;br /&gt;
			H = &#039;h&#039;,&lt;br /&gt;
			M = &#039;m&#039;,&lt;br /&gt;
			S = &#039;s&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_age = {&lt;br /&gt;
			plural = &#039;&#039;,&lt;br /&gt;
			sep = &#039;&#039;,&lt;br /&gt;
			y = &#039;歲&#039;,&lt;br /&gt;
			m = &#039;個月&#039;,&lt;br /&gt;
			w = &#039;週&#039;,&lt;br /&gt;
			d = &#039;天&#039;,&lt;br /&gt;
			H = &#039;小時&#039;,&lt;br /&gt;
			M = &#039;分&#039;,&lt;br /&gt;
			S = &#039;秒&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_raw = {},&lt;br /&gt;
	}&lt;br /&gt;
	local diff = parms.diff  -- must be a valid date difference&lt;br /&gt;
	local show = parms.show  -- may be nil; default is set below&lt;br /&gt;
	local abbr = parms.abbr or &#039;abbr_off&#039;&lt;br /&gt;
	local defaultJoin  -- 中文应该全为nil&lt;br /&gt;
	if abbr ~= &#039;abbr_off&#039; then&lt;br /&gt;
		defaultJoin = nil&lt;br /&gt;
	end&lt;br /&gt;
	if not show then&lt;br /&gt;
		show = &#039;ymd&#039;&lt;br /&gt;
		if parms.disp == &#039;disp_age&#039; then&lt;br /&gt;
			if diff.years &amp;lt; 3 then&lt;br /&gt;
				defaultJoin = nil&lt;br /&gt;
				if diff.years &amp;gt;= 1 then&lt;br /&gt;
					show = &#039;ym&#039;&lt;br /&gt;
				else&lt;br /&gt;
					show = &#039;md&#039;&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				show = &#039;y&#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if type(show) ~= &#039;table&#039; then&lt;br /&gt;
		show = translateParameters.show[show]&lt;br /&gt;
	end&lt;br /&gt;
	if parms.disp == &#039;disp_raw&#039; then&lt;br /&gt;
		defaultJoin = &#039;sep_space&#039;&lt;br /&gt;
		abbr = &#039;abbr_raw&#039;&lt;br /&gt;
	elseif parms.wantSc then&lt;br /&gt;
		defaultJoin = &#039;sep_serialcomma&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local diffOptions = {&lt;br /&gt;
		round = parms.round,&lt;br /&gt;
		duration = parms.wantDuration,&lt;br /&gt;
		range = parms.range and true or nil,&lt;br /&gt;
	}&lt;br /&gt;
	local prefix&lt;br /&gt;
	if parms.sortable then&lt;br /&gt;
		local value = diff.age_days + (parms.wantDuration and 1 or 0)  -- days and fraction of a day&lt;br /&gt;
		if diff.isnegative then&lt;br /&gt;
			value = -value&lt;br /&gt;
		end&lt;br /&gt;
		prefix = makeSort(value, parms.sortable)&lt;br /&gt;
	end&lt;br /&gt;
	local textOptions = {&lt;br /&gt;
		prefix = prefix,&lt;br /&gt;
		suffix = parms.suffix,  -- not currently used&lt;br /&gt;
		extra = parms.extra,&lt;br /&gt;
		format = parms.format,&lt;br /&gt;
		join = parms.sep or defaultJoin,&lt;br /&gt;
		isnegative = diff.isnegative,&lt;br /&gt;
		range = parms.range,&lt;br /&gt;
		spell = parms.spell,&lt;br /&gt;
	}&lt;br /&gt;
	if show.id == &#039;hide&#039; then&lt;br /&gt;
		return prefix or &#039;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local values = { diff:age(show.id, diffOptions) }&lt;br /&gt;
	if values[1] then&lt;br /&gt;
		return makeText(values, show, names[abbr], textOptions)&lt;br /&gt;
	end&lt;br /&gt;
	if diff.partial then&lt;br /&gt;
		-- Handle a more complex range such as&lt;br /&gt;
		-- {{age_yd|20 Dec 2001|2003|range=yes}} → 1 year, 12 days or 2 years, 11 days&lt;br /&gt;
		local opt = {&lt;br /&gt;
			format = textOptions.format,&lt;br /&gt;
			join = textOptions.join,&lt;br /&gt;
			isnegative = textOptions.isnegative,&lt;br /&gt;
			spell = textOptions.spell,&lt;br /&gt;
		}&lt;br /&gt;
		return&lt;br /&gt;
			(textOptions.prefix or &#039;&#039;) ..&lt;br /&gt;
			makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) ..&lt;br /&gt;
			rangeJoin(textOptions.range) ..&lt;br /&gt;
			makeText({ diff.partial.maxdiff:age(show.id, diffOptions) }, show, names[abbr], opt, true) ..&lt;br /&gt;
			(textOptions.suffix or &#039;&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;此處不支援參數show=&#039; .. show.id)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getDates(frame, getopt)&lt;br /&gt;
	-- Parse template parameters and return one of:&lt;br /&gt;
	-- * date         (a date table, if single)&lt;br /&gt;
	-- * date1, date2 (two date tables, if not single)&lt;br /&gt;
	-- * text         (a string error message)&lt;br /&gt;
	-- A missing date is optionally replaced with the current date.&lt;br /&gt;
	-- If wantMixture is true, a missing date component is replaced&lt;br /&gt;
	-- from the current date, so can get a bizarre mixture of&lt;br /&gt;
	-- specified/current y/m/d as has been done by some &amp;quot;age&amp;quot; templates.&lt;br /&gt;
	-- Some results may be placed in table getopt.&lt;br /&gt;
	local Date, currentDate = getExports(frame)&lt;br /&gt;
	getopt = getopt or {}&lt;br /&gt;
	local function flagCurrent(text)&lt;br /&gt;
		-- This allows the calling template to detect if the current date has been used,&lt;br /&gt;
		-- that is, whether both dates have been entered in a template expecting two.&lt;br /&gt;
		-- For example, an infobox may want the age when an event occurred, not the current age.&lt;br /&gt;
		-- Don&#039;t bother detecting if wantMixture is used because not needed and it is a poor option.&lt;br /&gt;
		if not text then&lt;br /&gt;
			text = &#039;currentdate&#039;&lt;br /&gt;
			if getopt.flag == &#039;usesCurrent&#039; then&lt;br /&gt;
				getopt.usesCurrent = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local fields = {}&lt;br /&gt;
	local isNamed = args.year or args.year1 or args.year2 or&lt;br /&gt;
		args.month or args.month1 or args.month2 or&lt;br /&gt;
		args.day or args.day1 or args.day2&lt;br /&gt;
	if isNamed then&lt;br /&gt;
		fields[1] = args.year1 or args.year&lt;br /&gt;
		fields[2] = args.month1 or args.month&lt;br /&gt;
		fields[3] = args.day1 or args.day&lt;br /&gt;
		fields[4] = args.year2&lt;br /&gt;
		fields[5] = args.month2&lt;br /&gt;
		fields[6] = args.day2&lt;br /&gt;
	else&lt;br /&gt;
		for i = 1, 6 do&lt;br /&gt;
			fields[i] = args[i]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local imax = 0&lt;br /&gt;
	for i = 1, 6 do&lt;br /&gt;
		fields[i] = stripToNil(fields[i])&lt;br /&gt;
		if fields[i] then&lt;br /&gt;
			imax = i&lt;br /&gt;
		end&lt;br /&gt;
		if getopt.omitZero and i % 3 ~= 1 then  -- omit zero months and days as unknown values but keep year 0 which is 1 BCE&lt;br /&gt;
			if tonumber(fields[i]) == 0 then&lt;br /&gt;
				fields[i] = nil&lt;br /&gt;
				getopt.partial = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local fix = getopt.fix and &#039;fix&#039; or &#039;&#039;&lt;br /&gt;
	local noDefault = imax == 0 and getopt.noMissing&lt;br /&gt;
	local partialText = getopt.partial and &#039;partial&#039; or &#039;&#039;&lt;br /&gt;
	local dates = {}&lt;br /&gt;
	if isNamed or imax &amp;gt;= 3 then&lt;br /&gt;
		local nrDates = getopt.single and 1 or 2&lt;br /&gt;
		if getopt.wantMixture then&lt;br /&gt;
			-- Cannot be partial since empty fields are set from current.&lt;br /&gt;
			local components = { &#039;year&#039;, &#039;month&#039;, &#039;day&#039; }&lt;br /&gt;
			for i = 1, nrDates * 3 do&lt;br /&gt;
				fields[i] = fields[i] or currentDate[components[i &amp;gt; 3 and i - 3 or i]]&lt;br /&gt;
			end&lt;br /&gt;
			for i = 1, nrDates do&lt;br /&gt;
				local index = i == 1 and 1 or 4&lt;br /&gt;
				dates[i] = Date(fields[index], fields[index+1], fields[index+2])&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			-- If partial dates are allowed, accept&lt;br /&gt;
			--     year only, or&lt;br /&gt;
			--     year and month only&lt;br /&gt;
			-- Do not accept year and day without a month because that makes no sense&lt;br /&gt;
			-- (and because, for example, Date(&#039;partial&#039;, 2001, nil, 12) sets day = nil, not 12).&lt;br /&gt;
			for i = 1, nrDates do&lt;br /&gt;
				local index = i == 1 and 1 or 4&lt;br /&gt;
				local y, m, d = fields[index], fields[index+1], fields[index+2]&lt;br /&gt;
				if (getopt.partial and y and (m or not d)) or (y and m and d) then&lt;br /&gt;
					dates[i] = Date(fix, partialText, y, m, d)&lt;br /&gt;
				elseif not y and not m and not d and not noDefault then&lt;br /&gt;
					dates[i] = Date(flagCurrent())&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	elseif not noDefault then&lt;br /&gt;
		getopt.textdates = true  -- have parsed each date from a single text field&lt;br /&gt;
		dates[1] = Date(fix, partialText, flagCurrent(fields[1]))&lt;br /&gt;
		if not getopt.single then&lt;br /&gt;
			dates[2] = Date(fix, partialText, flagCurrent(fields[2]))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not dates[1] then&lt;br /&gt;
		return message(&#039;需要有效的年月日&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if getopt.single then&lt;br /&gt;
		return dates[1]&lt;br /&gt;
	end&lt;br /&gt;
	if not dates[2] then&lt;br /&gt;
		return message(&#039;第二個日期應為年月日&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return dates[1], dates[2]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function ageGeneric(frame)&lt;br /&gt;
	-- Return the result required by the specified template.&lt;br /&gt;
	-- Can use sortable=x where x = on/table/off/debug in any supported template.&lt;br /&gt;
	-- Some templates default to sortable=on but can be overridden.&lt;br /&gt;
	local name = frame.args.template&lt;br /&gt;
	if not name then&lt;br /&gt;
		return message(&#039;有關模板需有“|template=x”參數，其中x是所需的操作&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local specs = {&lt;br /&gt;
		-- 重点！切勿随意更改！&lt;br /&gt;
		age_days = {                -- {{age in days}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_days_nts = {            -- {{age in days nts}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		duration_days = {           -- {{duration in days}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			duration = true,&lt;br /&gt;
		},&lt;br /&gt;
		duration_days_nts = {       -- {{duration in days nts}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			duration = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_full_years = {          -- {{age}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			flag = &#039;usesCurrent&#039;,&lt;br /&gt;
			omitZero = true,&lt;br /&gt;
			range = &#039;no&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_full_years_nts = {      -- {{age nts}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_in_years = {            -- {{age in years}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			negative = &#039;error&#039;,&lt;br /&gt;
			range = &#039;dash&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_in_years_nts = {        -- {{age in years nts}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			negative = &#039;error&#039;,&lt;br /&gt;
			range = &#039;dash&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_infant = {              -- {{age for infant}}&lt;br /&gt;
			-- Do not set show because special processing is done later.&lt;br /&gt;
			abbr = &#039;abbr_off&#039;,&lt;br /&gt;
			disp = &#039;disp_age&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_m = {                   -- {{age in months}}&lt;br /&gt;
			show = &#039;m&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_w = {                   -- {{age in weeks}}&lt;br /&gt;
			show = &#039;w&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_wd = {                  -- {{age in weeks and days}}&lt;br /&gt;
			show = &#039;wd&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_yd = {                  -- {{age in years and days}}&lt;br /&gt;
			show = &#039;yd&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_yd_nts = {              -- {{age in years and days nts}}&lt;br /&gt;
			show = &#039;yd&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_ym = {                  -- {{age in years and months}}&lt;br /&gt;
			show = &#039;ym&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
		},&lt;br /&gt;
		age_ymd = {                 -- {{age in years, months and days}}&lt;br /&gt;
			show = &#039;ymd&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_ymwd = {                -- {{age in years, months, weeks and days}}&lt;br /&gt;
			show = &#039;ymwd&#039;,&lt;br /&gt;
			wantMixture = true,&lt;br /&gt;
		},&lt;br /&gt;
	}&lt;br /&gt;
	local spec = specs[name]&lt;br /&gt;
	if not spec then&lt;br /&gt;
		return message(&#039;指定的模板名稱無效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if name == &#039;age_days&#039; then&lt;br /&gt;
		local su = stripToNil(args[&#039;show unit&#039;])&lt;br /&gt;
		if su then&lt;br /&gt;
			if su == &#039;abbr&#039; or su == &#039;full&#039; then&lt;br /&gt;
				spec.disp = nil&lt;br /&gt;
				spec.abbr = su == &#039;abbr&#039; and &#039;abbr_on&#039; or nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local partial, autofill&lt;br /&gt;
	local range = stripToNil(args.range) or spec.range&lt;br /&gt;
	if range then&lt;br /&gt;
		-- Suppose partial dates are used and age could be 11 or 12 years.&lt;br /&gt;
		-- &amp;quot;|range=&amp;quot; (empty value) has no effect (spec is used).&lt;br /&gt;
		-- &amp;quot;|range=yes&amp;quot; or spec.range == true sets range = true (gives &amp;quot;11 or 12&amp;quot;)&lt;br /&gt;
		-- &amp;quot;|range=dash&amp;quot; or spec.range == &#039;dash&#039; sets range = &#039;dash&#039; (gives &amp;quot;11–12&amp;quot;).&lt;br /&gt;
		-- &amp;quot;|range=no&amp;quot; or spec.range == &#039;no&#039; sets range = nil and fills each date in the diff (gives &amp;quot;12&amp;quot;).&lt;br /&gt;
		--     (&amp;quot;on&amp;quot; is equivalent to &amp;quot;yes&amp;quot;, and &amp;quot;off&amp;quot; is equivalent to &amp;quot;no&amp;quot;).&lt;br /&gt;
		-- &amp;quot;|range=OTHER&amp;quot; sets range = nil and rejects partial dates.&lt;br /&gt;
		range = ({ dash = &#039;dash&#039;, off = &#039;no&#039;, no = &#039;no&#039;, [true] = true })[range] or yes(range)&lt;br /&gt;
		if range then&lt;br /&gt;
			partial = true  -- accept partial dates with a possible age range for the result&lt;br /&gt;
			if range == &#039;no&#039; then&lt;br /&gt;
				autofill = true  -- missing month/day in first or second date are filled from other date or 1&lt;br /&gt;
				range = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local getopt = {&lt;br /&gt;
		fix = yes(args.fix),&lt;br /&gt;
		flag = stripToNil(args.flag) or spec.flag,&lt;br /&gt;
		omitZero = spec.omitZero,&lt;br /&gt;
		partial = partial,&lt;br /&gt;
		wantMixture = spec.wantMixture,&lt;br /&gt;
	}&lt;br /&gt;
	local date1, date2 = getDates(frame, getopt)&lt;br /&gt;
	if type(date1) == &#039;string&#039; then&lt;br /&gt;
		return date1&lt;br /&gt;
	end&lt;br /&gt;
	local useAge = spec.age&lt;br /&gt;
	if args.age ~= nil then&lt;br /&gt;
		useAge = yes(args.age, spec.age)&lt;br /&gt;
	end&lt;br /&gt;
	local format = stripToNil(args.format)&lt;br /&gt;
	local spell = spellOptions[format]&lt;br /&gt;
	if format then&lt;br /&gt;
		format = &#039;format_&#039; .. format&lt;br /&gt;
	elseif name == &#039;age_days&#039; and getopt.textdates then&lt;br /&gt;
		format = &#039;format_commas&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local parms = {&lt;br /&gt;
		diff = date2:subtract(date1, { fill = autofill }),&lt;br /&gt;
		wantDuration = spec.duration or yes(args.duration),&lt;br /&gt;
		range = range,&lt;br /&gt;
		wantSc = yes(args.sc),&lt;br /&gt;
		show = args.show == &#039;hide&#039; and &#039;hide&#039; or spec.show,&lt;br /&gt;
		abbr = useAge and &#039;abbr_age&#039; or spec.abbr,&lt;br /&gt;
		disp = spec.disp,&lt;br /&gt;
		extra = (getopt.usesCurrent and format ~= &#039;format_raw&#039;) and &#039;&amp;lt;span class=&amp;quot;currentage&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&#039; or nil,&lt;br /&gt;
		format = format or spec.format,&lt;br /&gt;
		round = yes(args.round),&lt;br /&gt;
		sep = spec.sep,&lt;br /&gt;
		sortable = translateParameters.sortable[args.sortable or spec.sortable],&lt;br /&gt;
		spell = spell,&lt;br /&gt;
	}&lt;br /&gt;
	if (spec.negative or frame.args.negative) == &#039;error&#039; and parms.diff.isnegative then&lt;br /&gt;
		return message(&#039;第二個日期不應在第一個日期之前&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return dateDifference(parms)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function bda(frame)&lt;br /&gt;
	-- Implement [[Template:Birth date and age]].&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local options = { noMissing=true, single=true }&lt;br /&gt;
	local date = getDates(frame, options)&lt;br /&gt;
	if type(date) == &#039;string&#039; then&lt;br /&gt;
		return date  -- error text&lt;br /&gt;
	end&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local diff = Date(&#039;currentdate&#039;) - date&lt;br /&gt;
	if diff.isnegative or diff.years &amp;gt; 150 then&lt;br /&gt;
		return message(&#039;計算年齡所需的出生日期無效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local disp, show = &#039;disp_raw&#039;, &#039;y&#039;&lt;br /&gt;
	if diff.years &amp;lt; 2 then&lt;br /&gt;
		disp = &#039;disp_age&#039;&lt;br /&gt;
		if diff.years == 0 and diff.months == 0 then&lt;br /&gt;
			show = &#039;d&#039;&lt;br /&gt;
		else&lt;br /&gt;
			show = &#039;m&#039;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local result = &#039;%-Y年%B月%-d日&#039;&lt;br /&gt;
	result = &#039;（&amp;lt;span class=&amp;quot;bday&amp;quot;&amp;gt;%-Y-%m-%d&amp;lt;/span&amp;gt;) &amp;lt;/span&amp;gt;&#039; .. result&lt;br /&gt;
	result = &#039;&amp;lt;span style=&amp;quot;display:none&amp;quot;&amp;gt; &#039; ..&lt;br /&gt;
		date:text(result) ..&lt;br /&gt;
		&#039;&amp;lt;span class=&amp;quot;noprint ForceAgeToShow&amp;quot;&amp;gt; &#039; ..&lt;br /&gt;
		&#039;（&#039; ..&lt;br /&gt;
		dateDifference({&lt;br /&gt;
			diff = diff,&lt;br /&gt;
			show = show,&lt;br /&gt;
			abbr = &#039;abbr_off&#039;,&lt;br /&gt;
			disp = disp,&lt;br /&gt;
			sep = &#039;sep_space&#039;,&lt;br /&gt;
		}) ..&lt;br /&gt;
		&#039;）&amp;lt;/span&amp;gt;&#039;&lt;br /&gt;
	local warnings = tonumber(frame.args.warnings)&lt;br /&gt;
	if warnings and warnings &amp;gt; 0 then&lt;br /&gt;
		local good = {&lt;br /&gt;
			df = true,&lt;br /&gt;
			mf = true,&lt;br /&gt;
			day = true,&lt;br /&gt;
			day1 = true,&lt;br /&gt;
			month = true,&lt;br /&gt;
			month1 = true,&lt;br /&gt;
			year = true,&lt;br /&gt;
			year1 = true,&lt;br /&gt;
		}&lt;br /&gt;
		local invalid&lt;br /&gt;
		local imax = options.textdates and 1 or 3&lt;br /&gt;
		for k, _ in pairs(args) do&lt;br /&gt;
			if type(k) == &#039;number&#039; then&lt;br /&gt;
				if k &amp;gt; imax then&lt;br /&gt;
					invalid = tostring(k)&lt;br /&gt;
					break&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				if not good[k] then&lt;br /&gt;
					invalid = k&lt;br /&gt;
					break&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if invalid then&lt;br /&gt;
			result = result .. message(invalid .. &#039;參數無效&#039;, &#039;warning&#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateToGsd(frame)&lt;br /&gt;
	-- Implement [[Template:Gregorian serial date]].&lt;br /&gt;
	-- Return Gregorian serial date of the given date, or the current date.&lt;br /&gt;
	-- The returned value is negative for dates before 1 January 1 AD&lt;br /&gt;
	-- despite the fact that GSD is not defined for such dates.&lt;br /&gt;
	local date = getDates(frame, { wantMixture=true, single=true })&lt;br /&gt;
	if type(date) == &#039;string&#039; then&lt;br /&gt;
		return date&lt;br /&gt;
	end&lt;br /&gt;
	return tostring(date.gsd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function jdToDate(frame)&lt;br /&gt;
	-- Return formatted date from a Julian date.&lt;br /&gt;
	-- The result includes a time if the input includes a fraction.&lt;br /&gt;
	-- The word &#039;Julian&#039; is accepted for the Julian calendar.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local date = Date(&#039;juliandate&#039;, args[1], args[2])&lt;br /&gt;
	if date then&lt;br /&gt;
		return date:text()&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;需要有效的儒略曆日期&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateToJd(frame)&lt;br /&gt;
	-- Return Julian date (a number) from a date which may include a time,&lt;br /&gt;
	-- or the current date (&#039;currentdate&#039;) or current date and time (&#039;currentdatetime&#039;).&lt;br /&gt;
	-- The word &#039;Julian&#039; is accepted for the Julian calendar.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local date = Date(args[1], args[2], args[3], args[4], args[5], args[6], args[7])&lt;br /&gt;
	if date then&lt;br /&gt;
		return tostring(date.jd)&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;需要有效的年/月/日或“currentdate”（當前日期）&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function timeInterval(frame)&lt;br /&gt;
	-- Implement [[Template:Time interval]].&lt;br /&gt;
	-- There are two positional arguments: date1, date2.&lt;br /&gt;
	-- The default for each is the current date and time.&lt;br /&gt;
	-- Result is date2 - date1 formatted.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local parms = {&lt;br /&gt;
		wantDuration = yes(args.duration),&lt;br /&gt;
		range = yes(args.range) or (args.range == &#039;dash&#039; and &#039;dash&#039; or nil),&lt;br /&gt;
		wantSc = yes(args.sc),&lt;br /&gt;
	}&lt;br /&gt;
	local fix = yes(args.fix) and &#039;fix&#039; or &#039;&#039;&lt;br /&gt;
	local date1 = Date(fix, &#039;partial&#039;, stripToNil(args[1]) or &#039;currentdatetime&#039;)&lt;br /&gt;
	if not date1 then&lt;br /&gt;
		return message(&#039;開始日期無效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local date2 = Date(fix, &#039;partial&#039;, stripToNil(args[2]) or &#039;currentdatetime&#039;)&lt;br /&gt;
	if not date2 then&lt;br /&gt;
		return message(&#039;結束日期無效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	parms.diff = date2 - date1&lt;br /&gt;
	for argname, translate in pairs(translateParameters) do&lt;br /&gt;
		local parm = stripToNil(args[argname])&lt;br /&gt;
		if parm then&lt;br /&gt;
			parm = translate[parm]&lt;br /&gt;
			if parm == nil then  -- test for nil because false is a valid setting&lt;br /&gt;
				return message(&#039;參數&#039; .. argname .. &#039;=&#039; .. args[argname] .. &#039;無效&#039;)&lt;br /&gt;
			end&lt;br /&gt;
			parms[argname] = parm&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if parms.round then&lt;br /&gt;
		local round = parms.round&lt;br /&gt;
		local show = parms.show&lt;br /&gt;
		if round ~= &#039;on&#039; then&lt;br /&gt;
			if show then&lt;br /&gt;
				if show.id ~= round then&lt;br /&gt;
					return message(&#039;參數show=&#039; .. args.show .. &#039;與round=&#039; .. args.round .. &#039;互有衝突&#039;)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				parms.show = translateParameters.show[round]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		parms.round = true&lt;br /&gt;
	end&lt;br /&gt;
	return dateDifference(parms)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	age_generic = ageGeneric,           -- can emulate several age templates&lt;br /&gt;
	birth_date_and_age = bda,           -- Template:Birth_date_and_age&lt;br /&gt;
	gsd = dateToGsd,                    -- Template:Gregorian_serial_date&lt;br /&gt;
	extract = dateExtract,              -- Template:Extract&lt;br /&gt;
	jd_to_date = jdToDate,              -- Template:?&lt;br /&gt;
	JULIANDAY = dateToJd,               -- Template:JULIANDAY&lt;br /&gt;
	time_interval = timeInterval,       -- Template:Time_interval&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Date&amp;diff=1334</id>
		<title>模組:Date</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Date&amp;diff=1334"/>
		<updated>2026-10-04T15:59:44Z</updated>

		<summary type="html">&lt;p&gt;DC：​建立內容為「-- Date functions for use by other modules. -- I18N and time zones are not supported.  local MINUS = &amp;#039;−&amp;#039;  -- Unicode U+2212 MINUS SIGN local floor = math.floor  local Date, DateDiff, diffmt  -- forward declarations local uniq = { &amp;#039;unique identifier&amp;#039; }  local function is_date(t) 	-- The system used to make a date read-only means there is no unique 	-- metatable that is conveniently accessible to check. 	return type(t) == &amp;#039;table&amp;#039; and t._id == uniq end  local…」的新頁面&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;-- Date functions for use by other modules.&lt;br /&gt;
-- I18N and time zones are not supported.&lt;br /&gt;
&lt;br /&gt;
local MINUS = &#039;−&#039;  -- Unicode U+2212 MINUS SIGN&lt;br /&gt;
local floor = math.floor&lt;br /&gt;
&lt;br /&gt;
local Date, DateDiff, diffmt  -- forward declarations&lt;br /&gt;
local uniq = { &#039;unique identifier&#039; }&lt;br /&gt;
&lt;br /&gt;
local function is_date(t)&lt;br /&gt;
	-- The system used to make a date read-only means there is no unique&lt;br /&gt;
	-- metatable that is conveniently accessible to check.&lt;br /&gt;
	return type(t) == &#039;table&#039; and t._id == uniq&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_diff(t)&lt;br /&gt;
	return type(t) == &#039;table&#039; and getmetatable(t) == diffmt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _list_join(list, sep)&lt;br /&gt;
	return table.concat(list, sep)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function collection()&lt;br /&gt;
	-- Return a table to hold items.&lt;br /&gt;
	return {&lt;br /&gt;
		n = 0,&lt;br /&gt;
		add = function (self, item)&lt;br /&gt;
			self.n = self.n + 1&lt;br /&gt;
			self[self.n] = item&lt;br /&gt;
		end,&lt;br /&gt;
		join = _list_join,&lt;br /&gt;
	}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function strip_to_nil(text)&lt;br /&gt;
	-- If text is a string, return its trimmed content, or nil if empty.&lt;br /&gt;
	-- Otherwise return text (convenient when Date fields are provided from&lt;br /&gt;
	-- another module which may pass a string, a number, or another type).&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		text = text:match(&#039;(%S.-)%s*$&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_leap_year(year, calname)&lt;br /&gt;
	-- Return true if year is a leap year.&lt;br /&gt;
	if calname == &#039;Julian&#039; then&lt;br /&gt;
		return year % 4 == 0&lt;br /&gt;
	end&lt;br /&gt;
	return (year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function days_in_month(year, month, calname)&lt;br /&gt;
	-- Return number of days (1..31) in given month (1..12).&lt;br /&gt;
	if month == 2 and is_leap_year(year, calname) then&lt;br /&gt;
		return 29&lt;br /&gt;
	end&lt;br /&gt;
	return ({ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 })[month]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function h_m_s(time)&lt;br /&gt;
	-- Return hour, minute, second extracted from fraction of a day.&lt;br /&gt;
	time = floor(time * 24 * 3600 + 0.5)  -- number of seconds&lt;br /&gt;
	local second = time % 60&lt;br /&gt;
	time = floor(time / 60)&lt;br /&gt;
	return floor(time / 60), time % 60, second&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hms(date)&lt;br /&gt;
	-- Return fraction of a day from date&#039;s time, where (0 &amp;lt;= fraction &amp;lt; 1)&lt;br /&gt;
	-- if the values are valid, but could be anything if outside range.&lt;br /&gt;
	return (date.hour + (date.minute + date.second / 60) / 60) / 24&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function julian_date(date)&lt;br /&gt;
	-- Return jd, jdz from a Julian or Gregorian calendar date where&lt;br /&gt;
	--   jd = Julian date and its fractional part is zero at noon&lt;br /&gt;
	--   jdz = same, but assume time is 00:00:00 if no time given&lt;br /&gt;
	-- http://www.tondering.dk/claus/cal/julperiod.php#formula&lt;br /&gt;
	-- Testing shows this works for all dates from year -9999 to 9999!&lt;br /&gt;
	-- JDN 0 is the 24-hour period starting at noon UTC on Monday&lt;br /&gt;
	--    1 January 4713 BC  = (-4712, 1, 1)   Julian calendar&lt;br /&gt;
	--   24 November 4714 BC = (-4713, 11, 24) Gregorian calendar&lt;br /&gt;
	local offset&lt;br /&gt;
	local a = floor((14 - date.month)/12)&lt;br /&gt;
	local y = date.year + 4800 - a&lt;br /&gt;
	if date.calendar == &#039;Julian&#039; then&lt;br /&gt;
		offset = floor(y/4) - 32083&lt;br /&gt;
	else&lt;br /&gt;
		offset = floor(y/4) - floor(y/100) + floor(y/400) - 32045&lt;br /&gt;
	end&lt;br /&gt;
	local m = date.month + 12*a - 3&lt;br /&gt;
	local jd = date.day + floor((153*m + 2)/5) + 365*y + offset&lt;br /&gt;
	if date.hastime then&lt;br /&gt;
		jd = jd + hms(date) - 0.5&lt;br /&gt;
		return jd, jd&lt;br /&gt;
	end&lt;br /&gt;
	return jd, jd - 0.5&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function set_date_from_jd(date)&lt;br /&gt;
	-- Set the fields of table date from its Julian date field.&lt;br /&gt;
	-- Return true if date is valid.&lt;br /&gt;
	-- http://www.tondering.dk/claus/cal/julperiod.php#formula&lt;br /&gt;
	-- This handles the proleptic Julian and Gregorian calendars.&lt;br /&gt;
	-- Negative Julian dates are not defined but they work.&lt;br /&gt;
	local calname = date.calendar&lt;br /&gt;
	local low, high  -- min/max limits for date ranges −9999-01-01 to 9999-12-31&lt;br /&gt;
	if calname == &#039;Gregorian&#039; then&lt;br /&gt;
		low, high = -1930999.5, 5373484.49999&lt;br /&gt;
	elseif calname == &#039;Julian&#039; then&lt;br /&gt;
		low, high = -1931076.5, 5373557.49999&lt;br /&gt;
	else&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local jd = date.jd&lt;br /&gt;
	if not (type(jd) == &#039;number&#039; and low &amp;lt;= jd and jd &amp;lt;= high) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local jdn = floor(jd)&lt;br /&gt;
	if date.hastime then&lt;br /&gt;
		local time = jd - jdn  -- 0 &amp;lt;= time &amp;lt; 1&lt;br /&gt;
		if time &amp;gt;= 0.5 then    -- if at or after midnight of next day&lt;br /&gt;
			jdn = jdn + 1&lt;br /&gt;
			time = time - 0.5&lt;br /&gt;
		else&lt;br /&gt;
			time = time + 0.5&lt;br /&gt;
		end&lt;br /&gt;
		date.hour, date.minute, date.second = h_m_s(time)&lt;br /&gt;
	else&lt;br /&gt;
		date.second = 0&lt;br /&gt;
		date.minute = 0&lt;br /&gt;
		date.hour = 0&lt;br /&gt;
	end&lt;br /&gt;
	local b, c&lt;br /&gt;
	if calname == &#039;Julian&#039; then&lt;br /&gt;
		b = 0&lt;br /&gt;
		c = jdn + 32082&lt;br /&gt;
	else  -- Gregorian&lt;br /&gt;
		local a = jdn + 32044&lt;br /&gt;
		b = floor((4*a + 3)/146097)&lt;br /&gt;
		c = a - floor(146097*b/4)&lt;br /&gt;
	end&lt;br /&gt;
	local d = floor((4*c + 3)/1461)&lt;br /&gt;
	local e = c - floor(1461*d/4)&lt;br /&gt;
	local m = floor((5*e + 2)/153)&lt;br /&gt;
	date.day = e - floor((153*m + 2)/5) + 1&lt;br /&gt;
	date.month = m + 3 - 12*floor(m/10)&lt;br /&gt;
	date.year = 100*b + d - 4800 + floor(m/10)&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function fix_numbers(numbers, y, m, d, H, M, S, partial, hastime, calendar)&lt;br /&gt;
	-- Put the result of normalizing the given values in table numbers.&lt;br /&gt;
	-- The result will have valid m, d values if y is valid; caller checks y.&lt;br /&gt;
	-- The logic of PHP mktime is followed where m or d can be zero to mean&lt;br /&gt;
	-- the previous unit, and -1 is the one before that, etc.&lt;br /&gt;
	-- Positive values carry forward.&lt;br /&gt;
	local date&lt;br /&gt;
	if not (1 &amp;lt;= m and m &amp;lt;= 12) then&lt;br /&gt;
		date = Date(y, 1, 1)&lt;br /&gt;
		if not date then return end&lt;br /&gt;
		date = date + ((m - 1) .. &#039;m&#039;)&lt;br /&gt;
		y, m = date.year, date.month&lt;br /&gt;
	end&lt;br /&gt;
	local days_hms&lt;br /&gt;
	if not partial then&lt;br /&gt;
		if hastime and H and M and S then&lt;br /&gt;
			if not (0 &amp;lt;= H and H &amp;lt;= 23 and&lt;br /&gt;
					0 &amp;lt;= M and M &amp;lt;= 59 and&lt;br /&gt;
					0 &amp;lt;= S and S &amp;lt;= 59) then&lt;br /&gt;
				days_hms = hms({ hour = H, minute = M, second = S })&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if days_hms or not (1 &amp;lt;= d and d &amp;lt;= days_in_month(y, m, calendar)) then&lt;br /&gt;
			date = date or Date(y, m, 1)&lt;br /&gt;
			if not date then return end&lt;br /&gt;
			date = date + (d - 1 + (days_hms or 0))&lt;br /&gt;
			y, m, d = date.year, date.month, date.day&lt;br /&gt;
			if days_hms then&lt;br /&gt;
				H, M, S = date.hour, date.minute, date.second&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	numbers.year = y&lt;br /&gt;
	numbers.month = m&lt;br /&gt;
	numbers.day = d&lt;br /&gt;
	if days_hms then&lt;br /&gt;
		-- Don&#039;t set H unless it was valid because a valid H will set hastime.&lt;br /&gt;
		numbers.hour = H&lt;br /&gt;
		numbers.minute = M&lt;br /&gt;
		numbers.second = S&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function set_date_from_numbers(date, numbers, options)&lt;br /&gt;
	-- Set the fields of table date from numeric values.&lt;br /&gt;
	-- Return true if date is valid.&lt;br /&gt;
	if type(numbers) ~= &#039;table&#039; then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local y = numbers.year   or date.year&lt;br /&gt;
	local m = numbers.month  or date.month&lt;br /&gt;
	local d = numbers.day    or date.day&lt;br /&gt;
	local H = numbers.hour&lt;br /&gt;
	local M = numbers.minute or date.minute or 0&lt;br /&gt;
	local S = numbers.second or date.second or 0&lt;br /&gt;
	local need_fix&lt;br /&gt;
	if y and m and d then&lt;br /&gt;
		date.partial = nil&lt;br /&gt;
		if not (-9999 &amp;lt;= y and y &amp;lt;= 9999 and&lt;br /&gt;
			1 &amp;lt;= m and m &amp;lt;= 12 and&lt;br /&gt;
			1 &amp;lt;= d and d &amp;lt;= days_in_month(y, m, date.calendar)) then&lt;br /&gt;
				if not date.want_fix then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				need_fix = true&lt;br /&gt;
		end&lt;br /&gt;
	elseif y and date.partial then&lt;br /&gt;
		if d or not (-9999 &amp;lt;= y and y &amp;lt;= 9999) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
		if m and not (1 &amp;lt;= m and m &amp;lt;= 12) then&lt;br /&gt;
			if not date.want_fix then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			need_fix = true&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		H = nil  -- ignore any time&lt;br /&gt;
		M = nil&lt;br /&gt;
		S = nil&lt;br /&gt;
	else&lt;br /&gt;
		if H then&lt;br /&gt;
			-- It is not possible to set M or S without also setting H.&lt;br /&gt;
			date.hastime = true&lt;br /&gt;
		else&lt;br /&gt;
			H = 0&lt;br /&gt;
		end&lt;br /&gt;
		if not (0 &amp;lt;= H and H &amp;lt;= 23 and&lt;br /&gt;
				0 &amp;lt;= M and M &amp;lt;= 59 and&lt;br /&gt;
				0 &amp;lt;= S and S &amp;lt;= 59) then&lt;br /&gt;
			if date.want_fix then&lt;br /&gt;
				need_fix = true&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	date.want_fix = nil&lt;br /&gt;
	if need_fix then&lt;br /&gt;
		fix_numbers(numbers, y, m, d, H, M, S, date.partial, date.hastime, date.calendar)&lt;br /&gt;
		return set_date_from_numbers(date, numbers, options)&lt;br /&gt;
	end&lt;br /&gt;
	date.year = y    -- -9999 to 9999 (&#039;n BC&#039; → year = 1 - n)&lt;br /&gt;
	date.month = m   -- 1 to 12 (may be nil if partial)&lt;br /&gt;
	date.day = d     -- 1 to 31 (* = nil if partial)&lt;br /&gt;
	date.hour = H    -- 0 to 59 (*)&lt;br /&gt;
	date.minute = M  -- 0 to 59 (*)&lt;br /&gt;
	date.second = S  -- 0 to 59 (*)&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		for _, k in ipairs({ &#039;am&#039;, &#039;era&#039;, &#039;format&#039; }) do&lt;br /&gt;
			if options[k] then&lt;br /&gt;
				date.options[k] = options[k]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function make_option_table(options1, options2)&lt;br /&gt;
	-- If options1 is a string, return a table with its settings, or&lt;br /&gt;
	-- if it is a table, use its settings.&lt;br /&gt;
	-- Missing options are set from table options2 or defaults.&lt;br /&gt;
	-- If a default is used, a flag is set so caller knows the value was not intentionally set.&lt;br /&gt;
	-- Valid option settings are:&lt;br /&gt;
	-- am: &#039;am&#039;, &#039;a.m.&#039;, &#039;AM&#039;, &#039;A.M.&#039;&lt;br /&gt;
	--     &#039;pm&#039;, &#039;p.m.&#039;, &#039;PM&#039;, &#039;P.M.&#039; (each has same meaning as corresponding item above)&lt;br /&gt;
	-- era: &#039;BCMINUS&#039;, &#039;BCNEGATIVE&#039;, &#039;BC&#039;, &#039;B.C.&#039;, &#039;BCE&#039;, &#039;B.C.E.&#039;, &#039;AD&#039;, &#039;A.D.&#039;, &#039;CE&#039;, &#039;C.E.&#039;&lt;br /&gt;
	-- Option am = &#039;am&#039; does not mean the hour is AM; it means &#039;am&#039; or &#039;pm&#039; is used, depending on the hour,&lt;br /&gt;
	--    and am = &#039;pm&#039; has the same meaning.&lt;br /&gt;
	-- Similarly, era = &#039;BC&#039; means &#039;BC&#039; is used if year &amp;lt;= 0.&lt;br /&gt;
	-- BCMINUS displays a MINUS if year &amp;lt; 0 and the display format does not include %{era}.&lt;br /&gt;
	-- BCNEGATIVE is similar but displays a hyphen.&lt;br /&gt;
	local result = { bydefault = {} }&lt;br /&gt;
	if type(options1) == &#039;table&#039; then&lt;br /&gt;
		result.am = options1.am&lt;br /&gt;
		result.era = options1.era&lt;br /&gt;
	elseif type(options1) == &#039;string&#039; then&lt;br /&gt;
		-- Example: &#039;am:AM era:BC&#039; or &#039;am=AM era=BC&#039;.&lt;br /&gt;
		for item in options1:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
			local lhs, rhs = item:match(&#039;^(%w+)[:=](.+)$&#039;)&lt;br /&gt;
			if lhs then&lt;br /&gt;
				result[lhs] = rhs&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	options2 = type(options2) == &#039;table&#039; and options2 or {}&lt;br /&gt;
	local defaults = { am = &#039;am&#039;, era = &#039;BC&#039; }&lt;br /&gt;
	for k, v in pairs(defaults) do&lt;br /&gt;
		if not result[k] then&lt;br /&gt;
			if options2[k] then&lt;br /&gt;
				result[k] = options2[k]&lt;br /&gt;
			else&lt;br /&gt;
				result[k] = v&lt;br /&gt;
				result.bydefault[k] = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local ampm_options = {&lt;br /&gt;
	-- lhs = input text accepted as an am/pm option&lt;br /&gt;
	-- rhs = code used internally&lt;br /&gt;
	[&#039;am&#039;]   = &#039;am&#039;,&lt;br /&gt;
	[&#039;AM&#039;]   = &#039;AM&#039;,&lt;br /&gt;
	[&#039;a.m.&#039;] = &#039;a.m.&#039;,&lt;br /&gt;
	[&#039;A.M.&#039;] = &#039;A.M.&#039;,&lt;br /&gt;
	[&#039;pm&#039;]   = &#039;am&#039;,  -- same as am&lt;br /&gt;
	[&#039;PM&#039;]   = &#039;AM&#039;,&lt;br /&gt;
	[&#039;p.m.&#039;] = &#039;a.m.&#039;,&lt;br /&gt;
	[&#039;P.M.&#039;] = &#039;A.M.&#039;,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local era_text = {&lt;br /&gt;
	-- Text for displaying an era with a positive year (after adjusting&lt;br /&gt;
	-- by replacing year with 1 - year if date.year &amp;lt;= 0).&lt;br /&gt;
	-- options.era = { year&amp;lt;=0 , year&amp;gt;0 }&lt;br /&gt;
	[&#039;BCMINUS&#039;]    = { &#039;BC&#039;    , &#039;&#039;    , isbc = true, sign = MINUS },&lt;br /&gt;
	[&#039;BCNEGATIVE&#039;] = { &#039;BC&#039;    , &#039;&#039;    , isbc = true, sign = &#039;-&#039;   },&lt;br /&gt;
	[&#039;BC&#039;]         = { &#039;BC&#039;    , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;B.C.&#039;]       = { &#039;B.C.&#039;  , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;BCE&#039;]        = { &#039;BCE&#039;   , &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;B.C.E.&#039;]     = { &#039;B.C.E.&#039;, &#039;&#039;    , isbc = true },&lt;br /&gt;
	[&#039;AD&#039;]         = { &#039;BC&#039;    , &#039;AD&#039;   },&lt;br /&gt;
	[&#039;A.D.&#039;]       = { &#039;B.C.&#039;  , &#039;A.D.&#039; },&lt;br /&gt;
	[&#039;CE&#039;]         = { &#039;BCE&#039;   , &#039;CE&#039;   },&lt;br /&gt;
	[&#039;C.E.&#039;]       = { &#039;B.C.E.&#039;, &#039;C.E.&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function get_era_for_year(era, year)&lt;br /&gt;
	return (era_text[era] or era_text[&#039;BC&#039;])[year &amp;gt; 0 and 2 or 1] or &#039;&#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function strftime(date, format, options)&lt;br /&gt;
	-- Return date formatted as a string using codes similar to those&lt;br /&gt;
	-- in the C strftime library function.&lt;br /&gt;
	local sformat = string.format&lt;br /&gt;
	local shortcuts = {&lt;br /&gt;
		[&#039;%c&#039;] = &#039;%-I:%M %p %-d %B %-Y %{era}&#039;,  -- date and time: 2:30 pm 1 April 2016&lt;br /&gt;
		[&#039;%x&#039;] = &#039;%-d %B %-Y %{era}&#039;,            -- date:          1 April 2016&lt;br /&gt;
		[&#039;%X&#039;] = &#039;%-I:%M %p&#039;,                    -- time:          2:30 pm&lt;br /&gt;
	}&lt;br /&gt;
	if shortcuts[format] then&lt;br /&gt;
		format = shortcuts[format]&lt;br /&gt;
	end&lt;br /&gt;
	local codes = {&lt;br /&gt;
		a = { field = &#039;dayabbr&#039; },&lt;br /&gt;
		A = { field = &#039;dayname&#039; },&lt;br /&gt;
		b = { field = &#039;monthabbr&#039; },&lt;br /&gt;
		B = { field = &#039;monthname&#039; },&lt;br /&gt;
		u = { fmt = &#039;%d&#039;  , field = &#039;dowiso&#039; },&lt;br /&gt;
		w = { fmt = &#039;%d&#039;  , field = &#039;dow&#039; },&lt;br /&gt;
		d = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;day&#039; },&lt;br /&gt;
		m = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;month&#039; },&lt;br /&gt;
		Y = { fmt = &#039;%04d&#039;, fmt2 = &#039;%d&#039;, field = &#039;year&#039; },&lt;br /&gt;
		H = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;hour&#039; },&lt;br /&gt;
		M = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;minute&#039; },&lt;br /&gt;
		S = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;second&#039; },&lt;br /&gt;
		j = { fmt = &#039;%03d&#039;, fmt2 = &#039;%d&#039;, field = &#039;dayofyear&#039; },&lt;br /&gt;
		I = { fmt = &#039;%02d&#039;, fmt2 = &#039;%d&#039;, field = &#039;hour&#039;, special = &#039;hour12&#039; },&lt;br /&gt;
		p = { field = &#039;hour&#039;, special = &#039;am&#039; },&lt;br /&gt;
	}&lt;br /&gt;
	options = make_option_table(options, date.options)&lt;br /&gt;
	local amopt = options.am&lt;br /&gt;
	local eraopt = options.era&lt;br /&gt;
	local function replace_code(spaces, modifier, id)&lt;br /&gt;
		local code = codes[id]&lt;br /&gt;
		if code then&lt;br /&gt;
			local fmt = code.fmt&lt;br /&gt;
			if modifier == &#039;-&#039; and code.fmt2 then&lt;br /&gt;
				fmt = code.fmt2&lt;br /&gt;
			end&lt;br /&gt;
			local value = date[code.field]&lt;br /&gt;
			if not value then&lt;br /&gt;
				return nil  -- an undefined field in a partial date&lt;br /&gt;
			end&lt;br /&gt;
			local special = code.special&lt;br /&gt;
			if special then&lt;br /&gt;
				if special == &#039;hour12&#039; then&lt;br /&gt;
					value = value % 12&lt;br /&gt;
					value = value == 0 and 12 or value&lt;br /&gt;
				elseif special == &#039;am&#039; then&lt;br /&gt;
					local ap = ({&lt;br /&gt;
						[&#039;a.m.&#039;] = { &#039;a.m.&#039;, &#039;p.m.&#039; },&lt;br /&gt;
						[&#039;AM&#039;] = { &#039;AM&#039;, &#039;PM&#039; },&lt;br /&gt;
						[&#039;A.M.&#039;] = { &#039;A.M.&#039;, &#039;P.M.&#039; },&lt;br /&gt;
					})[ampm_options[amopt]] or { &#039;am&#039;, &#039;pm&#039; }&lt;br /&gt;
					return (spaces == &#039;&#039; and &#039;&#039; or &#039;&amp;amp;nbsp;&#039;) .. (value &amp;lt; 12 and ap[1] or ap[2])&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			if code.field == &#039;year&#039; then&lt;br /&gt;
				local sign = (era_text[eraopt] or {}).sign&lt;br /&gt;
				if not sign or format:find(&#039;%{era}&#039;, 1, true) then&lt;br /&gt;
					sign = &#039;&#039;&lt;br /&gt;
					if value &amp;lt;= 0 then&lt;br /&gt;
						value = 1 - value&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					if value &amp;gt;= 0 then&lt;br /&gt;
						sign = &#039;&#039;&lt;br /&gt;
					else&lt;br /&gt;
						value = -value&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				return spaces .. sign .. sformat(fmt, value)&lt;br /&gt;
			end&lt;br /&gt;
			return spaces .. (fmt and sformat(fmt, value) or value)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function replace_property(spaces, id)&lt;br /&gt;
		if id == &#039;era&#039; then&lt;br /&gt;
			-- Special case so can use local era option.&lt;br /&gt;
			local result = get_era_for_year(eraopt, date.year)&lt;br /&gt;
			if result == &#039;&#039; then&lt;br /&gt;
				return &#039;&#039;&lt;br /&gt;
			end&lt;br /&gt;
			return (spaces == &#039;&#039; and &#039;&#039; or &#039;&amp;amp;nbsp;&#039;) .. result&lt;br /&gt;
		end&lt;br /&gt;
		local result = date[id]&lt;br /&gt;
		if type(result) == &#039;string&#039; then&lt;br /&gt;
			return spaces .. result&lt;br /&gt;
		end&lt;br /&gt;
		if type(result) == &#039;number&#039; then&lt;br /&gt;
			return  spaces .. tostring(result)&lt;br /&gt;
		end&lt;br /&gt;
		if type(result) == &#039;boolean&#039; then&lt;br /&gt;
			return  spaces .. (result and &#039;1&#039; or &#039;0&#039;)&lt;br /&gt;
		end&lt;br /&gt;
		-- This occurs if id is an undefined field in a partial date, or is the name of a function.&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local PERCENT = &#039;\127PERCENT\127&#039;&lt;br /&gt;
	return (format&lt;br /&gt;
		:gsub(&#039;%%%%&#039;, PERCENT)&lt;br /&gt;
		:gsub(&#039;(%s*)%%{(%w+)}&#039;, replace_property)&lt;br /&gt;
		:gsub(&#039;(%s*)%%(%-?)(%a)&#039;, replace_code)&lt;br /&gt;
		:gsub(PERCENT, &#039;%%&#039;)&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _date_text(date, fmt, options)&lt;br /&gt;
	-- Return a formatted string representing the given date.&lt;br /&gt;
	if not is_date(date) then&lt;br /&gt;
		error(&#039;date:text: need a date (use &amp;quot;date:text()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if type(fmt) == &#039;string&#039; and fmt:match(&#039;%S&#039;) then&lt;br /&gt;
		if fmt:find(&#039;%&#039;, 1, true) then&lt;br /&gt;
			return strftime(date, fmt, options)&lt;br /&gt;
		end&lt;br /&gt;
	elseif date.partial then&lt;br /&gt;
		fmt = date.month and &#039;my&#039; or &#039;y&#039;&lt;br /&gt;
	else&lt;br /&gt;
		fmt = &#039;dmy&#039;&lt;br /&gt;
		if date.hastime then&lt;br /&gt;
			fmt = (date.second &amp;gt; 0 and &#039;hms &#039; or &#039;hm &#039;) .. fmt&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function bad_format()&lt;br /&gt;
		-- For consistency with other format processing, return given format&lt;br /&gt;
		-- (or cleaned format if original was not a string) if invalid.&lt;br /&gt;
		return mw.text.nowiki(fmt)&lt;br /&gt;
	end&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		-- Ignore days in standard formats like &#039;ymd&#039;.&lt;br /&gt;
		if fmt == &#039;ym&#039; or fmt == &#039;ymd&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%Y-%m %{era}&#039; or &#039;%Y %{era}&#039;&lt;br /&gt;
		elseif fmt == &#039;my&#039; or fmt == &#039;dmy&#039; or fmt == &#039;mdy&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%B %-Y %{era}&#039; or &#039;%-Y %{era}&#039;&lt;br /&gt;
		elseif fmt == &#039;y&#039; then&lt;br /&gt;
			fmt = date.month and &#039;%-Y %{era}&#039; or &#039;%-Y %{era}&#039;&lt;br /&gt;
		else&lt;br /&gt;
			return bad_format()&lt;br /&gt;
		end&lt;br /&gt;
		return strftime(date, fmt, options)&lt;br /&gt;
	end&lt;br /&gt;
	local function hm_fmt()&lt;br /&gt;
		local plain = make_option_table(options, date.options).bydefault.am&lt;br /&gt;
		return plain and &#039;%H:%M&#039; or &#039;%-I:%M %p&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local need_time = date.hastime&lt;br /&gt;
	local t = collection()&lt;br /&gt;
	for item in fmt:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
		local f&lt;br /&gt;
		if item == &#039;hm&#039; then&lt;br /&gt;
			f = hm_fmt()&lt;br /&gt;
			need_time = false&lt;br /&gt;
		elseif item == &#039;hms&#039; then&lt;br /&gt;
			f = &#039;%H:%M:%S&#039;&lt;br /&gt;
			need_time = false&lt;br /&gt;
		elseif item == &#039;ymd&#039; then&lt;br /&gt;
			f = &#039;%Y-%m-%d %{era}&#039;&lt;br /&gt;
		elseif item == &#039;mdy&#039; then&lt;br /&gt;
			f = &#039;%B %-d, %-Y %{era}&#039;&lt;br /&gt;
		elseif item == &#039;dmy&#039; then&lt;br /&gt;
			f = &#039;%-d %B %-Y %{era}&#039;&lt;br /&gt;
		else&lt;br /&gt;
			return bad_format()&lt;br /&gt;
		end&lt;br /&gt;
		t:add(f)&lt;br /&gt;
	end&lt;br /&gt;
	fmt = t:join(&#039; &#039;)&lt;br /&gt;
	if need_time then&lt;br /&gt;
		fmt = hm_fmt() .. &#039; &#039; .. fmt&lt;br /&gt;
	end&lt;br /&gt;
	return strftime(date, fmt, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local day_info = {&lt;br /&gt;
	-- 0=Sun to 6=Sat&lt;br /&gt;
	[0] = { &#039;Sun&#039;, &#039;Sunday&#039; },&lt;br /&gt;
	{ &#039;Mon&#039;, &#039;Monday&#039; },&lt;br /&gt;
	{ &#039;Tue&#039;, &#039;Tuesday&#039; },&lt;br /&gt;
	{ &#039;Wed&#039;, &#039;Wednesday&#039; },&lt;br /&gt;
	{ &#039;Thu&#039;, &#039;Thursday&#039; },&lt;br /&gt;
	{ &#039;Fri&#039;, &#039;Friday&#039; },&lt;br /&gt;
	{ &#039;Sat&#039;, &#039;Saturday&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local month_info = {&lt;br /&gt;
	-- 1=Jan to 12=Dec&lt;br /&gt;
	{ &#039;Jan&#039;, &#039;January&#039; },&lt;br /&gt;
	{ &#039;Feb&#039;, &#039;February&#039; },&lt;br /&gt;
	{ &#039;Mar&#039;, &#039;March&#039; },&lt;br /&gt;
	{ &#039;Apr&#039;, &#039;April&#039; },&lt;br /&gt;
	{ &#039;May&#039;, &#039;May&#039; },&lt;br /&gt;
	{ &#039;Jun&#039;, &#039;June&#039; },&lt;br /&gt;
	{ &#039;Jul&#039;, &#039;July&#039; },&lt;br /&gt;
	{ &#039;Aug&#039;, &#039;August&#039; },&lt;br /&gt;
	{ &#039;Sep&#039;, &#039;September&#039; },&lt;br /&gt;
	{ &#039;Oct&#039;, &#039;October&#039; },&lt;br /&gt;
	{ &#039;Nov&#039;, &#039;November&#039; },&lt;br /&gt;
	{ &#039;Dec&#039;, &#039;December&#039; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function name_to_number(text, translate)&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		return translate[text:lower()]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function day_number(text)&lt;br /&gt;
	return name_to_number(text, {&lt;br /&gt;
		sun = 0, sunday = 0,&lt;br /&gt;
		mon = 1, monday = 1,&lt;br /&gt;
		tue = 2, tuesday = 2,&lt;br /&gt;
		wed = 3, wednesday = 3,&lt;br /&gt;
		thu = 4, thursday = 4,&lt;br /&gt;
		fri = 5, friday = 5,&lt;br /&gt;
		sat = 6, saturday = 6,&lt;br /&gt;
	})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function month_number(text)&lt;br /&gt;
	return name_to_number(text:gsub(&#039;%.&#039;, &#039;&#039;), {&lt;br /&gt;
		jan = 1, january = 1,&lt;br /&gt;
		feb = 2, february = 2,&lt;br /&gt;
		mar = 3, march = 3,&lt;br /&gt;
		apr = 4, april = 4,&lt;br /&gt;
		may = 5,&lt;br /&gt;
		jun = 6, june = 6,&lt;br /&gt;
		jul = 7, july = 7,&lt;br /&gt;
		aug = 8, august = 8,&lt;br /&gt;
		sep = 9, september = 9, sept = 9,&lt;br /&gt;
		oct = 10, october = 10,&lt;br /&gt;
		nov = 11, november = 11,&lt;br /&gt;
		dec = 12, december = 12,&lt;br /&gt;
	})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _list_text(list, fmt)&lt;br /&gt;
	-- Return a list of formatted strings from a list of dates.&lt;br /&gt;
	if not type(list) == &#039;table&#039; then&lt;br /&gt;
		error(&#039;date:list:text: need &amp;quot;list:text()&amp;quot; with a colon&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	local result = { join = _list_join }&lt;br /&gt;
	for i, date in ipairs(list) do&lt;br /&gt;
		result[i] = date:text(fmt)&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _date_list(date, spec)&lt;br /&gt;
	-- Return a possibly empty numbered table of dates meeting the specification.&lt;br /&gt;
	-- Dates in the list are in ascending order (oldest date first).&lt;br /&gt;
	-- The spec should be a string of form &amp;quot;&amp;lt;count&amp;gt; &amp;lt;day&amp;gt; &amp;lt;op&amp;gt;&amp;quot;&lt;br /&gt;
	-- where each item is optional and&lt;br /&gt;
	--   count = number of items wanted in list&lt;br /&gt;
	--   day = abbreviation or name such as Mon or Monday&lt;br /&gt;
	--   op = &amp;gt;, &amp;gt;=, &amp;lt;, &amp;lt;= (default is &amp;gt; meaning after date)&lt;br /&gt;
	-- If no count is given, the list is for the specified days in date&#039;s month.&lt;br /&gt;
	-- The default day is date&#039;s day.&lt;br /&gt;
	-- The spec can also be a positive or negative number:&lt;br /&gt;
	--   -5 is equivalent to &#039;5 &amp;lt;&#039;&lt;br /&gt;
	--   5  is equivalent to &#039;5&#039; which is &#039;5 &amp;gt;&#039;&lt;br /&gt;
	if not is_date(date) then&lt;br /&gt;
		error(&#039;date:list: need a date (use &amp;quot;date:list()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	local list = { text = _list_text }&lt;br /&gt;
	if date.partial then&lt;br /&gt;
		return list&lt;br /&gt;
	end&lt;br /&gt;
	local count, offset, operation&lt;br /&gt;
	local ops = {&lt;br /&gt;
		[&#039;&amp;gt;=&#039;] = { before = false, include = true  },&lt;br /&gt;
		[&#039;&amp;gt;&#039;]  = { before = false, include = false },&lt;br /&gt;
		[&#039;&amp;lt;=&#039;] = { before = true , include = true  },&lt;br /&gt;
		[&#039;&amp;lt;&#039;]  = { before = true , include = false },&lt;br /&gt;
	}&lt;br /&gt;
	if spec then&lt;br /&gt;
		if type(spec) == &#039;number&#039; then&lt;br /&gt;
			count = floor(spec + 0.5)&lt;br /&gt;
			if count &amp;lt; 0 then&lt;br /&gt;
				count = -count&lt;br /&gt;
				operation = ops[&#039;&amp;lt;&#039;]&lt;br /&gt;
			end&lt;br /&gt;
		elseif type(spec) == &#039;string&#039; then&lt;br /&gt;
			local num, day, op = spec:match(&#039;^%s*(%d*)%s*(%a*)%s*([&amp;lt;&amp;gt;=]*)%s*$&#039;)&lt;br /&gt;
			if not num then&lt;br /&gt;
				return list&lt;br /&gt;
			end&lt;br /&gt;
			if num ~= &#039;&#039; then&lt;br /&gt;
				count = tonumber(num)&lt;br /&gt;
			end&lt;br /&gt;
			if day ~= &#039;&#039; then&lt;br /&gt;
				local dow = day_number(day:gsub(&#039;[sS]$&#039;, &#039;&#039;))  -- accept plural days&lt;br /&gt;
				if not dow then&lt;br /&gt;
					return list&lt;br /&gt;
				end&lt;br /&gt;
				offset = dow - date.dow&lt;br /&gt;
			end&lt;br /&gt;
			operation = ops[op]&lt;br /&gt;
		else&lt;br /&gt;
			return list&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	offset = offset or 0&lt;br /&gt;
	operation = operation or ops[&#039;&amp;gt;&#039;]&lt;br /&gt;
	local datefrom, dayfirst, daylast&lt;br /&gt;
	if operation.before then&lt;br /&gt;
		if offset &amp;gt; 0 or (offset == 0 and not operation.include) then&lt;br /&gt;
			offset = offset - 7&lt;br /&gt;
		end&lt;br /&gt;
		if count then&lt;br /&gt;
			if count &amp;gt; 1 then&lt;br /&gt;
				offset = offset - 7*(count - 1)&lt;br /&gt;
			end&lt;br /&gt;
			datefrom = date + offset&lt;br /&gt;
		else&lt;br /&gt;
			daylast = date.day + offset&lt;br /&gt;
			dayfirst = daylast % 7&lt;br /&gt;
			if dayfirst == 0 then&lt;br /&gt;
				dayfirst = 7&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if offset &amp;lt; 0 or (offset == 0 and not operation.include) then&lt;br /&gt;
			offset = offset + 7&lt;br /&gt;
		end&lt;br /&gt;
		if count then&lt;br /&gt;
			datefrom = date + offset&lt;br /&gt;
		else&lt;br /&gt;
			dayfirst = date.day + offset&lt;br /&gt;
			daylast = date.monthdays&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not count then&lt;br /&gt;
		if daylast &amp;lt; dayfirst then&lt;br /&gt;
			return list&lt;br /&gt;
		end&lt;br /&gt;
		count = floor((daylast - dayfirst)/7) + 1&lt;br /&gt;
		datefrom = Date(date, {day = dayfirst})&lt;br /&gt;
	end&lt;br /&gt;
	for i = 1, count do&lt;br /&gt;
		if not datefrom then break end  -- exceeds date limits&lt;br /&gt;
		list[i] = datefrom&lt;br /&gt;
		datefrom = datefrom + 7&lt;br /&gt;
	end&lt;br /&gt;
	return list&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Cache the current date/time (UTC).&lt;br /&gt;
--&lt;br /&gt;
-- Note that os.date() returns an empty object with optimized lazy getters for each field.&lt;br /&gt;
-- Avoid current.min or current.sec in articles! https://phabricator.wikimedia.org/T416616&lt;br /&gt;
--&lt;br /&gt;
-- Beware that while os.date() uses &#039;min&#039; and &#039;sec&#039;, our Date() uses &#039;minute&#039; and &#039;second&#039;.&lt;br /&gt;
local current = os.date(&#039;!*t&#039;)&lt;br /&gt;
&lt;br /&gt;
local function extract_date(newdate, text)&lt;br /&gt;
	-- Parse the date/time in text and return n, o where&lt;br /&gt;
	--   n = table of numbers with date/time fields&lt;br /&gt;
	--   o = table of options for AM/PM or AD/BC or format, if any&lt;br /&gt;
	-- or return nothing if date is known to be invalid.&lt;br /&gt;
	-- Caller determines if the values in n are valid.&lt;br /&gt;
	-- A year must be positive (&#039;1&#039; to &#039;9999&#039;); use &#039;BC&#039; for BC.&lt;br /&gt;
	-- In a y-m-d string, the year must be four digits to avoid ambiguity&lt;br /&gt;
	-- (&#039;0001&#039; to &#039;9999&#039;). The only way to enter year &amp;lt;= 0 is by specifying&lt;br /&gt;
	-- the date as three numeric parameters like ymd Date(-1, 1, 1).&lt;br /&gt;
	-- Dates of form d/m/y, m/d/y, y/m/d are rejected as potentially ambiguous.&lt;br /&gt;
	local date, options = {}, {}&lt;br /&gt;
	if text:sub(-1) == &#039;Z&#039; then&lt;br /&gt;
		-- Extract date/time from a Wikidata timestamp.&lt;br /&gt;
		-- The year can be 1 to 16 digits but this module handles 1 to 4 digits only.&lt;br /&gt;
		-- Examples: &#039;+2016-06-21T14:30:00Z&#039;, &#039;-0000000180-00-00T00:00:00Z&#039;.&lt;br /&gt;
		local sign, y, m, d, H, M, S = text:match(&#039;^([+%-])(%d+)%-(%d%d)%-(%d%d)T(%d%d):(%d%d):(%d%d)Z$&#039;)&lt;br /&gt;
		if sign then&lt;br /&gt;
			y = tonumber(y)&lt;br /&gt;
			if sign == &#039;-&#039; and y &amp;gt; 0 then&lt;br /&gt;
				y = -y&lt;br /&gt;
			end&lt;br /&gt;
			if y &amp;lt;= 0 then&lt;br /&gt;
				options.era = &#039;BCE&#039;&lt;br /&gt;
			end&lt;br /&gt;
			date.year = y&lt;br /&gt;
			m = tonumber(m)&lt;br /&gt;
			d = tonumber(d)&lt;br /&gt;
			H = tonumber(H)&lt;br /&gt;
			M = tonumber(M)&lt;br /&gt;
			S = tonumber(S)&lt;br /&gt;
			if m == 0 then&lt;br /&gt;
				newdate.partial = true&lt;br /&gt;
				return date, options&lt;br /&gt;
			end&lt;br /&gt;
			date.month = m&lt;br /&gt;
			if d == 0 then&lt;br /&gt;
				newdate.partial = true&lt;br /&gt;
				return date, options&lt;br /&gt;
			end&lt;br /&gt;
			date.day = d&lt;br /&gt;
			if H &amp;gt; 0 or M &amp;gt; 0 or S &amp;gt; 0 then&lt;br /&gt;
				date.hour = H&lt;br /&gt;
				date.minute = M&lt;br /&gt;
				date.second = S&lt;br /&gt;
			end&lt;br /&gt;
			return date, options&lt;br /&gt;
		end&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_ymd(item)&lt;br /&gt;
		-- Called when no day or month has been set.&lt;br /&gt;
		local y, m, d = item:match(&#039;^(%d%d%d%d)%-(%w+)%-(%d%d?)$&#039;)&lt;br /&gt;
		if y then&lt;br /&gt;
			if date.year then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if m:match(&#039;^%d%d?$&#039;) then&lt;br /&gt;
				m = tonumber(m)&lt;br /&gt;
			else&lt;br /&gt;
				m = month_number(m)&lt;br /&gt;
			end&lt;br /&gt;
			if m then&lt;br /&gt;
				date.year = tonumber(y)&lt;br /&gt;
				date.month = m&lt;br /&gt;
				date.day = tonumber(d)&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_day_or_year(item)&lt;br /&gt;
		-- Called when a day would be valid, or&lt;br /&gt;
		-- when a year would be valid if no year has been set and partial is set.&lt;br /&gt;
		local number, suffix = item:match(&#039;^(%d%d?%d?%d?)(.*)$&#039;)&lt;br /&gt;
		if number then&lt;br /&gt;
			local n = tonumber(number)&lt;br /&gt;
			if #number &amp;lt;= 2 and n &amp;lt;= 31 then&lt;br /&gt;
				suffix = suffix:lower()&lt;br /&gt;
				if suffix == &#039;&#039; or suffix == &#039;st&#039; or suffix == &#039;nd&#039; or suffix == &#039;rd&#039; or suffix == &#039;th&#039; then&lt;br /&gt;
					date.day = n&lt;br /&gt;
					return true&lt;br /&gt;
				end&lt;br /&gt;
			elseif suffix == &#039;&#039; and newdate.partial and not date.year then&lt;br /&gt;
				date.year = n&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_month(item)&lt;br /&gt;
		-- A month must be given as a name or abbreviation; a number could be ambiguous.&lt;br /&gt;
		local m = month_number(item)&lt;br /&gt;
		if m then&lt;br /&gt;
			date.month = m&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local function extract_time(item)&lt;br /&gt;
		local h, m, s = item:match(&#039;^(%d%d?):(%d%d)(:?%d*)$&#039;)&lt;br /&gt;
		if date.hour or not h then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
		if s ~= &#039;&#039; then&lt;br /&gt;
			s = s:match(&#039;^:(%d%d)$&#039;)&lt;br /&gt;
			if not s then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		date.hour = tonumber(h)&lt;br /&gt;
		date.minute = tonumber(m)&lt;br /&gt;
		date.second = tonumber(s)  -- nil if empty string&lt;br /&gt;
		return true&lt;br /&gt;
	end&lt;br /&gt;
	local item_count = 0&lt;br /&gt;
	local index_time&lt;br /&gt;
	local function set_ampm(item)&lt;br /&gt;
		local H = date.hour&lt;br /&gt;
		if H and not options.am and index_time + 1 == item_count then&lt;br /&gt;
			options.am = ampm_options[item]  -- caller checked this is not nil&lt;br /&gt;
			if item:match(&#039;^[Aa]&#039;) then&lt;br /&gt;
				if not (1 &amp;lt;= H and H &amp;lt;= 12) then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				if H == 12 then&lt;br /&gt;
					date.hour = 0&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				if not (1 &amp;lt;= H and H &amp;lt;= 23) then&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
				if H &amp;lt;= 11 then&lt;br /&gt;
					date.hour = H + 12&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for item in text:gsub(&#039;,&#039;, &#039; &#039;):gsub(&#039;&amp;amp;nbsp;&#039;, &#039; &#039;):gmatch(&#039;%S+&#039;) do&lt;br /&gt;
		item_count = item_count + 1&lt;br /&gt;
		if era_text[item] then&lt;br /&gt;
			-- Era is accepted in peculiar places.&lt;br /&gt;
			if options.era then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			options.era = item&lt;br /&gt;
		elseif ampm_options[item] then&lt;br /&gt;
			if not set_ampm(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif item:find(&#039;:&#039;, 1, true) then&lt;br /&gt;
			if not extract_time(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			index_time = item_count&lt;br /&gt;
		elseif date.day and date.month then&lt;br /&gt;
			if date.year then&lt;br /&gt;
				return  -- should be nothing more so item is invalid&lt;br /&gt;
			end&lt;br /&gt;
			if not item:match(&#039;^(%d%d?%d?%d?)$&#039;) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			date.year = tonumber(item)&lt;br /&gt;
		elseif date.day then&lt;br /&gt;
			if not extract_month(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif date.month then&lt;br /&gt;
			if not extract_day_or_year(item) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		elseif extract_month(item) then&lt;br /&gt;
			options.format = &#039;mdy&#039;&lt;br /&gt;
		elseif extract_ymd(item) then&lt;br /&gt;
			options.format = &#039;ymd&#039;&lt;br /&gt;
		elseif extract_day_or_year(item) then&lt;br /&gt;
			if date.day then&lt;br /&gt;
				options.format = &#039;dmy&#039;&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not date.year or date.year == 0 then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local era = era_text[options.era]&lt;br /&gt;
	if era and era.isbc then&lt;br /&gt;
		date.year = 1 - date.year&lt;br /&gt;
	end&lt;br /&gt;
	return date, options&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function autofill(date1, date2)&lt;br /&gt;
	-- Fill any missing month or day in each date using the&lt;br /&gt;
	-- corresponding component from the other date, if present,&lt;br /&gt;
	-- or with 1 if both dates are missing the month or day.&lt;br /&gt;
	-- This gives a good result for calculating the difference&lt;br /&gt;
	-- between two partial dates when no range is wanted.&lt;br /&gt;
	-- Return filled date1, date2 (two full dates).&lt;br /&gt;
	local function filled(a, b)&lt;br /&gt;
		-- Return date a filled, if necessary, with month and/or day from date b.&lt;br /&gt;
		-- The filled day is truncated to fit the number of days in the month.&lt;br /&gt;
		local fillmonth, fillday&lt;br /&gt;
		if not a.month then&lt;br /&gt;
			fillmonth = b.month or 1&lt;br /&gt;
		end&lt;br /&gt;
		if not a.day then&lt;br /&gt;
			fillday = b.day or 1&lt;br /&gt;
		end&lt;br /&gt;
		if fillmonth or fillday then  -- need to create a new date&lt;br /&gt;
			a = Date(a, {&lt;br /&gt;
				month = fillmonth,&lt;br /&gt;
				day = math.min(fillday or a.day, days_in_month(a.year, fillmonth or a.month, a.calendar))&lt;br /&gt;
			})&lt;br /&gt;
		end&lt;br /&gt;
		return a&lt;br /&gt;
	end&lt;br /&gt;
	return filled(date1, date2), filled(date2, date1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function date_add_sub(lhs, rhs, is_sub)&lt;br /&gt;
	-- Return a new date from calculating (lhs + rhs) or (lhs - rhs),&lt;br /&gt;
	-- or return nothing if invalid.&lt;br /&gt;
	-- The result is nil if the calculated date exceeds allowable limits.&lt;br /&gt;
	-- Caller ensures that lhs is a date; its properties are copied for the new date.&lt;br /&gt;
	if lhs.partial then&lt;br /&gt;
		-- Adding to a partial is not supported.&lt;br /&gt;
		-- Can subtract a date or partial from a partial, but this is not called for that.&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local function is_prefix(text, word, minlen)&lt;br /&gt;
		local n = #text&lt;br /&gt;
		return (minlen or 1) &amp;lt;= n and n &amp;lt;= #word and text == word:sub(1, n)&lt;br /&gt;
	end&lt;br /&gt;
	local function do_days(n)&lt;br /&gt;
		local forcetime, jd&lt;br /&gt;
		if floor(n) == n then&lt;br /&gt;
			jd = lhs.jd&lt;br /&gt;
		else&lt;br /&gt;
			forcetime = not lhs.hastime&lt;br /&gt;
			jd = lhs.jdz&lt;br /&gt;
		end&lt;br /&gt;
		jd = jd + (is_sub and -n or n)&lt;br /&gt;
		if forcetime then&lt;br /&gt;
			jd = tostring(jd)&lt;br /&gt;
			if not jd:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
				jd = jd .. &#039;.0&#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return Date(lhs, &#039;juliandate&#039;, jd)&lt;br /&gt;
	end&lt;br /&gt;
	if type(rhs) == &#039;number&#039; then&lt;br /&gt;
		-- Add/subtract days, including fractional days.&lt;br /&gt;
		return do_days(rhs)&lt;br /&gt;
	end&lt;br /&gt;
	if type(rhs) == &#039;string&#039; then&lt;br /&gt;
		-- rhs is a single component like &#039;26m&#039; or &#039;26 months&#039; (with optional sign).&lt;br /&gt;
		-- Fractions like &#039;3.25d&#039; are accepted for the units which are handled as days.&lt;br /&gt;
		local sign, numstr, id = rhs:match(&#039;^%s*([+-]?)([%d%.]+)%s*(%a+)$&#039;)&lt;br /&gt;
		if sign then&lt;br /&gt;
			if sign == &#039;-&#039; then&lt;br /&gt;
				is_sub = not (is_sub and true or false)&lt;br /&gt;
			end&lt;br /&gt;
			local y, m, days&lt;br /&gt;
			local num = tonumber(numstr)&lt;br /&gt;
			if not num then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			id = id:lower()&lt;br /&gt;
			if is_prefix(id, &#039;years&#039;) then&lt;br /&gt;
				y = num&lt;br /&gt;
				m = 0&lt;br /&gt;
			elseif is_prefix(id, &#039;months&#039;) then&lt;br /&gt;
				y = floor(num / 12)&lt;br /&gt;
				m = num % 12&lt;br /&gt;
			elseif is_prefix(id, &#039;weeks&#039;) then&lt;br /&gt;
				days = num * 7&lt;br /&gt;
			elseif is_prefix(id, &#039;days&#039;) then&lt;br /&gt;
				days = num&lt;br /&gt;
			elseif is_prefix(id, &#039;hours&#039;) then&lt;br /&gt;
				days = num / 24&lt;br /&gt;
			elseif is_prefix(id, &#039;minutes&#039;, 3) then&lt;br /&gt;
				days = num / (24 * 60)&lt;br /&gt;
			elseif is_prefix(id, &#039;seconds&#039;) then&lt;br /&gt;
				days = num / (24 * 3600)&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if days then&lt;br /&gt;
				return do_days(days)&lt;br /&gt;
			end&lt;br /&gt;
			if numstr:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			if is_sub then&lt;br /&gt;
				y = -y&lt;br /&gt;
				m = -m&lt;br /&gt;
			end&lt;br /&gt;
			assert(-11 &amp;lt;= m and m &amp;lt;= 11)&lt;br /&gt;
			y = lhs.year + y&lt;br /&gt;
			m = lhs.month + m&lt;br /&gt;
			if m &amp;gt; 12 then&lt;br /&gt;
				y = y + 1&lt;br /&gt;
				m = m - 12&lt;br /&gt;
			elseif m &amp;lt; 1 then&lt;br /&gt;
				y = y - 1&lt;br /&gt;
				m = m + 12&lt;br /&gt;
			end&lt;br /&gt;
			local d = math.min(lhs.day, days_in_month(y, m, lhs.calendar))&lt;br /&gt;
			return Date(lhs, y, m, d)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if is_diff(rhs) then&lt;br /&gt;
		local days = rhs.age_days&lt;br /&gt;
		if (is_sub or false) ~= (rhs.isnegative or false) then&lt;br /&gt;
			days = -days&lt;br /&gt;
		end&lt;br /&gt;
		return lhs + days&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local full_date_only = {&lt;br /&gt;
	dayabbr = true,&lt;br /&gt;
	dayname = true,&lt;br /&gt;
	dow = true,&lt;br /&gt;
	dayofweek = true,&lt;br /&gt;
	dowiso = true,&lt;br /&gt;
	dayofweekiso = true,&lt;br /&gt;
	dayofyear = true,&lt;br /&gt;
	gsd = true,&lt;br /&gt;
	juliandate = true,&lt;br /&gt;
	jd = true,&lt;br /&gt;
	jdz = true,&lt;br /&gt;
	jdnoon = true,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Metatable for a date&#039;s calculated fields.&lt;br /&gt;
local datemt = {&lt;br /&gt;
	__index = function (self, key)&lt;br /&gt;
		if rawget(self, &#039;partial&#039;) then&lt;br /&gt;
			if full_date_only[key] then return end&lt;br /&gt;
			if key == &#039;monthabbr&#039; or key == &#039;monthdays&#039; or key == &#039;monthname&#039; then&lt;br /&gt;
				if not self.month then return end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local value&lt;br /&gt;
		if key == &#039;dayabbr&#039; then&lt;br /&gt;
			value = day_info[self.dow][1]&lt;br /&gt;
		elseif key == &#039;dayname&#039; then&lt;br /&gt;
			value = day_info[self.dow][2]&lt;br /&gt;
		elseif key == &#039;dow&#039; then&lt;br /&gt;
			value = (self.jdnoon + 1) % 7  -- day-of-week 0=Sun to 6=Sat&lt;br /&gt;
		elseif key == &#039;dayofweek&#039; then&lt;br /&gt;
			value = self.dow&lt;br /&gt;
		elseif key == &#039;dowiso&#039; then&lt;br /&gt;
			value = (self.jdnoon % 7) + 1  -- ISO day-of-week 1=Mon to 7=Sun&lt;br /&gt;
		elseif key == &#039;dayofweekiso&#039; then&lt;br /&gt;
			value = self.dowiso&lt;br /&gt;
		elseif key == &#039;dayofyear&#039; then&lt;br /&gt;
			local first = Date(self.year, 1, 1, self.calendar).jdnoon&lt;br /&gt;
			value = self.jdnoon - first + 1  -- day-of-year 1 to 366&lt;br /&gt;
		elseif key == &#039;era&#039; then&lt;br /&gt;
			-- Era text (never a negative sign) from year and options.&lt;br /&gt;
			value = get_era_for_year(self.options.era, self.year)&lt;br /&gt;
		elseif key == &#039;format&#039; then&lt;br /&gt;
			value = self.options.format or &#039;dmy&#039;&lt;br /&gt;
		elseif key == &#039;gsd&#039; then&lt;br /&gt;
			-- GSD = 1 from 00:00:00 to 23:59:59 on 1 January 1 AD Gregorian calendar,&lt;br /&gt;
			-- which is from jd 1721425.5 to 1721426.49999.&lt;br /&gt;
			value = floor(self.jd - 1721424.5)&lt;br /&gt;
		elseif key == &#039;juliandate&#039; or key == &#039;jd&#039; or key == &#039;jdz&#039; then&lt;br /&gt;
			local jd, jdz = julian_date(self)&lt;br /&gt;
			rawset(self, &#039;juliandate&#039;, jd)&lt;br /&gt;
			rawset(self, &#039;jd&#039;, jd)&lt;br /&gt;
			rawset(self, &#039;jdz&#039;, jdz)&lt;br /&gt;
			return key == &#039;jdz&#039; and jdz or jd&lt;br /&gt;
		elseif key == &#039;jdnoon&#039; then&lt;br /&gt;
			-- Julian date at noon (an integer) on the calendar day when jd occurs.&lt;br /&gt;
			value = floor(self.jd + 0.5)&lt;br /&gt;
		elseif key == &#039;isleapyear&#039; then&lt;br /&gt;
			value = is_leap_year(self.year, self.calendar)&lt;br /&gt;
		elseif key == &#039;monthabbr&#039; then&lt;br /&gt;
			value = month_info[self.month][1]&lt;br /&gt;
		elseif key == &#039;monthdays&#039; then&lt;br /&gt;
			value = days_in_month(self.year, self.month, self.calendar)&lt;br /&gt;
		elseif key == &#039;monthname&#039; then&lt;br /&gt;
			value = month_info[self.month][2]&lt;br /&gt;
		end&lt;br /&gt;
		if value ~= nil then&lt;br /&gt;
			rawset(self, key, value)&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
-- Date operators.&lt;br /&gt;
local function mt_date_add(lhs, rhs)&lt;br /&gt;
	if not is_date(lhs) then&lt;br /&gt;
		lhs, rhs = rhs, lhs  -- put date on left (it must be a date for this to have been called)&lt;br /&gt;
	end&lt;br /&gt;
	return date_add_sub(lhs, rhs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_sub(lhs, rhs)&lt;br /&gt;
	if is_date(lhs) then&lt;br /&gt;
		if is_date(rhs) then&lt;br /&gt;
			return DateDiff(lhs, rhs)&lt;br /&gt;
		end&lt;br /&gt;
		return date_add_sub(lhs, rhs, true)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_concat(lhs, rhs)&lt;br /&gt;
	return tostring(lhs) .. tostring(rhs)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_tostring(self)&lt;br /&gt;
	return self:text()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_eq(lhs, rhs)&lt;br /&gt;
	-- Return true if dates identify same date/time where, for example,&lt;br /&gt;
	-- Date(-4712, 1, 1, &#039;Julian&#039;) == Date(-4713, 11, 24, &#039;Gregorian&#039;) is true.&lt;br /&gt;
	-- This is called only if lhs and rhs have the same type and the same metamethod.&lt;br /&gt;
	if lhs.partial or rhs.partial then&lt;br /&gt;
		-- One date is partial; the other is a partial or a full date.&lt;br /&gt;
		-- The months may both be nil, but must be the same.&lt;br /&gt;
		return lhs.year == rhs.year and lhs.month == rhs.month and lhs.calendar == rhs.calendar&lt;br /&gt;
	end&lt;br /&gt;
	return lhs.jdz == rhs.jdz&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mt_date_lt(lhs, rhs)&lt;br /&gt;
	-- Return true if lhs &amp;lt; rhs, for example,&lt;br /&gt;
	-- Date(&#039;1 Jan 2016&#039;) &amp;lt; Date(&#039;06:00 1 Jan 2016&#039;) is true.&lt;br /&gt;
	-- This is called only if lhs and rhs have the same type and the same metamethod.&lt;br /&gt;
	if lhs.partial or rhs.partial then&lt;br /&gt;
		-- One date is partial; the other is a partial or a full date.&lt;br /&gt;
		if lhs.calendar ~= rhs.calendar then&lt;br /&gt;
			return lhs.calendar == &#039;Julian&#039;&lt;br /&gt;
		end&lt;br /&gt;
		if lhs.partial then&lt;br /&gt;
			lhs = lhs.partial.first&lt;br /&gt;
		end&lt;br /&gt;
		if rhs.partial then&lt;br /&gt;
			rhs = rhs.partial.first&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return lhs.jdz &amp;lt; rhs.jdz&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Examples of syntax to construct a date:&lt;br /&gt;
Date(y, m, d, &#039;julian&#039;)             default calendar is &#039;gregorian&#039;&lt;br /&gt;
Date(y, m, d, H, M, S, &#039;julian&#039;)&lt;br /&gt;
Date(&#039;juliandate&#039;, jd, &#039;julian&#039;)    if jd contains &amp;quot;.&amp;quot; text output includes H:M:S&lt;br /&gt;
Date(&#039;currentdate&#039;)&lt;br /&gt;
Date(&#039;currentdatetime&#039;)&lt;br /&gt;
Date(&#039;1 April 1995&#039;, &#039;julian&#039;)      parse date from text&lt;br /&gt;
Date(&#039;1 April 1995 AD&#039;, &#039;julian&#039;)   using an era sets a flag to do the same for output&lt;br /&gt;
Date(&#039;04:30:59 1 April 1995&#039;, &#039;julian&#039;)&lt;br /&gt;
Date(date)                          copy of an existing date&lt;br /&gt;
Date(date, t)                       same, updated with y,m,d,H,M,S fields from table t&lt;br /&gt;
Date(t)                       		date with y,m,d,H,M,S fields from table t&lt;br /&gt;
]]&lt;br /&gt;
function Date(...)  -- for forward declaration above&lt;br /&gt;
	-- Return a table holding a date assuming a uniform calendar always applies&lt;br /&gt;
	-- (proleptic Gregorian calendar or proleptic Julian calendar), or&lt;br /&gt;
	-- return nothing if date is invalid.&lt;br /&gt;
	-- A partial date has a valid year, however its month may be nil, and&lt;br /&gt;
	-- its day and time fields are nil.&lt;br /&gt;
	-- Field partial is set to false (if a full date) or a table (if a partial date).&lt;br /&gt;
	local calendars = { julian = &#039;Julian&#039;, gregorian = &#039;Gregorian&#039; }&lt;br /&gt;
	local newdate = {&lt;br /&gt;
		_id = uniq,&lt;br /&gt;
		calendar = &#039;Gregorian&#039;,  -- default is Gregorian calendar&lt;br /&gt;
		hastime = false,  -- true if input sets a time&lt;br /&gt;
		hour = 0,  -- always set hour/minute/second so don&#039;t have to handle nil&lt;br /&gt;
		minute = 0,&lt;br /&gt;
		second = 0,&lt;br /&gt;
		options = {},&lt;br /&gt;
		list = _date_list,&lt;br /&gt;
		subtract = function (self, rhs, options)&lt;br /&gt;
			return DateDiff(self, rhs, options)&lt;br /&gt;
		end,&lt;br /&gt;
		text = _date_text,&lt;br /&gt;
	}&lt;br /&gt;
	local argtype, datetext, is_copy, jd_number, tnums&lt;br /&gt;
	local numindex = 0&lt;br /&gt;
	local numfields = { &#039;year&#039;, &#039;month&#039;, &#039;day&#039;, &#039;hour&#039;, &#039;minute&#039;, &#039;second&#039; }&lt;br /&gt;
	local numbers = {}&lt;br /&gt;
	for _, v in ipairs({...}) do&lt;br /&gt;
		v = strip_to_nil(v)&lt;br /&gt;
		local vlower = type(v) == &#039;string&#039; and v:lower() or nil&lt;br /&gt;
		if v == nil then&lt;br /&gt;
			-- Ignore empty arguments after stripping so modules can directly pass template parameters.&lt;br /&gt;
		elseif calendars[vlower] then&lt;br /&gt;
			newdate.calendar = calendars[vlower]&lt;br /&gt;
		elseif vlower == &#039;partial&#039; then&lt;br /&gt;
			newdate.partial = true&lt;br /&gt;
		elseif vlower == &#039;fix&#039; then&lt;br /&gt;
			newdate.want_fix = true&lt;br /&gt;
		elseif is_date(v) then&lt;br /&gt;
			-- Copy existing date (items can be overridden by other arguments).&lt;br /&gt;
			if is_copy or tnums then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			is_copy = true&lt;br /&gt;
			newdate.calendar = v.calendar&lt;br /&gt;
			newdate.partial = v.partial&lt;br /&gt;
			newdate.hastime = v.hastime&lt;br /&gt;
			newdate.options = v.options&lt;br /&gt;
			newdate.year = v.year&lt;br /&gt;
			newdate.month = v.month&lt;br /&gt;
			newdate.day = v.day&lt;br /&gt;
			newdate.hour = v.hour&lt;br /&gt;
			newdate.minute = v.minute&lt;br /&gt;
			newdate.second = v.second&lt;br /&gt;
		elseif type(v) == &#039;table&#039; then&lt;br /&gt;
			if tnums then&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
			tnums = {}&lt;br /&gt;
			local tfields = { year=1, month=1, day=1, hour=2, minute=2, second=2 }&lt;br /&gt;
			for tk, tv in pairs(v) do&lt;br /&gt;
				if tfields[tk] then&lt;br /&gt;
					tnums[tk] = tonumber(tv)&lt;br /&gt;
				end&lt;br /&gt;
				if tfields[tk] == 2 then&lt;br /&gt;
					newdate.hastime = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			local num = tonumber(v)&lt;br /&gt;
			if not num and argtype == &#039;setdate&#039; and numindex == 1 then&lt;br /&gt;
				num = month_number(v)&lt;br /&gt;
			end&lt;br /&gt;
			if num then&lt;br /&gt;
				if not argtype then&lt;br /&gt;
					argtype = &#039;setdate&#039;&lt;br /&gt;
				end&lt;br /&gt;
				if argtype == &#039;setdate&#039; and numindex &amp;lt; 6 then&lt;br /&gt;
					numindex = numindex + 1&lt;br /&gt;
					numbers[numfields[numindex]] = num&lt;br /&gt;
				elseif argtype == &#039;juliandate&#039; and not jd_number then&lt;br /&gt;
					jd_number = num&lt;br /&gt;
					if type(v) == &#039;string&#039; then&lt;br /&gt;
						if v:find(&#039;.&#039;, 1, true) then&lt;br /&gt;
							newdate.hastime = true&lt;br /&gt;
						end&lt;br /&gt;
					elseif num ~= floor(num) then&lt;br /&gt;
						-- The given value was a number. The time will be used&lt;br /&gt;
						-- if the fractional part is nonzero.&lt;br /&gt;
						newdate.hastime = true&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					return&lt;br /&gt;
				end&lt;br /&gt;
			elseif argtype then&lt;br /&gt;
				return&lt;br /&gt;
			elseif type(v) == &#039;string&#039; then&lt;br /&gt;
				if v == &#039;currentdate&#039; or v == &#039;currentdatetime&#039; or v == &#039;juliandate&#039; then&lt;br /&gt;
					argtype = v&lt;br /&gt;
				else&lt;br /&gt;
					argtype = &#039;datetext&#039;&lt;br /&gt;
					datetext = v&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				return&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if argtype == &#039;datetext&#039; then&lt;br /&gt;
		if tnums or not set_date_from_numbers(newdate, extract_date(newdate, datetext)) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif argtype == &#039;juliandate&#039; then&lt;br /&gt;
		newdate.partial = nil&lt;br /&gt;
		newdate.jd = jd_number&lt;br /&gt;
		if not set_date_from_jd(newdate) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif argtype == &#039;currentdate&#039; or argtype == &#039;currentdatetime&#039; then&lt;br /&gt;
		newdate.partial = nil&lt;br /&gt;
		newdate.year = current.year&lt;br /&gt;
		newdate.month = current.month&lt;br /&gt;
		newdate.day = current.day&lt;br /&gt;
		if argtype == &#039;currentdatetime&#039; then&lt;br /&gt;
			newdate.hour = current.hour&lt;br /&gt;
			newdate.minute = current.min&lt;br /&gt;
			newdate.second = current.sec&lt;br /&gt;
			newdate.hastime = true&lt;br /&gt;
		end&lt;br /&gt;
		newdate.calendar = &#039;Gregorian&#039;  -- ignore any given calendar name&lt;br /&gt;
	elseif argtype == &#039;setdate&#039; then&lt;br /&gt;
		if tnums or not set_date_from_numbers(newdate, numbers) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	elseif not (is_copy or tnums) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	if tnums then&lt;br /&gt;
		newdate.jd = nil  -- force recalculation in case jd was set before changes from tnums&lt;br /&gt;
		if not set_date_from_numbers(newdate, tnums) then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if newdate.partial then&lt;br /&gt;
		local year = newdate.year&lt;br /&gt;
		local month = newdate.month&lt;br /&gt;
		local first = Date(year, month or 1, 1, newdate.calendar)&lt;br /&gt;
		month = month or 12&lt;br /&gt;
		local last = Date(year, month, days_in_month(year, month), newdate.calendar)&lt;br /&gt;
		newdate.partial = { first = first, last = last }&lt;br /&gt;
	else&lt;br /&gt;
		newdate.partial = false  -- avoid index lookup&lt;br /&gt;
	end&lt;br /&gt;
	setmetatable(newdate, datemt)&lt;br /&gt;
	local readonly = {}&lt;br /&gt;
	local mt = {&lt;br /&gt;
		__index = newdate,&lt;br /&gt;
		__newindex = function(t, k, v) error(&#039;date.&#039; .. tostring(k) .. &#039; is read-only&#039;, 2) end,&lt;br /&gt;
		__add = mt_date_add,&lt;br /&gt;
		__sub = mt_date_sub,&lt;br /&gt;
		__concat = mt_date_concat,&lt;br /&gt;
		__tostring = mt_date_tostring,&lt;br /&gt;
		__eq = mt_date_eq,&lt;br /&gt;
		__lt = mt_date_lt,&lt;br /&gt;
	}&lt;br /&gt;
	return setmetatable(readonly, mt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _diff_age(diff, code, options)&lt;br /&gt;
	-- Return a tuple of integer values from diff as specified by code, except that&lt;br /&gt;
	-- each integer may be a list of two integers for a diff with a partial date, or&lt;br /&gt;
	-- return nil if the code is not supported.&lt;br /&gt;
	-- If want round, the least significant unit is rounded to nearest whole unit.&lt;br /&gt;
	-- For a duration, an extra day is added.&lt;br /&gt;
	local wantround, wantduration, wantrange&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		wantround = options.round&lt;br /&gt;
		wantduration = options.duration&lt;br /&gt;
		wantrange = options.range&lt;br /&gt;
	else&lt;br /&gt;
		wantround = options&lt;br /&gt;
	end&lt;br /&gt;
	if not is_diff(diff) then&lt;br /&gt;
		local f = wantduration and &#039;duration&#039; or &#039;age&#039;&lt;br /&gt;
		error(f .. &#039;: need a date difference (use &amp;quot;diff:&#039; .. f .. &#039;()&amp;quot; with a colon)&#039;, 2)&lt;br /&gt;
	end&lt;br /&gt;
	if diff.partial then&lt;br /&gt;
		-- Ignore wantround, wantduration.&lt;br /&gt;
		local function choose(v)&lt;br /&gt;
			if type(v) == &#039;table&#039; then&lt;br /&gt;
				if not wantrange or v[1] == v[2] then&lt;br /&gt;
					-- Example: Date(&#039;partial&#039;, 2005) - Date(&#039;partial&#039;, 2001) gives&lt;br /&gt;
					-- diff.years = { 3, 4 } to show the range of possible results.&lt;br /&gt;
					-- If do not want a range, choose the second value as more expected.&lt;br /&gt;
					return v[2]&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return v&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;ym&#039; or code == &#039;ymd&#039; then&lt;br /&gt;
			if not wantrange and diff.iszero then&lt;br /&gt;
				-- This avoids an unexpected result such as&lt;br /&gt;
				-- Date(&#039;partial&#039;, 2001) - Date(&#039;partial&#039;, 2001)&lt;br /&gt;
				-- giving diff = { years = 0, months = { 0, 11 } }&lt;br /&gt;
				-- which would be reported as 0 years and 11 months.&lt;br /&gt;
				return 0, 0&lt;br /&gt;
			end&lt;br /&gt;
			return choose(diff.partial.years), choose(diff.partial.months)&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;y&#039; then&lt;br /&gt;
			return choose(diff.partial.years)&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;m&#039; or code == &#039;w&#039; or code == &#039;d&#039; then&lt;br /&gt;
			return choose({ diff.partial.mindiff:age(code), diff.partial.maxdiff:age(code) })&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local extra_days = wantduration and 1 or 0&lt;br /&gt;
	if code == &#039;wd&#039; or code == &#039;w&#039; or code == &#039;d&#039; then&lt;br /&gt;
		local offset = wantround and 0.5 or 0&lt;br /&gt;
		local days = diff.age_days + extra_days&lt;br /&gt;
		if code == &#039;wd&#039; or code == &#039;d&#039; then&lt;br /&gt;
			days = floor(days + offset)&lt;br /&gt;
			if code == &#039;d&#039; then&lt;br /&gt;
				return days&lt;br /&gt;
			end&lt;br /&gt;
			return floor(days/7), days % 7&lt;br /&gt;
		end&lt;br /&gt;
		return floor(days/7 + offset)&lt;br /&gt;
	end&lt;br /&gt;
	local H, M, S = diff.hours, diff.minutes, diff.seconds&lt;br /&gt;
	if code == &#039;dh&#039; or code == &#039;dhm&#039; or code == &#039;dhms&#039; or code == &#039;h&#039; or code == &#039;hm&#039; or code == &#039;hms&#039; or code == &#039;M&#039; or code == &#039;s&#039; then&lt;br /&gt;
		local days = floor(diff.age_days + extra_days)&lt;br /&gt;
		local inc_hour&lt;br /&gt;
		if wantround then&lt;br /&gt;
			if code == &#039;dh&#039; or code == &#039;h&#039; then&lt;br /&gt;
				if M &amp;gt;= 30 then&lt;br /&gt;
					inc_hour = true&lt;br /&gt;
				end&lt;br /&gt;
			elseif code == &#039;dhm&#039; or code == &#039;hm&#039; then&lt;br /&gt;
				if S &amp;gt;= 30 then&lt;br /&gt;
					M = M + 1&lt;br /&gt;
					if M &amp;gt;= 60 then&lt;br /&gt;
						M = 0&lt;br /&gt;
						inc_hour = true&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			elseif code == &#039;M&#039; then&lt;br /&gt;
				if S &amp;gt;= 30 then&lt;br /&gt;
					M = M + 1&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				-- Nothing needed because S is an integer.&lt;br /&gt;
			end&lt;br /&gt;
			if inc_hour then&lt;br /&gt;
				H = H + 1&lt;br /&gt;
				if H &amp;gt;= 24 then&lt;br /&gt;
					H = 0&lt;br /&gt;
					days = days + 1&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;dh&#039; or code == &#039;dhm&#039; or code == &#039;dhms&#039; then&lt;br /&gt;
			if code == &#039;dh&#039; then&lt;br /&gt;
				return days, H&lt;br /&gt;
			elseif code == &#039;dhm&#039; then&lt;br /&gt;
				return days, H, M&lt;br /&gt;
			else&lt;br /&gt;
				return days, H, M, S&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local hours = days * 24 + H&lt;br /&gt;
		if code == &#039;h&#039; then&lt;br /&gt;
			return hours&lt;br /&gt;
		elseif code == &#039;hm&#039; then&lt;br /&gt;
			return hours, M&lt;br /&gt;
		elseif code == &#039;M&#039; or code == &#039;s&#039; then&lt;br /&gt;
			M = hours * 60 + M&lt;br /&gt;
			if code == &#039;M&#039; then&lt;br /&gt;
				return M&lt;br /&gt;
			end&lt;br /&gt;
			return M * 60 + S&lt;br /&gt;
		end&lt;br /&gt;
		return hours, M, S&lt;br /&gt;
	end&lt;br /&gt;
	if wantround then&lt;br /&gt;
		local inc_hour&lt;br /&gt;
		if code == &#039;ymdh&#039; or code == &#039;ymwdh&#039; then&lt;br /&gt;
			if M &amp;gt;= 30 then&lt;br /&gt;
				inc_hour = true&lt;br /&gt;
			end&lt;br /&gt;
		elseif code == &#039;ymdhm&#039; or code == &#039;ymwdhm&#039; then&lt;br /&gt;
			if S &amp;gt;= 30 then&lt;br /&gt;
				M = M + 1&lt;br /&gt;
				if M &amp;gt;= 60 then&lt;br /&gt;
					M = 0&lt;br /&gt;
					inc_hour = true&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		elseif code == &#039;ymd&#039; or code == &#039;ymwd&#039; or code == &#039;yd&#039; or code == &#039;md&#039; then&lt;br /&gt;
			if H &amp;gt;= 12 then&lt;br /&gt;
				extra_days = extra_days + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if inc_hour then&lt;br /&gt;
			H = H + 1&lt;br /&gt;
			if H &amp;gt;= 24 then&lt;br /&gt;
				H = 0&lt;br /&gt;
				extra_days = extra_days + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local y, m, d = diff.years, diff.months, diff.days&lt;br /&gt;
	if extra_days &amp;gt; 0 then&lt;br /&gt;
		d = d + extra_days&lt;br /&gt;
		if d &amp;gt; 28 or code == &#039;yd&#039; then&lt;br /&gt;
			-- Recalculate in case have passed a month.&lt;br /&gt;
			diff = diff.date1 + extra_days - diff.date2&lt;br /&gt;
			y, m, d = diff.years, diff.months, diff.days&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if code == &#039;ymd&#039; then&lt;br /&gt;
		return y, m, d&lt;br /&gt;
	elseif code == &#039;yd&#039; then&lt;br /&gt;
		if y &amp;gt; 0 then&lt;br /&gt;
			-- It is known that diff.date1 &amp;gt; diff.date2.&lt;br /&gt;
			diff = diff.date1 - (diff.date2 + (y .. &#039;y&#039;))&lt;br /&gt;
		end&lt;br /&gt;
		return y, floor(diff.age_days)&lt;br /&gt;
	elseif code == &#039;md&#039; then&lt;br /&gt;
		return y * 12 + m, d&lt;br /&gt;
	elseif code == &#039;ym&#039; or code == &#039;m&#039; then&lt;br /&gt;
		if wantround then&lt;br /&gt;
			if d &amp;gt;= 16 then&lt;br /&gt;
				m = m + 1&lt;br /&gt;
				if m &amp;gt;= 12 then&lt;br /&gt;
					m = 0&lt;br /&gt;
					y = y + 1&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if code == &#039;ym&#039; then&lt;br /&gt;
			return y, m&lt;br /&gt;
		end&lt;br /&gt;
		return y * 12 + m&lt;br /&gt;
	elseif code == &#039;ymw&#039; then&lt;br /&gt;
		local weeks = floor(d/7)&lt;br /&gt;
		if wantround then&lt;br /&gt;
			local days = d % 7&lt;br /&gt;
			if days &amp;gt; 3 or (days == 3 and H &amp;gt;= 12) then&lt;br /&gt;
				weeks = weeks + 1&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return y, m, weeks&lt;br /&gt;
	elseif code == &#039;ymwd&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7&lt;br /&gt;
	elseif code == &#039;ymdh&#039; then&lt;br /&gt;
		return y, m, d, H&lt;br /&gt;
	elseif code == &#039;ymwdh&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7, H&lt;br /&gt;
	elseif code == &#039;ymdhm&#039; then&lt;br /&gt;
		return y, m, d, H, M&lt;br /&gt;
	elseif code == &#039;ymwdhm&#039; then&lt;br /&gt;
		return y, m, floor(d/7), d % 7, H, M&lt;br /&gt;
	end&lt;br /&gt;
	if code == &#039;y&#039; then&lt;br /&gt;
		if wantround and m &amp;gt;= 6 then&lt;br /&gt;
			y = y + 1&lt;br /&gt;
		end&lt;br /&gt;
		return y&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _diff_duration(diff, code, options)&lt;br /&gt;
	if type(options) ~= &#039;table&#039; then&lt;br /&gt;
		options = { round = options }&lt;br /&gt;
	end&lt;br /&gt;
	options.duration = true&lt;br /&gt;
	return _diff_age(diff, code, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Metatable for some operations on date differences.&lt;br /&gt;
diffmt = {  -- for forward declaration above&lt;br /&gt;
	__concat = function (lhs, rhs)&lt;br /&gt;
		return tostring(lhs) .. tostring(rhs)&lt;br /&gt;
	end,&lt;br /&gt;
	__tostring = function (self)&lt;br /&gt;
		return tostring(self.age_days)&lt;br /&gt;
	end,&lt;br /&gt;
	__index = function (self, key)&lt;br /&gt;
		local value&lt;br /&gt;
		if key == &#039;age_days&#039; then&lt;br /&gt;
			if rawget(self, &#039;partial&#039;) then&lt;br /&gt;
				local function jdz(date)&lt;br /&gt;
					return (date.partial and date.partial.first or date).jdz&lt;br /&gt;
				end&lt;br /&gt;
				value = jdz(self.date1) - jdz(self.date2)&lt;br /&gt;
			else&lt;br /&gt;
				value = self.date1.jdz - self.date2.jdz&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if value ~= nil then&lt;br /&gt;
			rawset(self, key, value)&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function DateDiff(date1, date2, options)  -- for forward declaration above&lt;br /&gt;
	-- Return a table with the difference between two dates (date1 - date2).&lt;br /&gt;
	-- The difference is negative if date1 is older than date2.&lt;br /&gt;
	-- Return nothing if invalid.&lt;br /&gt;
	-- If d = date1 - date2 then&lt;br /&gt;
	--     date1 = date2 + d&lt;br /&gt;
	-- If date1 &amp;gt;= date2 and the dates have no H:M:S time specified then&lt;br /&gt;
	--     date1 = date2 + (d.years..&#039;y&#039;) + (d.months..&#039;m&#039;) + d.days&lt;br /&gt;
	-- where the larger time units are added first.&lt;br /&gt;
	-- The result of Date(2015,1,x) + &#039;1m&#039; is Date(2015,2,28) for&lt;br /&gt;
	-- x = 28, 29, 30, 31. That means, for example,&lt;br /&gt;
	--     d = Date(2015,3,3) - Date(2015,1,31)&lt;br /&gt;
	-- gives d.years, d.months, d.days = 0, 1, 3 (excluding date1).&lt;br /&gt;
	if not (is_date(date1) and is_date(date2) and date1.calendar == date2.calendar) then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	local wantfill&lt;br /&gt;
	if type(options) == &#039;table&#039; then&lt;br /&gt;
		wantfill = options.fill&lt;br /&gt;
	end&lt;br /&gt;
	local isnegative = false&lt;br /&gt;
	local iszero = false&lt;br /&gt;
	if date1 &amp;lt; date2 then&lt;br /&gt;
		isnegative = true&lt;br /&gt;
		date1, date2 = date2, date1&lt;br /&gt;
	elseif date1 == date2 then&lt;br /&gt;
		iszero = true&lt;br /&gt;
	end&lt;br /&gt;
	-- It is known that date1 &amp;gt;= date2 (period is from date2 to date1).&lt;br /&gt;
	if date1.partial or date2.partial then&lt;br /&gt;
		-- Two partial dates might have timelines:&lt;br /&gt;
		---------------------A=================B--- date1 is from A to B inclusive&lt;br /&gt;
		--------C=======D-------------------------- date2 is from C to D inclusive&lt;br /&gt;
		-- date1 &amp;gt; date2 iff A &amp;gt; C (date1.partial.first &amp;gt; date2.partial.first)&lt;br /&gt;
		-- The periods can overlap (&#039;April 2001&#039; - &#039;2001&#039;):&lt;br /&gt;
		-------------A===B------------------------- A=2001-04-01  B=2001-04-30&lt;br /&gt;
		--------C=====================D------------ C=2001-01-01  D=2001-12-31&lt;br /&gt;
		if wantfill then&lt;br /&gt;
			date1, date2 = autofill(date1, date2)&lt;br /&gt;
		else&lt;br /&gt;
			local function zdiff(date1, date2)&lt;br /&gt;
				local diff = date1 - date2&lt;br /&gt;
				if diff.isnegative then&lt;br /&gt;
					return date1 - date1  -- a valid diff in case we call its methods&lt;br /&gt;
				end&lt;br /&gt;
				return diff&lt;br /&gt;
			end&lt;br /&gt;
			local function getdate(date, which)&lt;br /&gt;
				return date.partial and date.partial[which] or date&lt;br /&gt;
			end&lt;br /&gt;
			local maxdiff = zdiff(getdate(date1, &#039;last&#039;), getdate(date2, &#039;first&#039;))&lt;br /&gt;
			local mindiff = zdiff(getdate(date1, &#039;first&#039;), getdate(date2, &#039;last&#039;))&lt;br /&gt;
			local years, months&lt;br /&gt;
			if maxdiff.years == mindiff.years then&lt;br /&gt;
				years = maxdiff.years&lt;br /&gt;
				if maxdiff.months == mindiff.months then&lt;br /&gt;
					months = maxdiff.months&lt;br /&gt;
				else&lt;br /&gt;
					months = { mindiff.months, maxdiff.months }&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				years = { mindiff.years, maxdiff.years }&lt;br /&gt;
			end&lt;br /&gt;
			return setmetatable({&lt;br /&gt;
				date1 = date1,&lt;br /&gt;
				date2 = date2,&lt;br /&gt;
				partial = {&lt;br /&gt;
					years = years,&lt;br /&gt;
					months = months,&lt;br /&gt;
					maxdiff = maxdiff,&lt;br /&gt;
					mindiff = mindiff,&lt;br /&gt;
				},&lt;br /&gt;
				isnegative = isnegative,&lt;br /&gt;
				iszero = iszero,&lt;br /&gt;
				age = _diff_age,&lt;br /&gt;
				duration = _diff_duration,&lt;br /&gt;
			}, diffmt)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local y1, m1 = date1.year, date1.month&lt;br /&gt;
	local y2, m2 = date2.year, date2.month&lt;br /&gt;
	local years = y1 - y2&lt;br /&gt;
	local months = m1 - m2&lt;br /&gt;
	local d1 = date1.day + hms(date1)&lt;br /&gt;
	local d2 = date2.day + hms(date2)&lt;br /&gt;
	local days, time&lt;br /&gt;
	if d1 &amp;gt;= d2 then&lt;br /&gt;
		days = d1 - d2&lt;br /&gt;
	else&lt;br /&gt;
		months = months - 1&lt;br /&gt;
		-- Get days in previous month (before the &amp;quot;to&amp;quot; date) given December has 31 days.&lt;br /&gt;
		local dpm = m1 &amp;gt; 1 and days_in_month(y1, m1 - 1, date1.calendar) or 31&lt;br /&gt;
		if d2 &amp;gt;= dpm then&lt;br /&gt;
			days = d1 - hms(date2)&lt;br /&gt;
		else&lt;br /&gt;
			days = dpm - d2 + d1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if months &amp;lt; 0 then&lt;br /&gt;
		years = years - 1&lt;br /&gt;
		months = months + 12&lt;br /&gt;
	end&lt;br /&gt;
	days, time = math.modf(days)&lt;br /&gt;
	local H, M, S = h_m_s(time)&lt;br /&gt;
	return setmetatable({&lt;br /&gt;
		date1 = date1,&lt;br /&gt;
		date2 = date2,&lt;br /&gt;
		partial = false,  -- avoid index lookup&lt;br /&gt;
		years = years,&lt;br /&gt;
		months = months,&lt;br /&gt;
		days = days,&lt;br /&gt;
		hours = H,&lt;br /&gt;
		minutes = M,&lt;br /&gt;
		seconds = S,&lt;br /&gt;
		isnegative = isnegative,&lt;br /&gt;
		iszero = iszero,&lt;br /&gt;
		age = _diff_age,&lt;br /&gt;
		duration = _diff_duration,&lt;br /&gt;
	}, diffmt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	_current = current,&lt;br /&gt;
	_Date = Date,&lt;br /&gt;
	_days_in_month = days_in_month,&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Age&amp;diff=1333</id>
		<title>模組:Age</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E7%B5%84:Age&amp;diff=1333"/>
		<updated>2026-10-04T15:59:06Z</updated>

		<summary type="html">&lt;p&gt;DC：​建立內容為「-- Implement various &amp;quot;age of&amp;quot; and other date-related templates.  local _Date, _currentDate local function getExports(frame) 	-- Return objects exported from the date module or its sandbox. 	if not _Date then 		local sandbox = frame:getTitle():find(&amp;#039;sandbox&amp;#039;, 1, true) and &amp;#039;/sandbox&amp;#039; or &amp;#039;&amp;#039; 		local datemod = require(&amp;#039;Module:Date&amp;#039; .. sandbox) 		_Date = datemod._Date 		_currentDate = datemod._current 	end 	return _Date, _currentDate end  local Collection  -- a ta…」的新頁面&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;-- Implement various &amp;quot;age of&amp;quot; and other date-related templates.&lt;br /&gt;
&lt;br /&gt;
local _Date, _currentDate&lt;br /&gt;
local function getExports(frame)&lt;br /&gt;
	-- Return objects exported from the date module or its sandbox.&lt;br /&gt;
	if not _Date then&lt;br /&gt;
		local sandbox = frame:getTitle():find(&#039;sandbox&#039;, 1, true) and &#039;/sandbox&#039; or &#039;&#039;&lt;br /&gt;
		local datemod = require(&#039;Module:Date&#039; .. sandbox)&lt;br /&gt;
		_Date = datemod._Date&lt;br /&gt;
		_currentDate = datemod._current&lt;br /&gt;
	end&lt;br /&gt;
	return _Date, _currentDate&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local Collection  -- a table to hold items&lt;br /&gt;
Collection = {&lt;br /&gt;
	add = function (self, item)&lt;br /&gt;
		if item ~= nil then&lt;br /&gt;
			self.n = self.n + 1&lt;br /&gt;
			self[self.n] = item&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
	join = function (self, sep)&lt;br /&gt;
		return table.concat(self, sep)&lt;br /&gt;
	end,&lt;br /&gt;
	remove = function (self, pos)&lt;br /&gt;
		if self.n &amp;gt; 0 and (pos == nil or (0 &amp;lt; pos and pos &amp;lt;= self.n)) then&lt;br /&gt;
			self.n = self.n - 1&lt;br /&gt;
			return table.remove(self, pos)&lt;br /&gt;
		end&lt;br /&gt;
	end,&lt;br /&gt;
	sort = function (self, comp)&lt;br /&gt;
		table.sort(self, comp)&lt;br /&gt;
	end,&lt;br /&gt;
	new = function ()&lt;br /&gt;
		return setmetatable({n = 0}, Collection)&lt;br /&gt;
	end&lt;br /&gt;
}&lt;br /&gt;
Collection.__index = Collection&lt;br /&gt;
&lt;br /&gt;
local function stripToNil(text)&lt;br /&gt;
	-- If text is a string, return its trimmed content, or nil if empty.&lt;br /&gt;
	-- Otherwise return text (which may, for example, be nil).&lt;br /&gt;
	if type(text) == &#039;string&#039; then&lt;br /&gt;
		text = text:match(&#039;(%S.-)%s*$&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local yes = require(&#039;Module:Yesno&#039;)&lt;br /&gt;
&lt;br /&gt;
local function message(msg, id)&lt;br /&gt;
	-- Return formatted message text for an error or warning.&lt;br /&gt;
	local categories = {&lt;br /&gt;
		error = &#039;[[Category:Age模块错误]]&#039;,&lt;br /&gt;
		warning = &#039;[[Category:Age模块错误]]&#039;,  -- same as error until determine whether &#039;Age warning&#039; would be worthwhile&lt;br /&gt;
	}&lt;br /&gt;
	local a, b, category&lt;br /&gt;
	if id == &#039;warning&#039; then&lt;br /&gt;
		a = &#039;&amp;lt;sup&amp;gt;[&amp;lt;i&amp;gt;&#039;&lt;br /&gt;
		b = &#039;&amp;lt;/i&amp;gt;]&amp;lt;/sup&amp;gt;&#039;&lt;br /&gt;
	else&lt;br /&gt;
		a = &#039;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;错误：&#039;&lt;br /&gt;
		b = &#039;&amp;lt;/strong&amp;gt;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	if mw.title.getCurrentTitle():inNamespaces(0) then&lt;br /&gt;
		-- Category only in namespaces: 0=article.&lt;br /&gt;
		category = categories[id or &#039;error&#039;]&lt;br /&gt;
	end&lt;br /&gt;
	return&lt;br /&gt;
		a ..&lt;br /&gt;
		mw.text.nowiki(msg) ..&lt;br /&gt;
		b ..&lt;br /&gt;
		(category or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function formatNumber(number)&lt;br /&gt;
	-- Return the given number formatted with commas as group separators,&lt;br /&gt;
	-- given that the number is an integer.&lt;br /&gt;
	local numstr = tostring(number)&lt;br /&gt;
	local length = #numstr&lt;br /&gt;
	local places = Collection.new()&lt;br /&gt;
	local pos = 0&lt;br /&gt;
	repeat&lt;br /&gt;
		places:add(pos)&lt;br /&gt;
		pos = pos + 3&lt;br /&gt;
	until pos &amp;gt;= length&lt;br /&gt;
	places:add(length)&lt;br /&gt;
	local groups = Collection.new()&lt;br /&gt;
	for i = places.n, 2, -1 do&lt;br /&gt;
		local p1 = length - places[i] + 1&lt;br /&gt;
		local p2 = length - places[i - 1]&lt;br /&gt;
		groups:add(numstr:sub(p1, p2))&lt;br /&gt;
	end&lt;br /&gt;
	return groups:join(&#039;,&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function spellNumber(number, options, i)&lt;br /&gt;
	-- Return result of spelling number, or&lt;br /&gt;
	-- return number (as a string) if cannot spell it.&lt;br /&gt;
	-- i == 1 for the first number which can optionally start with an uppercase letter.&lt;br /&gt;
	number = tostring(number)&lt;br /&gt;
	return require(&#039;Module:ConvertNumeric&#039;).spell_number(&lt;br /&gt;
		number,&lt;br /&gt;
		nil,                       -- fraction numerator&lt;br /&gt;
		nil,                       -- fraction denominator&lt;br /&gt;
		i == 1 and options.upper,  -- true: &#039;One&#039; instead of &#039;one&#039;&lt;br /&gt;
		not options.us,            -- true: use &#039;and&#039; between tens/ones etc&lt;br /&gt;
		options.adj,               -- true: hyphenated&lt;br /&gt;
		options.ordinal            -- true: &#039;first&#039; instead of &#039;one&#039;&lt;br /&gt;
	) or number&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeSort(value, sortable)&lt;br /&gt;
	-- Return a sort key if requested.&lt;br /&gt;
	-- Assume value is a valid number which has not overflowed.&lt;br /&gt;
	if sortable == &#039;sortable_table&#039; or sortable == &#039;sortable_on&#039; or sortable == &#039;sortable_debug&#039; then&lt;br /&gt;
		local sortkey&lt;br /&gt;
		if value == 0 then&lt;br /&gt;
			sortkey = &#039;5000000000000000000&#039;&lt;br /&gt;
		else&lt;br /&gt;
			local mag = math.floor(math.log10(math.abs(value)) + 1e-14)&lt;br /&gt;
			local prefix&lt;br /&gt;
			if value &amp;gt; 0 then&lt;br /&gt;
				prefix = 7000 + mag&lt;br /&gt;
			else&lt;br /&gt;
				prefix = 2999 - mag&lt;br /&gt;
				value = value + 10^(mag+1)&lt;br /&gt;
			end&lt;br /&gt;
			sortkey = string.format(&#039;%d&#039;, prefix) .. string.format(&#039;%015.0f&#039;, math.floor(value * 10^(14-mag)))&lt;br /&gt;
		end&lt;br /&gt;
		local lhs, rhs&lt;br /&gt;
		if sortable == &#039;sortable_table&#039; then&lt;br /&gt;
			lhs = &#039;data-sort-value=&amp;quot;&#039;&lt;br /&gt;
			rhs = &#039;&amp;quot;|&#039;&lt;br /&gt;
		else&lt;br /&gt;
			lhs = sortable == &#039;sortable_debug&#039; and&lt;br /&gt;
				&#039;&amp;lt;span style=&amp;quot;border:1px solid;display:inline;&amp;quot; class=&amp;quot;sortkey&amp;quot;&amp;gt;&#039; or&lt;br /&gt;
				&#039;&amp;lt;span style=&amp;quot;display:none&amp;quot; class=&amp;quot;sortkey&amp;quot;&amp;gt;&#039;&lt;br /&gt;
			rhs = &#039;♠&amp;lt;/span&amp;gt;&#039;&lt;br /&gt;
		end&lt;br /&gt;
		return lhs .. sortkey .. rhs&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local translateParameters = {&lt;br /&gt;
	abbr = {&lt;br /&gt;
		off = &#039;abbr_off&#039;,&lt;br /&gt;
		on = &#039;abbr_on&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	disp = {&lt;br /&gt;
		age = &#039;disp_age&#039;,&lt;br /&gt;
		raw = &#039;disp_raw&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	format = {&lt;br /&gt;
		raw = &#039;format_raw&#039;,&lt;br /&gt;
		commas = &#039;format_commas&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	round = {&lt;br /&gt;
		on = &#039;on&#039;,&lt;br /&gt;
		yes = &#039;on&#039;,&lt;br /&gt;
		months = &#039;ym&#039;,&lt;br /&gt;
		weeks = &#039;ymw&#039;,&lt;br /&gt;
		days = &#039;ymd&#039;,&lt;br /&gt;
		hours = &#039;ymdh&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	sep = {&lt;br /&gt;
		comma = &#039;sep_comma&#039;,&lt;br /&gt;
		[&#039;,&#039;] = &#039;sep_comma&#039;,&lt;br /&gt;
		serialcomma = &#039;sep_serialcomma&#039;,&lt;br /&gt;
		space = &#039;sep_space&#039;,&lt;br /&gt;
	},&lt;br /&gt;
	show = {&lt;br /&gt;
		hide = { id = &#039;hide&#039; },&lt;br /&gt;
		y = { &#039;y&#039;, id = &#039;y&#039; },&lt;br /&gt;
		ym = { &#039;y&#039;, &#039;m&#039;, id = &#039;ym&#039; },&lt;br /&gt;
		ymd = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, id = &#039;ymd&#039; },&lt;br /&gt;
		ymw = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, id = &#039;ymw&#039; },&lt;br /&gt;
		ymwd = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, id = &#039;ymwd&#039; },&lt;br /&gt;
		yd = { &#039;y&#039;, &#039;d&#039;, id = &#039;yd&#039;, keepZero = true },&lt;br /&gt;
		m = { &#039;m&#039;, id = &#039;m&#039; },&lt;br /&gt;
		md = { &#039;m&#039;, &#039;d&#039;, id = &#039;md&#039; },&lt;br /&gt;
		w = { &#039;w&#039;, id = &#039;w&#039; },&lt;br /&gt;
		wd = { &#039;w&#039;, &#039;d&#039;, id = &#039;wd&#039; },&lt;br /&gt;
		h = { &#039;H&#039;, id = &#039;h&#039; },&lt;br /&gt;
		hm = { &#039;H&#039;, &#039;M&#039;, id = &#039;hm&#039; },&lt;br /&gt;
		hms = { &#039;H&#039;, &#039;M&#039;, &#039;S&#039;, id = &#039;hms&#039; },&lt;br /&gt;
		d = { &#039;d&#039;, id = &#039;d&#039; },&lt;br /&gt;
		dh = { &#039;d&#039;, &#039;H&#039;, id = &#039;dh&#039; },&lt;br /&gt;
		dhm = { &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;dhm&#039; },&lt;br /&gt;
		dhms = { &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, &#039;S&#039;, id = &#039;dhms&#039; },&lt;br /&gt;
		ymdh = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, &#039;H&#039;, id = &#039;ymdh&#039; },&lt;br /&gt;
		ymdhm = { &#039;y&#039;, &#039;m&#039;, &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;ymdhm&#039; },&lt;br /&gt;
		ymwdh = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, &#039;H&#039;, id = &#039;ymwdh&#039; },&lt;br /&gt;
		ymwdhm = { &#039;y&#039;, &#039;m&#039;, &#039;w&#039;, &#039;d&#039;, &#039;H&#039;, &#039;M&#039;, id = &#039;ymwdhm&#039; },&lt;br /&gt;
	},&lt;br /&gt;
	sortable = {&lt;br /&gt;
		off = false,&lt;br /&gt;
		on = &#039;sortable_on&#039;,&lt;br /&gt;
		table = &#039;sortable_table&#039;,&lt;br /&gt;
		debug = &#039;sortable_debug&#039;,&lt;br /&gt;
	},&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local spellOptions = {&lt;br /&gt;
	cardinal = {},&lt;br /&gt;
	Cardinal = { upper = true },&lt;br /&gt;
	cardinal_us = { us = true },&lt;br /&gt;
	Cardinal_us = { us = true, upper = true },&lt;br /&gt;
	ordinal = { ordinal = true },&lt;br /&gt;
	Ordinal = { ordinal = true, upper = true },&lt;br /&gt;
	ordinal_us = { ordinal = true, us = true },&lt;br /&gt;
	Ordinal_us = { ordinal = true, us = true, upper = true },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function dateExtract(frame)&lt;br /&gt;
	-- Return part of a date after performing an optional operation.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local parms = {}&lt;br /&gt;
	for i, v in ipairs(args) do&lt;br /&gt;
		parms[i] = v&lt;br /&gt;
	end&lt;br /&gt;
	if yes(args.fix) then&lt;br /&gt;
		table.insert(parms, &#039;fix&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if yes(args.partial) then&lt;br /&gt;
		table.insert(parms, &#039;partial&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local show = stripToNil(args.show) or &#039;dmy&#039;&lt;br /&gt;
	local date = Date(unpack(parms))&lt;br /&gt;
	if not date then&lt;br /&gt;
		if show == &#039;format&#039; then&lt;br /&gt;
			return &#039;error&#039;&lt;br /&gt;
		end&lt;br /&gt;
		return message(&#039;需要有效的日期&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local add = stripToNil(args.add)&lt;br /&gt;
	if add then&lt;br /&gt;
		for item in add:gmatch(&#039;%S+&#039;) do&lt;br /&gt;
			date = date + item&lt;br /&gt;
			if not date then&lt;br /&gt;
				return message(&#039;无法添加“&#039; .. item .. &#039;”&#039;)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local prefix, result&lt;br /&gt;
	local sortable = translateParameters.sortable[args.sortable]&lt;br /&gt;
	if sortable then&lt;br /&gt;
		local value = (date.partial and date.partial.first or date).jdz&lt;br /&gt;
		prefix = makeSort(value, sortable)&lt;br /&gt;
	end&lt;br /&gt;
	if show ~= &#039;hide&#039; then&lt;br /&gt;
		result = date[show]&lt;br /&gt;
		if result == nil then&lt;br /&gt;
			result = date:text(show)&lt;br /&gt;
		elseif type(result) == &#039;boolean&#039; then&lt;br /&gt;
			result = result and &#039;1&#039; or &#039;0&#039;&lt;br /&gt;
		else&lt;br /&gt;
			result = tostring(result)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return (prefix or &#039;&#039;) .. (result or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rangeJoin(range)&lt;br /&gt;
	-- Return text to be used between a range of ages.&lt;br /&gt;
	return range == &#039;dash&#039; and &#039;—&#039; or &#039;或&#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeText(values, components, names, options, noUpper)&lt;br /&gt;
	-- Return wikitext representing an age or duration.&lt;br /&gt;
	local text = Collection.new()&lt;br /&gt;
	local count = #values&lt;br /&gt;
	local sep = names.sep or &#039;&#039;&lt;br /&gt;
	for i, v in ipairs(values) do&lt;br /&gt;
		-- v is a number (say 4 for 4 years), or a table ({4,5} for 4 or 5 years).&lt;br /&gt;
		local islist = type(v) == &#039;table&#039;&lt;br /&gt;
		if (islist or v &amp;gt; 0) or (text.n == 0 and i == count) or (text.n &amp;gt; 0 and components.keepZero) then&lt;br /&gt;
			local fmt, vstr&lt;br /&gt;
			if options.spell then&lt;br /&gt;
				fmt = function(number)&lt;br /&gt;
					return spellNumber(number, options.spell, noUpper or i)&lt;br /&gt;
				end&lt;br /&gt;
			elseif i == 1 and options.format == &#039;format_commas&#039; then&lt;br /&gt;
				-- Numbers after the first should be small and not need formatting.&lt;br /&gt;
				fmt = formatNumber&lt;br /&gt;
			else&lt;br /&gt;
				fmt = tostring&lt;br /&gt;
			end&lt;br /&gt;
			if islist then&lt;br /&gt;
				vstr = fmt(v[1]) .. rangeJoin(options.range)&lt;br /&gt;
				noUpper = true&lt;br /&gt;
				vstr = vstr .. fmt(v[2])&lt;br /&gt;
			else&lt;br /&gt;
				vstr = fmt(v)&lt;br /&gt;
			end&lt;br /&gt;
			local name = names[components[i]]&lt;br /&gt;
			if name then&lt;br /&gt;
				local plural = names.plural&lt;br /&gt;
				if not plural or (islist and v[2] or v) == 1 then&lt;br /&gt;
					plural = &#039;&#039;&lt;br /&gt;
				end&lt;br /&gt;
				text:add(vstr .. sep .. name .. plural)&lt;br /&gt;
			else&lt;br /&gt;
				text:add(vstr)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local first, last&lt;br /&gt;
	-- hh mm ss&lt;br /&gt;
	if options.join == &#039;sep_space&#039; then&lt;br /&gt;
		first = &#039; &#039;&lt;br /&gt;
		last = &#039; &#039;&lt;br /&gt;
	-- hh时，mm分，ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_comma&#039; then&lt;br /&gt;
		first = &#039;，&#039;&lt;br /&gt;
		last = &#039;，&#039;&lt;br /&gt;
	-- hh时，mm分又ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_serialcomma&#039; then&lt;br /&gt;
		first = &#039;，&#039;&lt;br /&gt;
		last = text.n &amp;gt; 2 and (names.y == &#039;年&#039; and &#039;又&#039; or &#039;零&#039;) or &#039;，&#039;&lt;br /&gt;
	-- hh时mm分ss秒&lt;br /&gt;
	elseif options.join == &#039;sep_none&#039; then&lt;br /&gt;
		first = &#039;&#039;&lt;br /&gt;
		last = &#039;&#039;&lt;br /&gt;
	-- hh时mm分又ss秒&lt;br /&gt;
	else  -- &#039;sep_serial&#039;&lt;br /&gt;
		first = &#039;&#039;&lt;br /&gt;
		last = text.n &amp;gt; 2 and (names.y == &#039;年&#039; and &#039;又&#039; or &#039;零&#039;) or &#039;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	for i, v in ipairs(text) do&lt;br /&gt;
		if i &amp;lt; text.n then&lt;br /&gt;
			text[i] = v .. (i + 1 &amp;lt; text.n and first or last)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local sign = &#039;&#039;&lt;br /&gt;
	if options.isnegative then&lt;br /&gt;
		-- Do not display negative zero.&lt;br /&gt;
		if text.n &amp;gt; 1 or (text.n == 1 and text[1]:sub(1, 1) ~= &#039;0&#039; ) then&lt;br /&gt;
			if options.format == &#039;format_raw&#039; then&lt;br /&gt;
				sign = &#039;-&#039;  -- plain hyphen so result can be used in a calculation&lt;br /&gt;
			else&lt;br /&gt;
				sign = &#039;−&#039;  -- Unicode U+2212 MINUS SIGN&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return&lt;br /&gt;
		(options.prefix or &#039;&#039;) ..&lt;br /&gt;
		(options.extra or &#039;&#039;) ..&lt;br /&gt;
		sign ..&lt;br /&gt;
		text:join() ..&lt;br /&gt;
		(options.suffix or &#039;&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateDifference(parms)&lt;br /&gt;
	-- Return a formatted date difference using the given parameters&lt;br /&gt;
	-- which have been validated.&lt;br /&gt;
	local names = {&lt;br /&gt;
		abbr_off = {&lt;br /&gt;
			plural = &#039;&#039;,&lt;br /&gt;
			sep = &#039;&#039;,&lt;br /&gt;
			y = &#039;年&#039;,&lt;br /&gt;
			m = &#039;个月&#039;,&lt;br /&gt;
			w = &#039;周&#039;,&lt;br /&gt;
			d = &#039;天&#039;,&lt;br /&gt;
			H = &#039;小时&#039;,&lt;br /&gt;
			M = &#039;分&#039;,&lt;br /&gt;
			S = &#039;秒&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_on = {&lt;br /&gt;
			y = &#039;y&#039;,&lt;br /&gt;
			m = &#039;m&#039;,&lt;br /&gt;
			w = &#039;w&#039;,&lt;br /&gt;
			d = &#039;d&#039;,&lt;br /&gt;
			H = &#039;h&#039;,&lt;br /&gt;
			M = &#039;m&#039;,&lt;br /&gt;
			S = &#039;s&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_age = {&lt;br /&gt;
			plural = &#039;&#039;,&lt;br /&gt;
			sep = &#039;&#039;,&lt;br /&gt;
			y = &#039;岁&#039;,&lt;br /&gt;
			m = &#039;个月&#039;,&lt;br /&gt;
			w = &#039;周&#039;,&lt;br /&gt;
			d = &#039;天&#039;,&lt;br /&gt;
			H = &#039;小时&#039;,&lt;br /&gt;
			M = &#039;分&#039;,&lt;br /&gt;
			S = &#039;秒&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		abbr_raw = {},&lt;br /&gt;
	}&lt;br /&gt;
	local diff = parms.diff  -- must be a valid date difference&lt;br /&gt;
	local show = parms.show  -- may be nil; default is set below&lt;br /&gt;
	local abbr = parms.abbr or &#039;abbr_off&#039;&lt;br /&gt;
	local defaultJoin  -- 中文应该全为nil&lt;br /&gt;
	if abbr ~= &#039;abbr_off&#039; then&lt;br /&gt;
		defaultJoin = nil&lt;br /&gt;
	end&lt;br /&gt;
	if not show then&lt;br /&gt;
		show = &#039;ymd&#039;&lt;br /&gt;
		if parms.disp == &#039;disp_age&#039; then&lt;br /&gt;
			if diff.years &amp;lt; 3 then&lt;br /&gt;
				defaultJoin = nil&lt;br /&gt;
				if diff.years &amp;gt;= 1 then&lt;br /&gt;
					show = &#039;ym&#039;&lt;br /&gt;
				else&lt;br /&gt;
					show = &#039;md&#039;&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				show = &#039;y&#039;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if type(show) ~= &#039;table&#039; then&lt;br /&gt;
		show = translateParameters.show[show]&lt;br /&gt;
	end&lt;br /&gt;
	if parms.disp == &#039;disp_raw&#039; then&lt;br /&gt;
		defaultJoin = &#039;sep_space&#039;&lt;br /&gt;
		abbr = &#039;abbr_raw&#039;&lt;br /&gt;
	elseif parms.wantSc then&lt;br /&gt;
		defaultJoin = &#039;sep_serialcomma&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local diffOptions = {&lt;br /&gt;
		round = parms.round,&lt;br /&gt;
		duration = parms.wantDuration,&lt;br /&gt;
		range = parms.range and true or nil,&lt;br /&gt;
	}&lt;br /&gt;
	local prefix&lt;br /&gt;
	if parms.sortable then&lt;br /&gt;
		local value = diff.age_days + (parms.wantDuration and 1 or 0)  -- days and fraction of a day&lt;br /&gt;
		if diff.isnegative then&lt;br /&gt;
			value = -value&lt;br /&gt;
		end&lt;br /&gt;
		prefix = makeSort(value, parms.sortable)&lt;br /&gt;
	end&lt;br /&gt;
	local textOptions = {&lt;br /&gt;
		prefix = prefix,&lt;br /&gt;
		suffix = parms.suffix,  -- not currently used&lt;br /&gt;
		extra = parms.extra,&lt;br /&gt;
		format = parms.format,&lt;br /&gt;
		join = parms.sep or defaultJoin,&lt;br /&gt;
		isnegative = diff.isnegative,&lt;br /&gt;
		range = parms.range,&lt;br /&gt;
		spell = parms.spell,&lt;br /&gt;
	}&lt;br /&gt;
	if show.id == &#039;hide&#039; then&lt;br /&gt;
		return prefix or &#039;&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local values = { diff:age(show.id, diffOptions) }&lt;br /&gt;
	if values[1] then&lt;br /&gt;
		return makeText(values, show, names[abbr], textOptions)&lt;br /&gt;
	end&lt;br /&gt;
	if diff.partial then&lt;br /&gt;
		-- Handle a more complex range such as&lt;br /&gt;
		-- {{age_yd|20 Dec 2001|2003|range=yes}} → 1 year, 12 days or 2 years, 11 days&lt;br /&gt;
		local opt = {&lt;br /&gt;
			format = textOptions.format,&lt;br /&gt;
			join = textOptions.join,&lt;br /&gt;
			isnegative = textOptions.isnegative,&lt;br /&gt;
			spell = textOptions.spell,&lt;br /&gt;
		}&lt;br /&gt;
		return&lt;br /&gt;
			(textOptions.prefix or &#039;&#039;) ..&lt;br /&gt;
			makeText({ diff.partial.mindiff:age(show.id, diffOptions) }, show, names[abbr], opt) ..&lt;br /&gt;
			rangeJoin(textOptions.range) ..&lt;br /&gt;
			makeText({ diff.partial.maxdiff:age(show.id, diffOptions) }, show, names[abbr], opt, true) ..&lt;br /&gt;
			(textOptions.suffix or &#039;&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;此处不支持参数show=&#039; .. show.id)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getDates(frame, getopt)&lt;br /&gt;
	-- Parse template parameters and return one of:&lt;br /&gt;
	-- * date         (a date table, if single)&lt;br /&gt;
	-- * date1, date2 (two date tables, if not single)&lt;br /&gt;
	-- * text         (a string error message)&lt;br /&gt;
	-- A missing date is optionally replaced with the current date.&lt;br /&gt;
	-- If wantMixture is true, a missing date component is replaced&lt;br /&gt;
	-- from the current date, so can get a bizarre mixture of&lt;br /&gt;
	-- specified/current y/m/d as has been done by some &amp;quot;age&amp;quot; templates.&lt;br /&gt;
	-- Some results may be placed in table getopt.&lt;br /&gt;
	local Date, currentDate = getExports(frame)&lt;br /&gt;
	getopt = getopt or {}&lt;br /&gt;
	local function flagCurrent(text)&lt;br /&gt;
		-- This allows the calling template to detect if the current date has been used,&lt;br /&gt;
		-- that is, whether both dates have been entered in a template expecting two.&lt;br /&gt;
		-- For example, an infobox may want the age when an event occurred, not the current age.&lt;br /&gt;
		-- Don&#039;t bother detecting if wantMixture is used because not needed and it is a poor option.&lt;br /&gt;
		if not text then&lt;br /&gt;
			text = &#039;currentdate&#039;&lt;br /&gt;
			if getopt.flag == &#039;usesCurrent&#039; then&lt;br /&gt;
				getopt.usesCurrent = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return text&lt;br /&gt;
	end&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local fields = {}&lt;br /&gt;
	local isNamed = args.year or args.year1 or args.year2 or&lt;br /&gt;
		args.month or args.month1 or args.month2 or&lt;br /&gt;
		args.day or args.day1 or args.day2&lt;br /&gt;
	if isNamed then&lt;br /&gt;
		fields[1] = args.year1 or args.year&lt;br /&gt;
		fields[2] = args.month1 or args.month&lt;br /&gt;
		fields[3] = args.day1 or args.day&lt;br /&gt;
		fields[4] = args.year2&lt;br /&gt;
		fields[5] = args.month2&lt;br /&gt;
		fields[6] = args.day2&lt;br /&gt;
	else&lt;br /&gt;
		for i = 1, 6 do&lt;br /&gt;
			fields[i] = args[i]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local imax = 0&lt;br /&gt;
	for i = 1, 6 do&lt;br /&gt;
		fields[i] = stripToNil(fields[i])&lt;br /&gt;
		if fields[i] then&lt;br /&gt;
			imax = i&lt;br /&gt;
		end&lt;br /&gt;
		if getopt.omitZero and i % 3 ~= 1 then  -- omit zero months and days as unknown values but keep year 0 which is 1 BCE&lt;br /&gt;
			if tonumber(fields[i]) == 0 then&lt;br /&gt;
				fields[i] = nil&lt;br /&gt;
				getopt.partial = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local fix = getopt.fix and &#039;fix&#039; or &#039;&#039;&lt;br /&gt;
	local noDefault = imax == 0 and getopt.noMissing&lt;br /&gt;
	local partialText = getopt.partial and &#039;partial&#039; or &#039;&#039;&lt;br /&gt;
	local dates = {}&lt;br /&gt;
	if isNamed or imax &amp;gt;= 3 then&lt;br /&gt;
		local nrDates = getopt.single and 1 or 2&lt;br /&gt;
		if getopt.wantMixture then&lt;br /&gt;
			-- Cannot be partial since empty fields are set from current.&lt;br /&gt;
			local components = { &#039;year&#039;, &#039;month&#039;, &#039;day&#039; }&lt;br /&gt;
			for i = 1, nrDates * 3 do&lt;br /&gt;
				fields[i] = fields[i] or currentDate[components[i &amp;gt; 3 and i - 3 or i]]&lt;br /&gt;
			end&lt;br /&gt;
			for i = 1, nrDates do&lt;br /&gt;
				local index = i == 1 and 1 or 4&lt;br /&gt;
				dates[i] = Date(fields[index], fields[index+1], fields[index+2])&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			-- If partial dates are allowed, accept&lt;br /&gt;
			--     year only, or&lt;br /&gt;
			--     year and month only&lt;br /&gt;
			-- Do not accept year and day without a month because that makes no sense&lt;br /&gt;
			-- (and because, for example, Date(&#039;partial&#039;, 2001, nil, 12) sets day = nil, not 12).&lt;br /&gt;
			for i = 1, nrDates do&lt;br /&gt;
				local index = i == 1 and 1 or 4&lt;br /&gt;
				local y, m, d = fields[index], fields[index+1], fields[index+2]&lt;br /&gt;
				if (getopt.partial and y and (m or not d)) or (y and m and d) then&lt;br /&gt;
					dates[i] = Date(fix, partialText, y, m, d)&lt;br /&gt;
				elseif not y and not m and not d and not noDefault then&lt;br /&gt;
					dates[i] = Date(flagCurrent())&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	elseif not noDefault then&lt;br /&gt;
		getopt.textdates = true  -- have parsed each date from a single text field&lt;br /&gt;
		dates[1] = Date(fix, partialText, flagCurrent(fields[1]))&lt;br /&gt;
		if not getopt.single then&lt;br /&gt;
			dates[2] = Date(fix, partialText, flagCurrent(fields[2]))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not dates[1] then&lt;br /&gt;
		return message(&#039;需要有效的年月日&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if getopt.single then&lt;br /&gt;
		return dates[1]&lt;br /&gt;
	end&lt;br /&gt;
	if not dates[2] then&lt;br /&gt;
		return message(&#039;第二个日期应该是年月日&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return dates[1], dates[2]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function ageGeneric(frame)&lt;br /&gt;
	-- Return the result required by the specified template.&lt;br /&gt;
	-- Can use sortable=x where x = on/table/off/debug in any supported template.&lt;br /&gt;
	-- Some templates default to sortable=on but can be overridden.&lt;br /&gt;
	local name = frame.args.template&lt;br /&gt;
	if not name then&lt;br /&gt;
		return message(&#039;调用它的模板必须有“|template=x”参数，其中x是所需的操作&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local specs = {&lt;br /&gt;
		-- 重点！切勿随意更改！&lt;br /&gt;
		age_days = {                -- {{age in days}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_days_nts = {            -- {{age in days nts}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		duration_days = {           -- {{duration in days}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			duration = true,&lt;br /&gt;
		},&lt;br /&gt;
		duration_days_nts = {       -- {{duration in days nts}}&lt;br /&gt;
			show = &#039;d&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			duration = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_full_years = {          -- {{age}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			flag = &#039;usesCurrent&#039;,&lt;br /&gt;
			omitZero = true,&lt;br /&gt;
			range = &#039;no&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_full_years_nts = {      -- {{age nts}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_in_years = {            -- {{age in years}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			negative = &#039;error&#039;,&lt;br /&gt;
			range = &#039;dash&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_in_years_nts = {        -- {{age in years nts}}&lt;br /&gt;
			show = &#039;y&#039;,&lt;br /&gt;
			abbr = &#039;abbr_raw&#039;,&lt;br /&gt;
			negative = &#039;error&#039;,&lt;br /&gt;
			range = &#039;dash&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_infant = {              -- {{age for infant}}&lt;br /&gt;
			-- Do not set show because special processing is done later.&lt;br /&gt;
			abbr = &#039;abbr_off&#039;,&lt;br /&gt;
			disp = &#039;disp_age&#039;,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_m = {                   -- {{age in months}}&lt;br /&gt;
			show = &#039;m&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_w = {                   -- {{age in weeks}}&lt;br /&gt;
			show = &#039;w&#039;,&lt;br /&gt;
			disp = &#039;disp_raw&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_wd = {                  -- {{age in weeks and days}}&lt;br /&gt;
			show = &#039;wd&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_yd = {                  -- {{age in years and days}}&lt;br /&gt;
			show = &#039;yd&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_yd_nts = {              -- {{age in years and days nts}}&lt;br /&gt;
			show = &#039;yd&#039;,&lt;br /&gt;
			format = &#039;format_commas&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
			sortable = &#039;on&#039;,&lt;br /&gt;
			age = true,&lt;br /&gt;
		},&lt;br /&gt;
		age_ym = {                  -- {{age in years and months}}&lt;br /&gt;
			show = &#039;ym&#039;,&lt;br /&gt;
			sep = args.sep == &#039;and&#039; and &#039;sep_serialcomma&#039; or nil,&lt;br /&gt;
		},&lt;br /&gt;
		age_ymd = {                 -- {{age in years, months and days}}&lt;br /&gt;
			show = &#039;ymd&#039;,&lt;br /&gt;
			range = &#039;dash&#039;,&lt;br /&gt;
		},&lt;br /&gt;
		age_ymwd = {                -- {{age in years, months, weeks and days}}&lt;br /&gt;
			show = &#039;ymwd&#039;,&lt;br /&gt;
			wantMixture = true,&lt;br /&gt;
		},&lt;br /&gt;
	}&lt;br /&gt;
	local spec = specs[name]&lt;br /&gt;
	if not spec then&lt;br /&gt;
		return message(&#039;指定的模板名称无效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	if name == &#039;age_days&#039; then&lt;br /&gt;
		local su = stripToNil(args[&#039;show unit&#039;])&lt;br /&gt;
		if su then&lt;br /&gt;
			if su == &#039;abbr&#039; or su == &#039;full&#039; then&lt;br /&gt;
				spec.disp = nil&lt;br /&gt;
				spec.abbr = su == &#039;abbr&#039; and &#039;abbr_on&#039; or nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local partial, autofill&lt;br /&gt;
	local range = stripToNil(args.range) or spec.range&lt;br /&gt;
	if range then&lt;br /&gt;
		-- Suppose partial dates are used and age could be 11 or 12 years.&lt;br /&gt;
		-- &amp;quot;|range=&amp;quot; (empty value) has no effect (spec is used).&lt;br /&gt;
		-- &amp;quot;|range=yes&amp;quot; or spec.range == true sets range = true (gives &amp;quot;11或12&amp;quot;)&lt;br /&gt;
		-- &amp;quot;|range=dash&amp;quot; or spec.range == &#039;dash&#039; sets range = &#039;dash&#039; (gives &amp;quot;11—12&amp;quot;).&lt;br /&gt;
		-- &amp;quot;|range=no&amp;quot; or spec.range == &#039;no&#039; sets range = nil and fills each date in the diff (gives &amp;quot;12&amp;quot;).&lt;br /&gt;
		--     (&amp;quot;on&amp;quot; is equivalent to &amp;quot;yes&amp;quot;, and &amp;quot;off&amp;quot; is equivalent to &amp;quot;no&amp;quot;).&lt;br /&gt;
		-- &amp;quot;|range=OTHER&amp;quot; sets range = nil and rejects partial dates.&lt;br /&gt;
		range = ({ dash = &#039;dash&#039;, off = &#039;no&#039;, no = &#039;no&#039;, [true] = true })[range] or yes(range)&lt;br /&gt;
		if range then&lt;br /&gt;
			partial = true  -- accept partial dates with a possible age range for the result&lt;br /&gt;
			if range == &#039;no&#039; then&lt;br /&gt;
				autofill = true  -- missing month/day in first or second date are filled from other date or 1&lt;br /&gt;
				range = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local getopt = {&lt;br /&gt;
		fix = yes(args.fix),&lt;br /&gt;
		flag = stripToNil(args.flag) or spec.flag,&lt;br /&gt;
		omitZero = spec.omitZero,&lt;br /&gt;
		partial = partial,&lt;br /&gt;
		wantMixture = spec.wantMixture,&lt;br /&gt;
	}&lt;br /&gt;
	local date1, date2 = getDates(frame, getopt)&lt;br /&gt;
	if type(date1) == &#039;string&#039; then&lt;br /&gt;
		return date1&lt;br /&gt;
	end&lt;br /&gt;
	local useAge = spec.age&lt;br /&gt;
	if args.age ~= nil then&lt;br /&gt;
		useAge = yes(args.age, spec.age)&lt;br /&gt;
	end&lt;br /&gt;
	local format = stripToNil(args.format)&lt;br /&gt;
	local spell = spellOptions[format]&lt;br /&gt;
	if format then&lt;br /&gt;
		format = &#039;format_&#039; .. format&lt;br /&gt;
	elseif name == &#039;age_days&#039; and getopt.textdates then&lt;br /&gt;
		format = &#039;format_commas&#039;&lt;br /&gt;
	end&lt;br /&gt;
	local parms = {&lt;br /&gt;
		diff = date2:subtract(date1, { fill = autofill }),&lt;br /&gt;
		wantDuration = spec.duration or yes(args.duration),&lt;br /&gt;
		range = range,&lt;br /&gt;
		wantSc = yes(args.sc),&lt;br /&gt;
		show = args.show == &#039;hide&#039; and &#039;hide&#039; or spec.show,&lt;br /&gt;
		abbr = useAge and &#039;abbr_age&#039; or spec.abbr,&lt;br /&gt;
		disp = spec.disp,&lt;br /&gt;
		extra = (getopt.usesCurrent and format ~= &#039;format_raw&#039;) and &#039;&amp;lt;span class=&amp;quot;currentage&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&#039; or nil,&lt;br /&gt;
		format = format or spec.format,&lt;br /&gt;
		round = yes(args.round),&lt;br /&gt;
		sep = spec.sep,&lt;br /&gt;
		sortable = translateParameters.sortable[args.sortable or spec.sortable],&lt;br /&gt;
		spell = spell,&lt;br /&gt;
	}&lt;br /&gt;
	if (spec.negative or frame.args.negative) == &#039;error&#039; and parms.diff.isnegative then&lt;br /&gt;
		return message(&#039;第二个日期不应该在第一个日期之前&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	return dateDifference(parms)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function bda(frame)&lt;br /&gt;
	-- Implement [[Template:Birth date and age]].&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local options = { noMissing=true, single=true }&lt;br /&gt;
	local date = getDates(frame, options)&lt;br /&gt;
	if type(date) == &#039;string&#039; then&lt;br /&gt;
		return date  -- error text&lt;br /&gt;
	end&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local diff = Date(&#039;currentdate&#039;) - date&lt;br /&gt;
	if diff.isnegative or diff.years &amp;gt; 150 then&lt;br /&gt;
		return message(&#039;计算年龄所需的出生日期无效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local disp, show = &#039;disp_raw&#039;, &#039;y&#039;&lt;br /&gt;
	if diff.years &amp;lt; 2 then&lt;br /&gt;
		disp = &#039;disp_age&#039;&lt;br /&gt;
		if diff.years == 0 and diff.months == 0 then&lt;br /&gt;
			show = &#039;d&#039;&lt;br /&gt;
		else&lt;br /&gt;
			show = &#039;m&#039;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local result = &#039;%-Y年%B月%-d日&#039;&lt;br /&gt;
	result = &#039;（&amp;lt;span class=&amp;quot;bday&amp;quot;&amp;gt;%-Y-%m-%d&amp;lt;/span&amp;gt;) &amp;lt;/span&amp;gt;&#039; .. result&lt;br /&gt;
	result = &#039;&amp;lt;span style=&amp;quot;display:none&amp;quot;&amp;gt; &#039; ..&lt;br /&gt;
		date:text(result) ..&lt;br /&gt;
		&#039;&amp;lt;span class=&amp;quot;noprint ForceAgeToShow&amp;quot;&amp;gt; &#039; ..&lt;br /&gt;
		&#039;（&#039; ..&lt;br /&gt;
		dateDifference({&lt;br /&gt;
			diff = diff,&lt;br /&gt;
			show = show,&lt;br /&gt;
			abbr = &#039;abbr_off&#039;,&lt;br /&gt;
			disp = disp,&lt;br /&gt;
			sep = &#039;sep_space&#039;,&lt;br /&gt;
		}) ..&lt;br /&gt;
		&#039;）&amp;lt;/span&amp;gt;&#039;&lt;br /&gt;
	local warnings = tonumber(frame.args.warnings)&lt;br /&gt;
	if warnings and warnings &amp;gt; 0 then&lt;br /&gt;
		local good = {&lt;br /&gt;
			df = true,&lt;br /&gt;
			mf = true,&lt;br /&gt;
			day = true,&lt;br /&gt;
			day1 = true,&lt;br /&gt;
			month = true,&lt;br /&gt;
			month1 = true,&lt;br /&gt;
			year = true,&lt;br /&gt;
			year1 = true,&lt;br /&gt;
		}&lt;br /&gt;
		local invalid&lt;br /&gt;
		local imax = options.textdates and 1 or 3&lt;br /&gt;
		for k, _ in pairs(args) do&lt;br /&gt;
			if type(k) == &#039;number&#039; then&lt;br /&gt;
				if k &amp;gt; imax then&lt;br /&gt;
					invalid = tostring(k)&lt;br /&gt;
					break&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				if not good[k] then&lt;br /&gt;
					invalid = k&lt;br /&gt;
					break&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if invalid then&lt;br /&gt;
			result = result .. message(invalid .. &#039;参数无效&#039;, &#039;warning&#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateToGsd(frame)&lt;br /&gt;
	-- Implement [[Template:Gregorian serial date]].&lt;br /&gt;
	-- Return Gregorian serial date of the given date, or the current date.&lt;br /&gt;
	-- The returned value is negative for dates before 1 January 1 AD&lt;br /&gt;
	-- despite the fact that GSD is not defined for such dates.&lt;br /&gt;
	local date = getDates(frame, { wantMixture=true, single=true })&lt;br /&gt;
	if type(date) == &#039;string&#039; then&lt;br /&gt;
		return date&lt;br /&gt;
	end&lt;br /&gt;
	return tostring(date.gsd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function jdToDate(frame)&lt;br /&gt;
	-- Return formatted date from a Julian date.&lt;br /&gt;
	-- The result includes a time if the input includes a fraction.&lt;br /&gt;
	-- The word &#039;Julian&#039; is accepted for the Julian calendar.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local date = Date(&#039;juliandate&#039;, args[1], args[2])&lt;br /&gt;
	if date then&lt;br /&gt;
		return date:text()&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;需要有效的儒略历日期&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dateToJd(frame)&lt;br /&gt;
	-- Return Julian date (a number) from a date which may include a time,&lt;br /&gt;
	-- or the current date (&#039;currentdate&#039;) or current date and time (&#039;currentdatetime&#039;).&lt;br /&gt;
	-- The word &#039;Julian&#039; is accepted for the Julian calendar.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local date = Date(args[1], args[2], args[3], args[4], args[5], args[6], args[7])&lt;br /&gt;
	if date then&lt;br /&gt;
		return tostring(date.jd)&lt;br /&gt;
	end&lt;br /&gt;
	return message(&#039;需要有效的年/月/日或“currentdate”（当前）&#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function timeInterval(frame)&lt;br /&gt;
	-- Implement [[Template:Time interval]].&lt;br /&gt;
	-- There are two positional arguments: date1, date2.&lt;br /&gt;
	-- The default for each is the current date and time.&lt;br /&gt;
	-- Result is date2 - date1 formatted.&lt;br /&gt;
	local Date = getExports(frame)&lt;br /&gt;
	local args = frame:getParent().args&lt;br /&gt;
	local parms = {&lt;br /&gt;
		wantDuration = yes(args.duration),&lt;br /&gt;
		range = yes(args.range) or (args.range == &#039;dash&#039; and &#039;dash&#039; or nil),&lt;br /&gt;
		wantSc = yes(args.sc),&lt;br /&gt;
	}&lt;br /&gt;
	local fix = yes(args.fix) and &#039;fix&#039; or &#039;&#039;&lt;br /&gt;
	local date1 = Date(fix, &#039;partial&#039;, stripToNil(args[1]) or &#039;currentdatetime&#039;)&lt;br /&gt;
	if not date1 then&lt;br /&gt;
		return message(&#039;第一个参数中的开始日期无效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local date2 = Date(fix, &#039;partial&#039;, stripToNil(args[2]) or &#039;currentdatetime&#039;)&lt;br /&gt;
	if not date2 then&lt;br /&gt;
		return message(&#039;第二个参数中的结束日期无效&#039;)&lt;br /&gt;
	end&lt;br /&gt;
	parms.diff = date2 - date1&lt;br /&gt;
	for argname, translate in pairs(translateParameters) do&lt;br /&gt;
		local parm = stripToNil(args[argname])&lt;br /&gt;
		if parm then&lt;br /&gt;
			parm = translate[parm]&lt;br /&gt;
			if parm == nil then  -- test for nil because false is a valid setting&lt;br /&gt;
				return message(&#039;参数&#039; .. argname .. &#039;=&#039; .. args[argname] .. &#039;无效&#039;)&lt;br /&gt;
			end&lt;br /&gt;
			parms[argname] = parm&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if parms.round then&lt;br /&gt;
		local round = parms.round&lt;br /&gt;
		local show = parms.show&lt;br /&gt;
		if round ~= &#039;on&#039; then&lt;br /&gt;
			if show then&lt;br /&gt;
				if show.id ~= round then&lt;br /&gt;
					return message(&#039;参数show=&#039; .. args.show .. &#039;与round=&#039; .. args.round .. &#039;冲突&#039;)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				parms.show = translateParameters.show[round]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		parms.round = true&lt;br /&gt;
	end&lt;br /&gt;
	return dateDifference(parms)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	age_generic = ageGeneric,           -- can emulate several age templates&lt;br /&gt;
	birth_date_and_age = bda,           -- Template:Birth_date_and_age&lt;br /&gt;
	gsd = dateToGsd,                    -- Template:Gregorian_serial_date&lt;br /&gt;
	extract = dateExtract,              -- Template:Extract&lt;br /&gt;
	jd_to_date = jdToDate,              -- Template:?&lt;br /&gt;
	JULIANDAY = dateToJd,               -- Template:JULIANDAY&lt;br /&gt;
	time_interval = timeInterval,       -- Template:Time_interval&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E6%9D%BF:Age_in_years_and_days&amp;diff=1332</id>
		<title>模板:Age in years and days</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E6%9D%BF:Age_in_years_and_days&amp;diff=1332"/>
		<updated>2026-10-04T15:57:33Z</updated>

		<summary type="html">&lt;p&gt;DC：​&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;{{{{{|safesubst:}}}#invoke:age|age_generic|template=age_yd}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
{{documentation}}&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
	<entry>
		<id>https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E6%9D%BF:Age_in_years_and_days&amp;diff=1331</id>
		<title>模板:Age in years and days</title>
		<link rel="alternate" type="text/html" href="https://encyclo-sanctum.encyclato.org/index.php?title=%E6%A8%A1%E6%9D%BF:Age_in_years_and_days&amp;diff=1331"/>
		<updated>2026-10-04T15:57:03Z</updated>

		<summary type="html">&lt;p&gt;DC：​建立內容為「&amp;lt;includeonly&amp;gt;{{{{{♥|safesubst:}}}#invoke:age|age_generic|template=age_yd}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt; {{documentation}} &amp;lt;/noinclude&amp;gt;」的新頁面&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;includeonly&amp;gt;{{{{{♥|safesubst:}}}#invoke:age|age_generic|template=age_yd}}&amp;lt;/includeonly&amp;gt;&amp;lt;noinclude&amp;gt;&lt;br /&gt;
{{documentation}}&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>DC</name></author>
	</entry>
</feed>