Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/MrSpecjal/Dates
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!
p = {} p.extractDate = function (frame) local date = frame.args.date or "invalid value" local format = frame.args.format or "recognize format" local output = "" if(date == "invalid value") then output = "Your input date is invalid" return output end local day, month, year = string.match(date, "(%d+) (%w+) (%d+)") if day == nil then day = 1 end if month == nil then month = Invalid end if year == nil then year = 2018 end output = "Year = " .. year .. "<br>Day = " .. day .. "<br>Month = ".. month return output end p.checkDate = function (frame) local us_mdY = frame.args.us_mdY local m, d, Y = us_mdY:match("(%d+)/(%d+)/(%d+)") local epoch = os.time{year=Y, month=m, day=d} local zeromdy = string.format("%02d/%02d/%04d", m, d, Y) return zeromdy == os.date('%m/%d/%Y', epoch) end p.isValidDate = function (frame) local us_mdY = frame.args.us_mdY local m, d, y = us_mdY:match("(%d+)/(%d+)/(%d+)") m, d, y = tonumber(m), tonumber(d), tonumber(y) if d <= 0 or d > 31 or m <= 0 or m > 12 or y <= 0 then -- Cases that don't make sense return false elseif m == 4 or m == 6 or m == 9 or m == 11 then -- Apr, Jun, Sep, Nov can have at most 30 days return d <= 30 elseif m == 2 then -- Feb if y%400 == 0 or (y%100 ~= 0 and y%4 == 0) then -- if leap year, days can be at most 29 return d <= 29 else -- else 28 days is the max return d <= 28 end else -- all other months can have at most 31 days return d <= 31 end 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/MrSpecjal/Dates/doc
(
edit
)