Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Angr pukhlya/2
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} p.date_formatting = function( frame ) -- Unpacking date local date = frame.args.date or "Invalid entry" local format = frame.args.format or "" months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ["January"] = "01", ["February"] = "02", ["March"] = "03", ["April"] = "04", ["May"] = "05", ["June"] = "06", ["July"] = "07", ["August"] = "08", ["September"] = "09", ["October"] = "10", ["November"] = "11", ["December"] = "12"} local year, day = string.match(date, "%D*(%d*)%D*(%d*)%D*") local ans = "" if year ~= "" and day ~= "" then if tonumber(day) > 31 then if tonumber(year) <= 31 then day, year = year, day else ans = "Invalid entry" end end end local k = nil local month = "" for i = 1, #months do k = string.find(date, months[i]) if k == nil then k = string.find(date, string.lower(string.sub(months[i], 1, 1)) .. string.sub(months[i], 2)) end if k == nil then k = string.find(date, string.lower(string.sub(months[i], 1, 1)) .. string.sub(months[i], 2, 3)) end if k == nil then k = string.find(date, string.sub(months[i], 1, 1) .. string.sub(months[i], 2, 3)) end if k ~= nil then month = months[i] end end if day ~= "" and year ~= "" and month == "" and string.find(date, "[-,/]") ~= nil then day, month, year = string.match(date, "(%d+)[-, /](%d+)[-, /](%d+)") local a, b, c = day, month, year if tonumber(a) > 31 then year = a elseif tonumber(b) > 31 then year = b elseif tonumber(c) > 31 then year = c end if tonumber(a) > 12 and year ~= nil and year ~= a then day = a elseif tonumber(b) > 12 and year ~= nil and year ~= b then day = b elseif tonumber(c) > 12 and year ~= nil and year ~= c then day = c end if (year == a and day == b) or (year == b and day == a) then month = months[tonumber(c)] elseif (year == b and day == c) or (year == c and day == b) then month = months[a] elseif (year == a and day == c) or (year == c and day == a) then month = months[tonumber(b)] else day, month, year = a, months[tonumber(b)], c end end if month == "" and day == "" and year == "" then ans = "Invalid entry" else right = {} for i = 1, 12 do if i == 2 then if year % 400 == 0 or (year % 100 ~= 0 and year % 4 == 0) then right[i] = 29 else right[i] = 28 end elseif i <= 7 then right[i] = 30 + i % 2 else right[i] = 31 - i % 2 end end if right[tonumber(months[month])] ~= nil and day ~= "" then if right[tonumber(months[month])] < tonumber(day) then ans = "Invalid entry" end elseif month == "" and day ~= "" and year ~= "" and string.find(date, "%a") ~= nil then ans = "Invalid entry" end end --Formatting unpacked date local format_old = "" if day ~= "" and year ~= "" and month ~= "" then if string.find(date, ",") ~= nil then format_old = "mdy" elseif string.find(date, "[-,/]") ~= nil then format_old = "iso" else format_old = "dmy" end elseif year ~= "" and month ~= "" then format_old = "month and year" else format_old = "year" end local u_date = "" local dop = "" if format == "" then format = format_old end if ans ~= "Invalid entry" then if format == "mdy" then u_date = month .. " " .. day .. ", " .. year elseif format == "dmy" then u_date = day .. " " .. month .. " " .. year elseif format == "iso" then u_date = year .. "-" .. months[month] .. "-" .. day elseif format == "year" then u_date = year elseif format == "month and year" then u_date = month .. " " .. year else u_date = day .. " " .. month .. " " .. year end if string.find(date, "(uncertain)") ~= nil or string.find(date, "around") ~= nil then dop = "circa " end else u_date = ans end return dop .. u_date end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Angr pukhlya/2/doc
(
edit
)