https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&feed=atom&action=historyモジュール:ISOdate - 版の履歴2024-03-29T08:15:08Zこのウィキのこのページに関する変更履歴MediaWiki 1.39.6https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=48068&oldid=prevWikiSysop: 1版 をインポートしました2023-05-08T00:09:06Z<p>1版 をインポートしました</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="ja">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← 古い版</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">2023年5月8日 (月) 09:09時点における版</td>
</tr><tr><td colspan="2" class="diff-notice" lang="ja"><div class="mw-diff-empty">(相違点なし)</div>
</td></tr></table>WikiSysophttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=48067&oldid=prevbsd>Jarekt: code clean-up to break it into smaller pieces and retire unused parts2022-05-09T01:50:45Z<p>code clean-up to break it into smaller pieces and retire unused parts</p>
<a href="https://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=48067&oldid=41209">差分を表示</a>bsd>Jarekthttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=41209&oldid=prevWikiSysop: 1版 をインポートしました2020-01-08T10:37:54Z<p>1版 をインポートしました</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="ja">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← 古い版</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">2020年1月8日 (水) 19:37時点における版</td>
</tr>
<!-- diff cache key wiki-mw_:diff::1.12:old-41208:rev-41209 -->
</table>WikiSysophttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=41208&oldid=prevbsd>Jarekt: rename Module:Date to Module:DateI18n2019-04-13T21:40:12Z<p>rename Module:Date to Module:DateI18n</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="ja">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← 古い版</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">2019年4月14日 (日) 06:40時点における版</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">1行目:</td>
<td colspan="2" class="diff-lineno">1行目:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[ </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[ </div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> __ </ins> <ins style="font-weight: bold; text-decoration: none;">__ _ _ ___ ____ ___ _ _ </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> | \/ | ___ __| |_ _| | ___ _|_ _/ ___| / _ \ __| | __ _| |_ ___ </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> | |\/| |/ _ \ / _` | | | | |/ _ (_)| |\___ \| | | |/ _` |/ _` | __/ _ \</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> | | | | (_) | (_| | |_| | | __/_ | | ___) | |_| | (_| | (_| | || __/</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> |_| |_|\___/ \__,_|\__,_|_|\___(_)___|____/ \___/ \__,_|\__,_|\__\___|</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> </ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This module is intended for processing of date strings.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This module is intended for processing of date strings.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l9">9行目:</td>
<td colspan="2" class="diff-lineno">14行目:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* User:Parent5446 - original version of the function mimicking template:ISOdate</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* User:Parent5446 - original version of the function mimicking template:ISOdate</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l18">18行目:</td>
<td colspan="2" class="diff-lineno">22行目:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- === Dependencies ======================</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- === Dependencies ======================</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- =======================================</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- =======================================</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>local D = require('Module:<del style="font-weight: bold; text-decoration: none;">Date</del>')</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>local D = require('Module:<ins style="font-weight: bold; text-decoration: none;">DateI18n</ins>')</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[</div></td></tr>
</table>bsd>Jarekthttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=38853&oldid=prevWikiSysop: 1版2018-04-12T00:15:03Z<p>1版</p>
<p><b>新規ページ</b></p><div>--[[ <br />
<br />
This module is intended for processing of date strings.<br />
<br />
Please do not modify this code without applying the changes first at Module:ISOdate/sandbox and testing <br />
at Module:ISOdate/sandbox/testcases and Module talk:ISOdate/sandbox/testcases.<br />
<br />
Authors and maintainers:<br />
* User:Parent5446 - original version of the function mimicking template:ISOdate<br />
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear<br />
<br />
]]<br />
<br />
<br />
local p = {}<br />
<br />
-- =======================================<br />
-- === Dependencies ======================<br />
-- =======================================<br />
local D = require('Module:Date')<br />
<br />
--[[<br />
ISOyear<br />
<br />
This function returns year part of date string.<br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOyear|target_string}}<br />
<br />
Parameters<br />
1: The date string <br />
<br />
Error Handling:<br />
If the string does not look like it contain the year than the function will not return anything.<br />
That is the preferred treatment for the template:Creator which is the main (only?) template calling it.<br />
]]<br />
function p.ISOyear( frame )<br />
return p._ISOyear( frame.args[1] )<br />
end<br />
<br />
function p._ISOyear( input )<br />
if not input then<br />
return ''<br />
end<br />
input = mw.text.trim( input )<br />
<br />
-- if empty string then return it<br />
if input == "" then<br />
return input<br />
end<br />
<br />
-- if number then return it<br />
if tonumber( input ) then<br />
return mw.ustring.format( '%04i', input )<br />
end<br />
<br />
-- otherwise use regular expression match<br />
input = mw.ustring.match( input, '^+?(-?%d%d?%d?%d?)-' )<br />
if input and tonumber( input ) then<br />
return mw.ustring.format( '%04i', input )<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
--[[<br />
ISOdate<br />
<br />
This function is the core part of the ISOdate template. <br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOdate|target_string|lang=}}<br />
<br />
Parameters:<br />
1: The date string <br />
lang: The language to display it in<br />
form: Language format (genitive, etc.) for some languages<br />
class: CSS class for the <time> node<br />
<br />
Error Handling:<br />
If the string does not look like it contain the proper ISO date than the function will return the original string.<br />
<br />
That is the preferred treatment for the template:Information (and similar templates) which calling it.<br />
]]<br />
function p.ISOdate(frame)<br />
local datestr, succeded<br />
local args = frame.args<br />
if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then <br />
args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language <br />
end<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(args[1]),<br />
args.lang, -- language<br />
args.case or '', -- allows to specify grammatical case for the month for languages that use them<br />
args.class or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
args.trim_year or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
return datestr<br />
end<br />
<br />
function p._ISOdate(datestr, lang, case, class, trim_year)<br />
<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
local patterns = {<br />
-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2<br />
-- date and time can be separated by space or "T" and there could be a "Z" on the end indicating "Zulu" time zone<br />
{dlen=6, tail=7, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)"}, <br />
{dlen=6, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$"}, <br />
-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2<br />
-- (if one knows hour and minute than it was probably after a year 1000)<br />
{dlen=5, tail=6, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)"},<br />
{dlen=5, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$"},<br />
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2<br />
{dlen=3, tail=4, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},<br />
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits<br />
-- (want to avoit converting to dates strings like 10-5 = 5<br />
{dlen=2, tail=3, regexp="^+?(%d%d%d%d?)-(%d%d)(%s.+)"}, <br />
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits<br />
{dlen=2, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)$"}, <br />
-- string starts with a number -> it has to be 3 or 4 digit long to be a year<br />
{dlen=1, tail=2, regexp="^+?(%d%d%d%d?)(%s.+)"}, <br />
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year<br />
{dlen=1, tail=0, regexp="^+?(%d%d?%d?%d?)$"},<br />
}<br />
<br />
-- create datevec based on which variables are provided<br />
local datevec, tail, formatNum<br />
datevec, tail, formatNum = p.test_date_formats(datestr or '', patterns)<br />
if datevec[1]=='' or datevec[1]==nil then<br />
-- quickly return if datestr does not look like date (it could be a template)<br />
return datestr, false<br />
end<br />
<br />
-- call p._Date function to format date string<br />
local succeded, datestr2<br />
succeded, datestr2 = pcall( D._Date, datevec, lang, case, class, trim_year)<br />
if succeded and datestr2~='' then<br />
return mw.text.trim( datestr2 .. tail), true<br />
else -- in case of errors return the original string<br />
return datestr, false<br />
end <br />
end<br />
<br />
function p.ISOdate_extended(frame)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
<br />
local datestr, succeded<br />
local args = frame.args<br />
if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then <br />
args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language <br />
end<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(args[1]),<br />
args.lang, -- language<br />
args.case or '', -- allows to specify grammatical case for the month for languages that use them<br />
args.class or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
args.trim_year or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
if succeded then<br />
return datestr<br />
end<br />
<br />
local patterns = {<br />
-- Exended set of recognized formats: like MM/DD/YYYY<br />
{dlen=3, tail=4, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)%s(%w+)%s(%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%w+)%s(%d%d?),%s(%d%d%d%d)$"},<br />
}<br />
<br />
local datevec, tail, formatNum, category = ''<br />
datevec, tail, formatNum = p.test_date_formats(frame.args[1], patterns)<br />
if formatNum==1 or formatNum==2 then<br />
vec = datevec;<br />
if tonumber(datevec[1])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[2], datevec[1] )<br />
category = '[[Category:Date in DD/MM/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
elseif tonumber(datevec[2])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[1], datevec[2] )<br />
category = '[[Category:Date in MM/DD/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
end<br />
elseif (formatNum==3 or formatNum==4) and (datevec[3]=='' or datevec[3]~=nil) then<br />
local str = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )<br />
local vec = {str:match( "^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$" )}<br />
if vec and vec[1]~=nil then<br />
frame.args[1] = string.format('%04i-%02i-%02i', vec[1], vec[2], vec[3] )<br />
category = '[[Category:Date in word format]]'<br />
return p.ISOdate(frame);<br />
end<br />
end <br />
return datestr<br />
end<br />
<br />
function p.test_date_formats(datestr, patterns)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
<br />
local datevec = {'','','','','',''}<br />
local tail = ''<br />
local vec, pat<br />
local formatNum = 0<br />
for i, pat in ipairs( patterns ) do<br />
vec = {datestr:match( pat.regexp )}<br />
if vec and vec[1]~=nil then<br />
for j=1,pat.dlen do<br />
datevec[j] = vec[j]<br />
end<br />
if pat.tail>0 and vec[pat.tail]~=nil then<br />
tail = mw.ustring.gsub(' ' .. vec[pat.tail], ' +', ' ')<br />
end<br />
formatNum = i<br />
break<br />
end<br />
end<br />
return datevec, tail, formatNum<br />
end<br />
<br />
return p</div>WikiSysophttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=36129&oldid=prevWikiSysop: 1版2016-06-06T08:20:17Z<p>1版</p>
<p><b>新規ページ</b></p><div>--[[ <br />
<br />
This module is intended for processing of date strings.<br />
<br />
Please do not modify this code without applying the changes first at Module:ISOdate/sandbox and testing <br />
at Module:ISOdate/sandbox/testcases and Module talk:ISOdate/sandbox/testcases.<br />
<br />
Authors and maintainers:<br />
* User:Parent5446 - original version of the function mimicking template:ISOdate<br />
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear<br />
<br />
]]<br />
<br />
<br />
local p = {}<br />
<br />
-- =======================================<br />
-- === Dependencies ======================<br />
-- =======================================<br />
local D = require('Module:Date')<br />
<br />
--[[<br />
ISOyear<br />
<br />
This function returns year part of date string.<br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOyear|target_string}}<br />
<br />
Parameters<br />
1: The date string <br />
<br />
Error Handling:<br />
If the string does not look like it contain the year than the function will not return anything.<br />
That is the preferred treatment for the template:Creator which is the main (only?) template calling it.<br />
]]<br />
function p.ISOyear( frame )<br />
local input = frame.args[1]<br />
if not input then<br />
input = frame.args["s"]<br />
end<br />
input = mw.text.trim( input )<br />
<br />
-- if empty string then return it<br />
if input == "" then<br />
return input<br />
end<br />
<br />
-- if number then return it<br />
if tonumber( input ) then<br />
return mw.ustring.format( '%04i', input )<br />
end<br />
<br />
-- otherwise use regular expression match<br />
input = mw.ustring.match( input, '^+?(-?%d%d?%d?%d?)-' )<br />
if input then<br />
return mw.ustring.format( '%04i', input )<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
--[[<br />
ISOdate<br />
<br />
This function is the core part of the ISOdate template. <br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOdate|target_string|lang=}}<br />
<br />
Parameters:<br />
1: The date string <br />
lang: The language to display it in<br />
form: Language format (genitive, etc.) for some languages<br />
class: CSS class for the <time> node<br />
<br />
Error Handling:<br />
If the string does not look like it contain the proper ISO date than the function will return the original string.<br />
<br />
That is the preferred treatment for the template:Information (and similar templates) which calling it.<br />
]]<br />
function p.ISOdate(frame)<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
frame.args["case"] or '', -- allows to specify grammatical case for the month for languages that use them<br />
frame.args["class"] or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
frame.args["trim_year"] or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
return datestr<br />
end<br />
<br />
function p._ISOdate(datestr, lang, case, class, trim_year)<br />
<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
local patterns = {<br />
-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2<br />
-- date and time can be separated by space or "T" and there could be a "Z" on the end indicating "Zulu" time zone<br />
{dlen=6, tail=7, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)"}, <br />
{dlen=6, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$"}, <br />
-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2<br />
-- (if one knows hour and minute than it was probably after a year 1000)<br />
{dlen=5, tail=6, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)"},<br />
{dlen=5, tail=0, regexp="^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$"},<br />
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2<br />
{dlen=3, tail=4, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},<br />
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits<br />
-- (want to avoit converting to dates strings like 10-5 = 5<br />
{dlen=2, tail=3, regexp="^+?(%d%d%d%d?)-(%d%d)(%s.+)"}, <br />
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits<br />
{dlen=2, tail=0, regexp="^+?(%d%d?%d?%d?)-(%d%d?)$"}, <br />
-- string starts with a number -> it has to be 3 or 4 digit long to be a year<br />
{dlen=1, tail=2, regexp="^+?(%d%d%d%d?)(%s.+)"}, <br />
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year<br />
{dlen=1, tail=0, regexp="^+?(%d%d?%d?%d?)$"},<br />
}<br />
<br />
-- create datevec based on which variables are provided<br />
local datevec, tail, formatNum<br />
datevec, tail, formatNum = p.test_date_formats(datestr, patterns)<br />
if datevec[1]=='' or datevec[1]==nil then<br />
-- quickly return if datestr does not look like date (it could be a template)<br />
return datestr, false<br />
end<br />
<br />
-- call p._Date function to format date string<br />
local succeded, datestr2<br />
succeded, datestr2 = pcall( D._Date, datevec, lang, case, class, trim_year)<br />
if succeded and datestr2~='' then<br />
return mw.text.trim( datestr2 .. tail), true<br />
else -- in case of errors return the original string<br />
return datestr, false<br />
end <br />
end<br />
<br />
function p.ISOdate_extended(frame)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
frame.args["case"] or '', -- allows to specify grammatical case for the month for languages that use them<br />
frame.args["class"] or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
frame.args["trim_year"] or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
if succeded then<br />
return datestr<br />
end<br />
<br />
local patterns = {<br />
-- Exended set of recognized formats: like MM/DD/YYYY<br />
{dlen=3, tail=4, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)%s(%w+)%s(%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%w+)%s(%d%d?),%s(%d%d%d%d)$"},<br />
}<br />
<br />
local datevec, tail, formatNum, category = ''<br />
datevec, tail, formatNum = p.test_date_formats(frame.args[1], patterns)<br />
if formatNum==1 or formatNum==2 then<br />
vec = datevec;<br />
if tonumber(datevec[1])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[2], datevec[1] )<br />
category = '[[Category:Date in DD/MM/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
elseif tonumber(datevec[2])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[1], datevec[2] )<br />
category = '[[Category:Date in MM/DD/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
end<br />
elseif (formatNum==3 or formatNum==4) and (datevec[3]=='' or datevec[3]~=nil) then<br />
local str = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )<br />
local vec = {str:match( "^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$" )}<br />
if vec and vec[1]~=nil then<br />
frame.args[1] = string.format('%04i-%02i-%02i', vec[1], vec[2], vec[3] )<br />
category = '[[Category:Date in word format]]'<br />
return p.ISOdate(frame);<br />
end<br />
end <br />
return datestr<br />
end<br />
<br />
function p.test_date_formats(datestr, patterns)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
<br />
local datevec = {'','','','','',''}<br />
local tail = ''<br />
local vec, pat<br />
local formatNum = 0<br />
for i, pat in ipairs( patterns ) do<br />
vec = {datestr:match( pat.regexp )}<br />
if vec and vec[1]~=nil then<br />
for j=1,pat.dlen do<br />
datevec[j] = vec[j]<br />
end<br />
if pat.tail>0 and vec[pat.tail]~=nil then<br />
tail = mw.ustring.gsub(' ' .. vec[pat.tail], ' +', ' ')<br />
end<br />
formatNum = i<br />
break<br />
end<br />
end<br />
return datevec, tail, formatNum<br />
end<br />
<br />
return p</div>WikiSysophttps://bsd.neuroinf.jp/w/index.php?title=%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB:ISOdate&diff=29099&oldid=prevWikiSysop: 1版2015-03-09T14:29:26Z<p>1版</p>
<p><b>新規ページ</b></p><div>--[[ <br />
<br />
This module is intended for processing of date strings.<br />
<br />
Please do not modify this code without applying the changes first at Module:ISOdate/sandbox and testing <br />
at Module:ISOdate/sandbox/testcases and Module talk:ISOdate/sandbox/testcases.<br />
<br />
Authors and maintainers:<br />
* User:Parent5446 - original version of the function mimicking template:ISOdate<br />
* User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear<br />
<br />
]]<br />
<br />
<br />
local p = {}<br />
<br />
-- =======================================<br />
-- === Dependencies ======================<br />
-- =======================================<br />
local D = require('Module:Date')<br />
<br />
--[[<br />
ISOyear<br />
<br />
This function returns year part of date string.<br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOyear|target_string}}<br />
<br />
Parameters<br />
1: The date string <br />
<br />
Error Handling:<br />
If the string does not look like it contain the year than the function will not return anything.<br />
That is the preferred treatment for the template:Creator which is the main (only?) template calling it.<br />
]]<br />
function p.ISOyear( frame )<br />
local input = frame.args[1]<br />
if not input then<br />
input = frame.args["s"]<br />
end<br />
input = mw.text.trim( input )<br />
<br />
-- if empty string then return it<br />
if input == "" then<br />
return input<br />
end<br />
<br />
-- if number then return it<br />
if tonumber( input ) then<br />
return mw.ustring.format( '%04i', input )<br />
end<br />
<br />
-- otherwise use regular expression match<br />
input = mw.ustring.match( input, '^(-?%d%d?%d?%d?)-' )<br />
if input then<br />
return mw.ustring.format( '%04i', input )<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
--[[<br />
ISOdate<br />
<br />
This function is the core part of the ISOdate template. <br />
<br />
Usage:<br />
{{#invoke:ISOdate|ISOdate|target_string|lang=}}<br />
<br />
Parameters:<br />
1: The date string <br />
lang: The language to display it in<br />
form: Language format (genitive, etc.) for some languages<br />
class: CSS class for the <time> node<br />
<br />
Error Handling:<br />
If the string does not look like it contain the proper ISO date than the function will return the original string.<br />
<br />
That is the preferred treatment for the template:Information (and similar templates) which calling it.<br />
]]<br />
function p.ISOdate(frame)<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
frame.args["case"] or '', -- allows to specify grammatical case for the month for languages that use them<br />
frame.args["class"] or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
frame.args["trim_year"] or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
return datestr<br />
end<br />
<br />
function p._ISOdate(datestr, lang, case, class, trim_year)<br />
<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
local patterns = {<br />
-- strings starting with YYYY-MM-DD HH:MM:SS. Year 4 digits (if we know seconds than it was within the last 100 years), the rest 1-2<br />
-- date and time can be separated by space or "T" and there could be a "Z" on the end indicating "Zulu" time zone<br />
{dlen=6, tail=7, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)"}, <br />
{dlen=6, tail=0, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$"}, <br />
-- strings starting with YYYY-MM-DD HH:MM. Year 4 digits, the rest 1-2<br />
-- (if one knows hour and minute than it was probably after a year 1000)<br />
{dlen=5, tail=6, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)"},<br />
{dlen=5, tail=0, regexp="^(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$"},<br />
-- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2<br />
{dlen=3, tail=4, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$"},<br />
-- strings starting with YYYY-MM. Year 3-4 digits, month 2 digits<br />
-- (want to avoit converting to dates strings like 10-5 = 5<br />
{dlen=2, tail=3, regexp="^(%d%d%d%d?)-(%d%d)(%s.+)"}, <br />
-- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits<br />
{dlen=2, tail=0, regexp="^(%d%d?%d?%d?)-(%d%d?)$"}, <br />
-- string starts with a number -> it has to be 3 or 4 digit long to be a year<br />
{dlen=1, tail=2, regexp="^(%d%d%d%d?)(%s.+)"}, <br />
-- if whole string is a number (1-4 digit long) than it will be interpreted as a year<br />
{dlen=1, tail=0, regexp="^(%d%d?%d?%d?)$"},<br />
}<br />
<br />
-- create datevec based on which variables are provided<br />
local datevec, tail, formatNum<br />
datevec, tail, formatNum = p.test_date_formats(datestr, patterns)<br />
if datevec[1]=='' or datevec[1]==nil then<br />
-- quickly return if datestr does not look like date (it could be a template)<br />
return datestr, false<br />
end<br />
<br />
-- call p._Date function to format date string<br />
local succeded, datestr2<br />
succeded, datestr2 = pcall( D._Date, datevec, lang, case, class, trim_year)<br />
if succeded and datestr2~='' then<br />
return mw.text.trim( datestr2 .. tail), true<br />
else -- in case of errors return the original string<br />
return datestr, false<br />
end <br />
end<br />
<br />
function p.ISOdate_extended(frame)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
-- regexp hints:<br />
-- 1) Strings starting with "^" and ending with "$" indicate whole string match<br />
-- 2) optional tail part copied as-is and following the main parsed part of the date have to be separated from the date by a whitespace, so "(\s.+)?"<br />
<br />
local datestr, succeded<br />
datestr, succeded = p._ISOdate(<br />
mw.text.trim(frame.args[1]),<br />
frame.args["lang"], -- language<br />
frame.args["case"] or '', -- allows to specify grammatical case for the month for languages that use them<br />
frame.args["class"] or 'dtstart', -- allows to set the html class of the time node where the date is included. <br />
frame.args["trim_year"] or '100-999' -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is <br />
)<br />
if succeded then<br />
return datestr<br />
end<br />
<br />
local patterns = {<br />
-- Exended set of recognized formats: like MM/DD/YYYY<br />
{dlen=3, tail=4, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)(%s.+)"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%d%d?)%s(%w+)%s(%d%d%d%d)$"},<br />
{dlen=3, tail=0, regexp="^(%w+)%s(%d%d?),%s(%d%d%d%d)$"},<br />
}<br />
<br />
local datevec, tail, formatNum, category = ''<br />
datevec, tail, formatNum = p.test_date_formats(frame.args[1], patterns)<br />
if formatNum==1 or formatNum==2 then<br />
vec = datevec;<br />
if tonumber(datevec[1])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[2], datevec[1] )<br />
category = '[[Category:Date in DD/MM/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
elseif tonumber(datevec[2])>12 then<br />
frame.args[1] = string.format('%04i-%02i-%02i', datevec[3], datevec[1], datevec[2] )<br />
category = '[[Category:Date in MM/DD/YYYY format]]'<br />
return mw.text.trim( p.ISOdate(frame) .. tail);<br />
end<br />
elseif (formatNum==3 or formatNum==4) and (datevec[3]=='' or datevec[3]~=nil) then<br />
local str = mw.getCurrentFrame():callParserFunction( "#time", { 'Y-m-d', datestr} )<br />
local vec = {str:match( "^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$" )}<br />
if vec and vec[1]~=nil then<br />
frame.args[1] = string.format('%04i-%02i-%02i', vec[1], vec[2], vec[3] )<br />
category = '[[Category:Date in word format]]'<br />
return p.ISOdate(frame);<br />
end<br />
end <br />
return datestr<br />
end<br />
<br />
function p.test_date_formats(datestr, patterns)<br />
-- pattern: regexp - regular expresion to test; dlen - number of date elements; tail = which element is a "tail" if any<br />
<br />
local datevec = {'','','','','',''}<br />
local tail = ''<br />
local vec, pat<br />
local formatNum = 0<br />
for i, pat in ipairs( patterns ) do<br />
vec = {datestr:match( pat.regexp )}<br />
if vec and vec[1]~=nil then<br />
for j=1,pat.dlen do<br />
datevec[j] = vec[j]<br />
end<br />
if pat.tail>0 and vec[pat.tail]~=nil then<br />
tail = mw.ustring.gsub(' ' .. vec[pat.tail], ' +', ' ')<br />
end<br />
formatNum = i<br />
break<br />
end<br />
end<br />
return datevec, tail, formatNum<br />
end<br />
<br />
return p</div>WikiSysop