<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FRexxS%2FDateData</id>
	<title>Module:Sandbox/RexxS/DateData - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FRexxS%2FDateData"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/RexxS/DateData&amp;action=history"/>
	<updated>2026-05-24T03:21:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/RexxS/DateData&amp;diff=146068&amp;oldid=prev</id>
		<title>imported&gt;RexxS: just return the object</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/RexxS/DateData&amp;diff=146068&amp;oldid=prev"/>
		<updated>2015-06-08T00:13:23Z</updated>

		<summary type="html">&lt;p&gt;just return the object&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Helper functions for [[Template:Start date]]&lt;br /&gt;
-- This will accept a start_date returning a string that:&lt;br /&gt;
-- for a valid date, wraps a hidden copy of the date in ISO format in a microformat&lt;br /&gt;
-- returns start_date&lt;br /&gt;
-- See Module:Age for other date functions&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- This parses a date string into a Lua date table&lt;br /&gt;
p.parse_date = function(frame)&lt;br /&gt;
  local strdate = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;)&lt;br /&gt;
  local invalid = false&lt;br /&gt;
  local wrd = {}&lt;br /&gt;
  local num = {} -- this is a list of indexes of wrd where the value is a number &amp;lt; 32&lt;br /&gt;
  local yr = {}  -- this is a list of indexes of wrd where the value is a number &amp;gt; 31&lt;br /&gt;
  local mth = {} -- this is a list of indexes of wrd where the value is a month&lt;br /&gt;
&lt;br /&gt;
  for w in string.gmatch(strdate, &amp;quot;%w+&amp;quot;) do&lt;br /&gt;
    -- catch numbers like &amp;#039;27th&amp;#039;&lt;br /&gt;
    local found1, found2 = string.find(w, &amp;quot;%d+&amp;quot;)&lt;br /&gt;
    if found1 then w = string.sub(w, found1, found2) end&lt;br /&gt;
    -- now we can store what we found&lt;br /&gt;
    wrd[#wrd+1] = w&lt;br /&gt;
    if tonumber(w) then&lt;br /&gt;
      if tonumber(w) &amp;lt; 32 then num[#num+1] = #wrd else yr[#yr+1] = #wrd end&lt;br /&gt;
    end&lt;br /&gt;
    local s = string.sub(w, 1, 3) -- the first 3 chars of w&lt;br /&gt;
    local f1 = string.find(&amp;quot;Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec&amp;quot;, s, 1, true)&lt;br /&gt;
    if f1 then&lt;br /&gt;
      mth[#mth+1] = #wrd&lt;br /&gt;
      wrd[#wrd] = (f1 + 3)/4 -- replace Jan with 1, Feb with 2, etc.&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  -- at this point #wrd contains the number of words and numbers and wrd contains the words and numbers&lt;br /&gt;
  -- num is an index of day or numeric month candidates&lt;br /&gt;
  -- yr is an index of year candidates&lt;br /&gt;
  -- mth is an index of alphabetic month candidates&lt;br /&gt;
&lt;br /&gt;
  -- this part is for debugging purposes:&lt;br /&gt;
  local msg = #wrd .. &amp;quot; word(s)&amp;lt;br /&amp;gt;&amp;quot;&lt;br /&gt;
  local n=1&lt;br /&gt;
  local y=1&lt;br /&gt;
  local m=1&lt;br /&gt;
  for i = 1, #wrd do&lt;br /&gt;
    msg = msg .. wrd[i]&lt;br /&gt;
    if i == yr[y] then&lt;br /&gt;
      msg = msg .. &amp;quot; &amp;lt;- Year&amp;quot;&lt;br /&gt;
      y = y+1&lt;br /&gt;
    end&lt;br /&gt;
    if i == num[n] then&lt;br /&gt;
      msg = msg .. &amp;quot; &amp;lt;- Number&amp;quot;&lt;br /&gt;
      n = n+1&lt;br /&gt;
    end&lt;br /&gt;
    if i == mth[m] then&lt;br /&gt;
      msg = msg .. &amp;quot; &amp;lt;- Month&amp;quot;&lt;br /&gt;
      m = m+1&lt;br /&gt;
    end&lt;br /&gt;
    msg = msg .. &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
  -- debugging stuff finishes here.&lt;br /&gt;
&lt;br /&gt;
  --  let&amp;#039;s take out the garbage&lt;br /&gt;
  if not yr[1] then invalid = true end -- no year&lt;br /&gt;
  if not num[1] then invalid = true end -- no day&lt;br /&gt;
  if not mth[1] then&lt;br /&gt;
    -- no alpha month:&lt;br /&gt;
    if not num[2] then&lt;br /&gt;
      invalid = true -- no month&lt;br /&gt;
    else&lt;br /&gt;
      -- two numbers, but:&lt;br /&gt;
      if not yr[1] then&lt;br /&gt;
        invalid = true -- no year&lt;br /&gt;
      else&lt;br /&gt;
      -- two numbers and a year, but:&lt;br /&gt;
        if yr[1] &amp;gt; num[1] then invalid = true end -- year is not first, so date not in yyyy--mm--dd format&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  if invalid then&lt;br /&gt;
    msg = msg .. &amp;quot;invalid date&amp;lt;br /&amp;gt;&amp;quot;&lt;br /&gt;
    msg = msg .. strdate&lt;br /&gt;
  else&lt;br /&gt;
    -- if we have an alpha month, then it&amp;#039;s either dmy or mdy. Otherwise it may be yyyy-mm-dd:&lt;br /&gt;
    local ymddate&lt;br /&gt;
    local dt = {}&lt;br /&gt;
    if mth[1] then&lt;br /&gt;
      -- dmy or mdy work the same now&lt;br /&gt;
      dt.year = wrd[yr[1]]&lt;br /&gt;
      dt.month = wrd[mth[1]]&lt;br /&gt;
      dt.day = wrd[num[1]]&lt;br /&gt;
    else&lt;br /&gt;
      -- yyyymmdd has numeric month before numeric day&lt;br /&gt;
      dt.year = wrd[yr[1]]&lt;br /&gt;
      dt.month = wrd[num[1]]&lt;br /&gt;
      dt.day = wrd[num[2]]&lt;br /&gt;
    end&lt;br /&gt;
    ymddate = os.date(&amp;quot;%Y-%m-%d&amp;quot;, os.time(dt))&lt;br /&gt;
    msg = msg .. ymddate .. &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;&lt;br /&gt;
    msg = msg .. &amp;#039;&amp;lt;span style=&amp;quot;display:none&amp;quot;&amp;gt;&amp;amp;#160;(&amp;lt;span class=&amp;quot;bday dtstart published updated&amp;quot;&amp;gt;&amp;#039; .. ymddate .. &amp;#039;&amp;lt;/span&amp;gt;)&amp;lt;/span&amp;gt;&amp;#039; .. strdate&lt;br /&gt;
  end&lt;br /&gt;
  return msg&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- call with {{#invoke:Sandbox/RexxS/DateData|FormatDate|&amp;lt;datestring&amp;gt;|&amp;lt;format&amp;gt;}}&lt;br /&gt;
p.FormatDate = function(frame)&lt;br /&gt;
	local langcode = mw.language.getContentLanguage()&lt;br /&gt;
	local strdate = mw.text.trim(frame.args[1] or &amp;quot;+2015-06-08T01:15:30Z&amp;quot;)&lt;br /&gt;
	local strformat = mw.text.trim(frame.args[2] or &amp;quot;j F Y&amp;quot;)&lt;br /&gt;
	return langcode:formatDate(strformat, strdate)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;RexxS</name></author>
	</entry>
</feed>