https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AParsedate Module:Parsedate - Revision history 2025-06-04T04:36:16Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.3 https://en.wikipedia.org/w/index.php?title=Module:Parsedate&diff=570586213&oldid=prev RexxS: RexxS moved page Module:/Parsedate to Module:Parsedate without leaving a redirect: accidental '/' char at start 2013-08-28T21:24:06Z <p>RexxS moved page <a href="/w/index.php?title=Module:/Parsedate&amp;action=edit&amp;redlink=1" class="new" title="Module:/Parsedate (page does not exist)">Module:/Parsedate</a> to <a href="/wiki/Module:Parsedate" title="Module:Parsedate">Module:Parsedate</a> without leaving a redirect: accidental &#039;/&#039; char at start</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 21:24, 28 August 2013</td> </tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div> </td></tr></table> RexxS https://en.wikipedia.org/w/index.php?title=Module:Parsedate&diff=570585986&oldid=prev RexxS: create a module to parse dates to help date templates that could allow freeform entry 2013-08-28T21:22:05Z <p>create a module to parse dates to help date templates that could allow freeform entry</p> <p><b>New page</b></p><div>-- Helper functions for [[Template:Start date]]<br /> -- This will accept a start_date returning a string that:<br /> -- for a valid date, wraps a hidden copy of the date in ISO format in a microformat<br /> -- returns start_date<br /> -- See Module:Age for other date functions<br /> <br /> local p = {}<br /> <br /> -- This parses a valid date string into a Lua date table and returns a hidden microformat<br /> -- Only valid for dates after 31 A.D.<br /> <br /> p.parse_date = function(frame)<br /> local strdate = mw.text.trim(frame.args[1] or &quot;&quot;)<br /> local invalid = false<br /> local wrd = {}<br /> local num = {} -- this is a list of indices of wrd where the value is a number &lt; 32<br /> local yr = {} -- this is a list of indices of wrd where the value is a number &gt; 31<br /> local mth = {} -- this is a list of indices of wrd where the value is an alphabetical month<br /> <br /> for w in string.gmatch(strdate, &quot;%w+&quot;) do<br /> -- catch numbers like &#039;27th&#039;<br /> local found1, found2 = string.find(w, &quot;%d+&quot;)<br /> if found1 then w = string.sub(w, found1, found2) end<br /> -- now we can store what we found<br /> wrd[#wrd+1] = w<br /> if tonumber(w) then<br /> if tonumber(w) &lt; 32 then num[#num+1] = #wrd else yr[#yr+1] = #wrd end<br /> end<br /> local s = string.sub(w, 1, 3) -- the first 3 chars of w<br /> local f1 = string.find(&quot;Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec&quot;, s, 1, true)<br /> if f1 then<br /> mth[#mth+1] = #wrd<br /> wrd[#wrd] = (f1 + 3)/4 -- replace Jan with 1, Feb with 2, etc.<br /> end<br /> end<br /> <br /> -- at this point #wrd contains the number of words and numbers and wrd contains the words and numbers<br /> -- num is an index of day or numeric month candidates<br /> -- yr is an index of year candidates<br /> -- mth is an index of alphabetic month candidates<br /> <br /> -- let&#039;s take out the garbage<br /> if not yr[1] then invalid = true end -- no year<br /> if not num[1] then invalid = true end -- no day<br /> if not mth[1] then<br /> -- no alpha month:<br /> if not num[2] then<br /> invalid = true -- no month<br /> else<br /> -- two numbers, but:<br /> if not yr[1] then<br /> invalid = true -- no year<br /> else<br /> -- two numbers and a year, but:<br /> if yr[1] &gt; num[1] then invalid = true end -- year is not first, so date not in yyyy--mm--dd format<br /> end<br /> end<br /> end<br /> <br /> local msg -- the output string<br /> if invalid then<br /> msg = strdate<br /> else<br /> -- if we have an alpha month, then it&#039;s either dmy or mdy. Otherwise it may be yyyy-mm-dd:<br /> local ymddate<br /> local dt = {}<br /> if mth[1] then<br /> -- str_date contains an alpha month, so dmy or mdy work the same now.<br /> -- Put the first occurrence of each into the date table:<br /> dt.year = wrd[yr[1]]<br /> dt.month = wrd[mth[1]]<br /> dt.day = wrd[num[1]]<br /> else<br /> -- yyyymmdd has to have numeric month before numeric day<br /> dt.year = wrd[yr[1]]<br /> dt.month = wrd[num[1]]<br /> dt.day = wrd[num[2]]<br /> end<br /> ymddate = os.date(&quot;%Y-%m-%d&quot;, os.time(dt))<br /> msg = &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#160;(&lt;span class=&quot;bday dtstart published updated&quot;&gt;&#039; .. ymddate .. &#039;&lt;/span&gt;)&lt;/span&gt;&#039; .. strdate<br /> end<br /> return msg<br /> end<br /> <br /> return p</div> RexxS