https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AParsedateModule:Parsedate - Revision history2025-06-04T04:36:16ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.3https://en.wikipedia.org/w/index.php?title=Module:Parsedate&diff=570586213&oldid=prevRexxS: RexxS moved page Module:/Parsedate to Module:Parsedate without leaving a redirect: accidental '/' char at start2013-08-28T21:24:06Z<p>RexxS moved page <a href="/w/index.php?title=Module:/Parsedate&action=edit&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 '/' 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>RexxShttps://en.wikipedia.org/w/index.php?title=Module:Parsedate&diff=570585986&oldid=prevRexxS: create a module to parse dates to help date templates that could allow freeform entry2013-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 "")<br />
local invalid = false<br />
local wrd = {}<br />
local num = {} -- this is a list of indices of wrd where the value is a number < 32<br />
local yr = {} -- this is a list of indices of wrd where the value is a number > 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, "%w+") do<br />
-- catch numbers like '27th'<br />
local found1, found2 = string.find(w, "%d+")<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) < 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("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", 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'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] > 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'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("%Y-%m-%d", os.time(dt))<br />
msg = '<span style="display:none">&#160;(<span class="bday dtstart published updated">' .. ymddate .. '</span>)</span>' .. strdate<br />
end<br />
return msg<br />
end<br />
<br />
return p</div>RexxS