Jump to content
Main menu
Main menu
move to sidebar
hide
Ulifolau
Itulau Muamua
Vāega mo Tagata Lautele
Suiga talu ai nei
Itūlau le fa'ailogaina
Fesoasoani
Itūlau fa'apitoa
Su'e
Su'e
Appearance
Meaalofa tupe
Lesitala le ulufale
Fa'aola
Personal tools
Meaalofa tupe
Lesitala le ulufale
Fa'aola
Pages for logged out editors
learn more
Contributions
Talanoaga
Editing
Module:YMD to ISO
Add languages
Module
Talanoaga
English
Read
Edit source
View history
Meafaigāluega
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
Nofoaga e soso'o mai
Related changes
Si'i mai le faila
Page information
Get shortened URL
Download QR code
Appearance
move to sidebar
hide
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 = {} local function month_number(month_name) local months_full = {january=1, february=2, march=3, april=4, may=5, june=6, july=7, august=8, september=9, october=10, november=11, december=12} local months_abbr = {jan=1, feb=2, mar=3, apr=4, may=5, jun=6, jul=7, aug=8, sep=9, sept=9, oct=10, nov=11, dec=12} local month_lc, _ = string.gsub(string.lower(month_name),'%.','',1) local month_num = months_full[month_lc] or months_abbr[month_lc] or 0 return month_num end local function days_in_month(month_num,year) -- modified from code in Module:Citation/CS1/Date_validation local days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} local month_length if month_num == 2 then -- February: 28 days, unless leap year month_length = 28 if year <= 1582 then -- Julian calendar before Oct 1582 if (year%4) == 0 then month_length = 29 -- if leap year, then 29 days end else -- Gregorian calendar since Oct 1582 if ( (year%4)==0 and ((year%100)~=0 or (year%400)==0) ) then month_length = 29 -- if leap year, then 29 days end end else -- not February, get number of days for month month_length = days[month_num] end return month_length end local function zero_pad(string) if string.len(string) == 1 then return '0' .. string else return string end end function p.main(frame) if frame.args[1] == nil then return '' -- first argument is missing end local arg1, _ = string.gsub(mw.text.trim(frame.args[1]),'_',' ') return p._main(arg1) end function p._main(arg1) if arg1 == '' then return '' -- first argument is empty end if not arg1:match('^%d%d%d%d %a%a%a%a?%.?%a?%a?%a?%a?%a?%a? *%d%d?$') then return arg1 -- invalid date pattern end local year, month_name, day = string.match(arg1, '^(%d%d%d%d) *(%a%a%a%a?%.?%a?%a?%a?%a?%a?%a?) *(%d%d?)$') if month_number(month_name) == 0 then return arg1 -- invalid month name or abbreviation end if tonumber(day) < 1 or tonumber(day) > days_in_month(month_number(month_name),tonumber(year)) then return arg1 -- invalid day number for given month end return year .. '-' .. zero_pad(tostring(month_number(month_name))) .. '-' .. zero_pad(day) end return p
'Oto'otoga
By saving changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Toe tapē
Fesoasoani e teuteu
(opens in new window)
Preview page with this template
Wikidata entities used in this page
Module:YMD to ISO
: Sitelink, Description: en
Template used on this page:
Module:YMD to ISO/doc
(
Teuteu
)
Su'e
Su'e
Editing
Module:YMD to ISO
Add languages
Add topic