https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AISOdate Module:ISOdate - Revision history 2025-05-29T02:38:50Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.2 https://en.wikipedia.org/w/index.php?title=Module:ISOdate&diff=1221385236&oldid=prev Pppery: Protected "Module:ISOdate" ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) 2024-04-29T16:35:41Z <p>Protected &quot;<a href="/wiki/Module:ISOdate" title="Module:ISOdate">Module:ISOdate</a>&quot; ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <tr class="diff-title" lang="en"> <td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:35, 29 April 2024</td> </tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div> </td></tr></table> Pppery https://en.wikipedia.org/w/index.php?title=Module:ISOdate&diff=879890634&oldid=prev Mike Peel: Protected "Module:ISOdate": High-risk Lua module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) 2019-01-24T01:40:44Z <p>Protected &quot;<a href="/wiki/Module:ISOdate" title="Module:ISOdate">Module:ISOdate</a>&quot;: <a href="/wiki/Wikipedia:High-risk_templates" title="Wikipedia:High-risk templates">High-risk Lua module</a> ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <tr class="diff-title" lang="en"> <td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 01:40, 24 January 2019</td> </tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div> </td></tr></table> Mike Peel https://en.wikipedia.org/w/index.php?title=Module:ISOdate&diff=858614274&oldid=prev RexxS: use internationalised date module 2018-09-08T12:48:39Z <p>use internationalised date module</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="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 12:48, 8 September 2018</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 18:</td> <td colspan="2" class="diff-lineno">Line 18:</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>')<ins style="font-weight: bold; text-decoration: none;"> -- the enwp version of c:Module:Date</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> RexxS https://en.wikipedia.org/w/index.php?title=Module:ISOdate&diff=858493489&oldid=prev Mike Peel: Recreate, copy from commons (previous version was deleted as unused, but there's a plan to use this in WikidataIB now) 2018-09-07T15:41:17Z <p>Recreate, copy from commons (previous version was deleted as unused, but there&#039;s a plan to use this in WikidataIB now)</p> <p><b>New page</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(&#039;Module:Date&#039;)<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 &#039;&#039;<br /> end<br /> input = mw.text.trim( input )<br /> <br /> -- if empty string then return it<br /> if input == &quot;&quot; then<br /> return input<br /> end<br /> <br /> -- if number then return it<br /> if tonumber( input ) then<br /> return mw.ustring.format( &#039;%04i&#039;, input )<br /> end<br /> <br /> -- otherwise use regular expression match<br /> input = mw.ustring.match( input, &#039;^+?(-?%d%d?%d?%d?)-&#039; )<br /> if input and tonumber( input ) then<br /> return mw.ustring.format( &#039;%04i&#039;, input )<br /> else<br /> return &#039;&#039;<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 &lt;time&gt; 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( &quot;int&quot;, &quot;lang&quot; ) -- get user&#039;s chosen language <br /> end<br /> datestr, succeded = p._ISOdate(<br /> mw.text.trim(args[1]),<br /> args.lang, -- language<br /> args.case or &#039;&#039;, -- allows to specify grammatical case for the month for languages that use them<br /> args.class or &#039;dtstart&#039;, -- allows to set the html class of the time node where the date is included. <br /> args.trim_year or &#039;100-999&#039; -- 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 &quot;tail&quot; if any<br /> -- regexp hints:<br /> -- 1) Strings starting with &quot;^&quot; and ending with &quot;$&quot; 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 &quot;(\s.+)?&quot;<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 &quot;T&quot; and there could be a &quot;Z&quot; on the end indicating &quot;Zulu&quot; time zone<br /> {dlen=6, tail=7, regexp=&quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?(%s.*)&quot;}, <br /> {dlen=6, tail=0, regexp=&quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?):(%d%d?)Z?$&quot;}, <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=&quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)(%s.+)&quot;},<br /> {dlen=5, tail=0, regexp=&quot;^+?(%d%d%d%d)-(%d%d?)-(%d%d?)[ T](%d%d?):(%d%d?)$&quot;},<br /> -- strings starting with YYYY-MM-DD. Year 1-4 digits, the rest 1-2<br /> {dlen=3, tail=4, regexp=&quot;^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)(%s.+)&quot;},<br /> {dlen=3, tail=0, regexp=&quot;^+?(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$&quot;},<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=&quot;^+?(%d%d%d%d?)-(%d%d)(%s.+)&quot;}, <br /> -- if whole string is in YYYY-MM form: If Year 1-4 digits, month 1-2 digits<br /> {dlen=2, tail=0, regexp=&quot;^+?(%d%d?%d?%d?)-(%d%d?)$&quot;}, <br /> -- string starts with a number -&gt; it has to be 3 or 4 digit long to be a year<br /> {dlen=1, tail=2, regexp=&quot;^+?(%d%d%d%d?)(%s.+)&quot;}, <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=&quot;^+?(%d%d?%d?%d?)$&quot;},<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 &#039;&#039;, patterns)<br /> if datevec[1]==&#039;&#039; 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~=&#039;&#039; 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 &quot;tail&quot; if any<br /> -- regexp hints:<br /> -- 1) Strings starting with &quot;^&quot; and ending with &quot;$&quot; 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 &quot;(\s.+)?&quot;<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( &quot;int&quot;, &quot;lang&quot; ) -- get user&#039;s chosen language <br /> end<br /> datestr, succeded = p._ISOdate(<br /> mw.text.trim(args[1]),<br /> args.lang, -- language<br /> args.case or &#039;&#039;, -- allows to specify grammatical case for the month for languages that use them<br /> args.class or &#039;dtstart&#039;, -- allows to set the html class of the time node where the date is included. <br /> args.trim_year or &#039;100-999&#039; -- 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=&quot;^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)(%s.+)&quot;},<br /> {dlen=3, tail=0, regexp=&quot;^(%d%d?)[-./](%d%d?)[-./](%d%d%d%d)$&quot;},<br /> {dlen=3, tail=0, regexp=&quot;^(%d%d?)%s(%w+)%s(%d%d%d%d)$&quot;},<br /> {dlen=3, tail=0, regexp=&quot;^(%w+)%s(%d%d?),%s(%d%d%d%d)$&quot;},<br /> }<br /> <br /> local datevec, tail, formatNum, category = &#039;&#039;<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])&gt;12 then<br /> frame.args[1] = string.format(&#039;%04i-%02i-%02i&#039;, datevec[3], datevec[2], datevec[1] )<br /> category = &#039;[[Category:Date in DD/MM/YYYY format]]&#039;<br /> return mw.text.trim( p.ISOdate(frame) .. tail);<br /> elseif tonumber(datevec[2])&gt;12 then<br /> frame.args[1] = string.format(&#039;%04i-%02i-%02i&#039;, datevec[3], datevec[1], datevec[2] )<br /> category = &#039;[[Category:Date in MM/DD/YYYY format]]&#039;<br /> return mw.text.trim( p.ISOdate(frame) .. tail);<br /> end<br /> elseif (formatNum==3 or formatNum==4) and (datevec[3]==&#039;&#039; or datevec[3]~=nil) then<br /> local str = mw.getCurrentFrame():callParserFunction( &quot;#time&quot;, { &#039;Y-m-d&#039;, datestr} )<br /> local vec = {str:match( &quot;^(%d%d?%d?%d?)-(%d%d?)-(%d%d?)$&quot; )}<br /> if vec and vec[1]~=nil then<br /> frame.args[1] = string.format(&#039;%04i-%02i-%02i&#039;, vec[1], vec[2], vec[3] )<br /> category = &#039;[[Category:Date in word format]]&#039;<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 &quot;tail&quot; if any<br /> <br /> local datevec = {&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;&#039;}<br /> local tail = &#039;&#039;<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&gt;0 and vec[pat.tail]~=nil then<br /> tail = mw.ustring.gsub(&#039; &#039; .. vec[pat.tail], &#039; +&#039;, &#039; &#039;)<br /> end<br /> formatNum = i<br /> break<br /> end<br /> end<br /> return datevec, tail, formatNum<br /> end<br /> <br /> return p</div> Mike Peel