Module:Sandbox/RexxS/Dates

This is an old revision of this page, as edited by RexxS (talk | contribs) at 16:35, 11 November 2018 (test functions related to dates). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
--[[
test functions related to dates
-]]

local p = {}

local function leapd(y)
	if y % 1000 == 0 then return 29 end
	if y % 100 == 0 then return 28 end
	if y% 4 == 0 then return 29 end
	return 28
end

local days_in_month = { 31, leapd(y), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

local function day_try( d, m, y)
	if d <= days_in_month[m] then return "Valid" else return "Invalid" end
end

function p.dayTry(frame)
	local date = frame.args.date or mw.text.trim(frame.args[1] or "")
	local d, y, m = date:match("(%d+)%D+(%d+)"), date:match("%a+")
	return day_try(d, m, y)
end
	
return p