Title: Module:Citation/CS1/Date validation - freem URL Source: https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation Markdown Content: [Jump to content](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#bodyContent) - [x] Main menu Main menu move to sidebar hide Navigation * [Main page](https://freemwiki.com/wiki/Main_Page "Visit the main page [alt-shift-z]") * [Recent changes](https://freemwiki.com/wiki/Special:RecentChanges "A list of recent changes in the wiki [alt-shift-r]") * [Random page](https://freemwiki.com/wiki/Special:Random "Load a random page [alt-shift-x]") * [Help about MediaWiki](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents) Legal * [Terms](https://freemwiki.com/wiki/Terms_of_Service) * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Contact](https://freemwiki.com/wiki/Contact) [![Image 1](https://freemwiki.com/images/freem.svg)**freem**](https://freemwiki.com/wiki/Main_Page) [Search](https://freemwiki.com/wiki/Special:Search "Search freem [alt-shift-f]") Search - [x] Appearance * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ACitation%2FCS1%2FDate+validation&returntoquery=oldid%3D579716 "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ACitation%2FCS1%2FDate+validation&returntoquery=oldid%3D579716 "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") - [x] Personal tools * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ACitation%2FCS1%2FDate+validation&returntoquery=oldid%3D579716 "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ACitation%2FCS1%2FDate+validation&returntoquery=oldid%3D579716 "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") Pages for logged out editors [learn more](https://freemwiki.com/wiki/Help:Introduction) * [Contributions](https://freemwiki.com/wiki/Special:MyContributions "A list of edits made from this IP address [alt-shift-y]") * [Talk](https://freemwiki.com/wiki/Special:MyTalk "Discussion about edits from this IP address [alt-shift-n]") # Module:Citation/CS1/Date validation - [x] 1 language * [English](https://freemwiki.com/wiki/Module:Citation/CS1/ "Module:Citation/CS1/ – English") * [Module](https://freemwiki.com/wiki/Module:Citation/CS1/Date_validation "View the module page [alt-shift-c]") * [Discussion](https://freemwiki.com/index.php?title=Module_talk:Citation/CS1/Date_validation&action=edit&redlink=1 "Discussion about the content page (page does not exist) [alt-shift-t]") - [x] English * [Read](https://freemwiki.com/wiki/Module:Citation/CS1/Date_validation) * [Edit source](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&action=edit "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&action=history "Past revisions of this page [alt-shift-h]") - [x] Tools Tools move to sidebar hide Actions * [Read](https://freemwiki.com/wiki/Module:Citation/CS1/Date_validation) * [Edit source](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&action=edit "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&action=history) General * [What links here](https://freemwiki.com/wiki/Special:WhatLinksHere/Module:Citation/CS1/Date_validation "A list of all wiki pages that link here [alt-shift-j]") * [Related changes](https://freemwiki.com/wiki/Special:RecentChangesLinked/Module:Citation/CS1/Date_validation "Recent changes in pages linked from this page [alt-shift-k]") * [Special pages](https://freemwiki.com/wiki/Special:SpecialPages "A list of all special pages [alt-shift-q]") * [Printable version](javascript:print(); "Printable version of this page [alt-shift-p]") * [Permanent link](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&oldid=579716 "Permanent link to this revision of this page") * [Page information](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&action=info "More information about this page") Appearance move to sidebar hide From freem <[Module:Citation/CS1](https://freemwiki.com/wiki/Module:Citation/CS1 "Module:Citation/CS1") Revision as of 06:18, 21 October 2025 by [Lukegao](https://freemwiki.com/index.php?title=User:Lukegao&action=edit&redlink=1 "User:Lukegao (page does not exist)")([talk](https://freemwiki.com/index.php?title=User_talk:Lukegao&action=edit&redlink=1 "User talk:Lukegao (page does not exist)") | [contribs](https://freemwiki.com/wiki/Special:Contributions/Lukegao "Special:Contributions/Lukegao"))(1 revision imported) ([diff](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&diff=prev&oldid=579716 "Module:Citation/CS1/Date validation")) [← Older revision](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&direction=prev&oldid=579716 "Module:Citation/CS1/Date validation") | Latest revision (diff) | Newer revision → (diff) _Documentation for this module may be created at [Module:Citation/CS1/Date validation/doc](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date\_validation/doc&action=edit&redlink=1 "Module:Citation/CS1/Date validation/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1)--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-2)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-3)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-4)local add_prop_cat, is_set, in_array, set_message, substitute, wrap_style;-- imported functions from selected Module:Citation/CS1/Utilities[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-5)local cfg;-- table of tables imported from selected Module:Citation/CS1/Configuration[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-6)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-7)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-8)--[[--------------------------< F I L E - S C O P E D E C L A R A T I O N S >--------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-9)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-10)File-scope variables are declared here[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-11)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-12)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-13)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-14)local lang_object = mw.getContentLanguage();-- used by is_valid_accessdate(), is_valid_year(), date_name_xlate(); TODO: move to ~/Configuration?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-15)local year_limit;-- used by is_valid_year()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-16)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-17)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-18)--[=[-------------------------< I S _ V A L I D _ A C C E S S D A T E >----------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-19)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-20)returns true if:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-21) Wikipedia start date <= accessdate < today + 2 days[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-22)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-23)Wikipedia start date is 2001-01-15T00:00:00 UTC which is 979516800 seconds after 1970-01-01T00:00:00 UTC (the start of Unix time)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-24)accessdate is the date provided in |access-date= at time 00:00:00 UTC[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-25)today is the current date at time 00:00:00 UTC plus 48 hours[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-26) if today is 2015-01-01T00:00:00 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-27) adding 24 hours gives 2015-01-02T00:00:00 – one second more than today[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-28) adding 24 hours gives 2015-01-03T00:00:00 – one second more than tomorrow[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-29)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-30)This function does not work if it is fed month names for languages other than English. Wikimedia #time: parser[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-31)apparently doesn't understand non-English date month names. This function will always return false when the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-32)contains a non-English month name because good1 is false after the call to lang.formatDate(). To get around that[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-33)call this function with YYYY-MM-DD format dates.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-34)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-35)]=][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-36)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-37)local function is_valid_accessdate (accessdate)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-38)local good1, good2;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-39)local access_ts, tomorrow_ts;-- to hold Unix time stamps representing the dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-40)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-41)good1, access_ts = pcall (lang_object.formatDate, lang_object, 'U', accessdate );-- convert accessdate value to Unix timestamp [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-42)good2, tomorrow_ts = pcall (lang_object.formatDate, lang_object, 'U', 'today + 2 days' );-- today midnight + 2 days is one second more than all day tomorrow[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-43)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-44)if good1 and good2 then-- lang.formatDate() returns a timestamp in the local script which which tonumber() may not understand[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-45)access_ts = tonumber (access_ts) or lang_object:parseFormattedNumber (access_ts);-- convert to numbers for the comparison;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-46)tomorrow_ts = tonumber (tomorrow_ts) or lang_object:parseFormattedNumber (tomorrow_ts);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-47)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-48)return false;-- one or both failed to convert to Unix time stamp[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-49)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-50)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-51)if 979516800 <= access_ts and access_ts < tomorrow_ts then-- Wikipedia start date <= accessdate < tomorrow's date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-52)return true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-53)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-54)return false;-- accessdate out of range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-55)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-56)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-57)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-58)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-59)--[[--------------------------< G E T _ M O N T H _ N U M B E R >----------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-60)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-61)returns a number according to the month in a date: 1 for January, etc. Capitalization and spelling must be correct.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-62)If not a valid month, returns 0[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-63)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-64)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-65)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-66)local function get_month_number (month)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-67)return cfg.date_names['local'].long[month] or cfg.date_names['local'].short[month] or-- look for local names first[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-68)cfg.date_names['en'].long[month] or cfg.date_names['en'].short[month] or-- failing that, look for English names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-69)0;-- not a recognized month name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-70)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-71)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-72)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-73)--[[--------------------------< G E T _ S E A S O N _ N U M B E R >--------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-74)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-75)returns a number according to the sequence of seasons in a year: 21 for Spring, etc. Capitalization and spelling[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-76)must be correct. If not a valid season, returns 0.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-77) 21-24 = Spring, Summer, Autumn, Winter, independent of “Hemisphere”[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-78)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-79)returns 0 when is not |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-80)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-81)Season numbering is defined by Extended Date/Time Format (EDTF) specification ([https://www.loc.gov/standards/datetime/](https://www.loc.gov/standards/datetime/))[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-82)which became part of ISO 8601 in 2019. See '§Sub-year groupings'. The standard defines various divisions using[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-83)numbers 21-41. cs1|2 only supports generic seasons. EDTF does support the distinction between north and south[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-84)hemisphere seasons but cs1|2 has no way to make that distinction.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-85)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-86)These additional divisions not currently supported:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-87) 25-28 = Spring - Northern Hemisphere, Summer- Northern Hemisphere, Autumn - Northern Hemisphere, Winter - Northern Hemisphere[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-88) 29-32 = Spring – Southern Hemisphere, Summer– Southern Hemisphere, Autumn – Southern Hemisphere, Winter - Southern Hemisphere[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-89) 33-36 = Quarter 1, Quarter 2, Quarter 3, Quarter 4 (3 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-90) 37-39 = Quadrimester 1, Quadrimester 2, Quadrimester 3 (4 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-91) 40-41 = Semestral 1, Semestral-2 (6 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-92)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-93)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-94)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-95)local function get_season_number (season, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-96)if 'date' ~= param then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-97)return 0;-- season dates only supported by |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-98)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-99)return cfg.date_names['local'].season[season] or-- look for local names first[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-100)cfg.date_names['en'].season[season] or-- failing that, look for English names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-101)0;-- not a recognized season name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-102)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-103)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-104)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-105)--[[--------------------------< G E T _ Q U A R T E R _ N U M B E R >------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-106)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-107)returns a number according to the sequence of quarters in a year: 33 for first quarter, etc. Capitalization and spelling[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-108)must be correct. If not a valid quarter, returns 0.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-109) 33-36 = Quarter 1, Quarter 2, Quarter 3, Quarter 4 (3 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-110)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-111)returns 0 when is not |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-112)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-113)Quarter numbering is defined by Extended Date/Time Format (EDTF) specification ([https://www.loc.gov/standards/datetime/](https://www.loc.gov/standards/datetime/))[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-114)which became part of ISO 8601 in 2019. See '§Sub-year groupings'. The standard defines various divisions using[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-115)numbers 21-41. cs1|2 only supports generic seasons and quarters.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-116)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-117)These additional divisions not currently supported:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-118) 37-39 = Quadrimester 1, Quadrimester 2, Quadrimester 3 (4 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-119) 40-41 = Semestral 1, Semestral-2 (6 months each)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-120)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-121)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-122)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-123)local function get_quarter_number (quarter, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-124)if 'date' ~= param then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-125)return 0;-- quarter dates only supported by |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-126)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-127)quarter = mw.ustring.gsub (quarter, ' +', ' ');-- special case replace multiple space chars with a single space char[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-128)return cfg.date_names['local'].quarter[quarter] or-- look for local names first[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-129)cfg.date_names['en'].quarter[quarter] or-- failing that, look for English names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-130)0;-- not a recognized quarter name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-131)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-132)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-133)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-134)--[[--------------------------< G E T _ P R O P E R _ N A M E _ N U M B E R >----------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-135)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-136)returns a non-zero number if date contains a recognized proper-name. Capitalization and spelling must be correct.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-137)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-138)returns 0 when is not |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-139)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-140)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-141)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-142)local function get_proper_name_number (name, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-143)if 'date' ~= param then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-144)return 0;-- proper-name dates only supported by |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-145)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-146)return cfg.date_names['local'].named[name] or-- look for local names dates first[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-147)cfg.date_names['en'].named[name] or-- failing that, look for English names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-148)0;-- not a recognized named date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-149)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-150)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-151)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-152)--[[--------------------------< G E T _ E L E M E N T _ N U M B E R <------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-153)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-154)returns true if month or season or quarter or proper name is valid (properly spelled, capitalized, abbreviated)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-155)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-156)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-157)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-158)local function get_element_number (element, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-159)local num;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-160)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-161)local funcs = {get_month_number, get_season_number, get_quarter_number, get_proper_name_number};-- list of functions to execute in order[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-162)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-163)for _, func in ipairs (funcs) do-- spin through the function list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-164)num = func (element, param);-- call the function and get the returned number[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-165)if 0 ~= num then-- non-zero when valid month season quarter [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-166)return num;-- return that number[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-167)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-168)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-169)return nil;-- not valid[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-170)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-171)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-172)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-173)--[[--------------------------< I S _ V A L I D _ Y E A R >----------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-174)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-175)Function gets current year from the server and compares it to year from a citation parameter. Years more than one[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-176)year in the future are not acceptable.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-177)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-178)Special case for |pmc-embargo-date=: years more than two years in the future are not acceptable[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-179)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-180)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-181)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-182)local function is_valid_year (year, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-183)if not is_set (year_limit) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-184)year_limit = tonumber(os.date("%Y"))+1;-- global variable so we only have to fetch it once[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-185)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-186)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-187)year = tonumber (year) or lang_object:parseFormattedNumber (year);-- convert to number for the comparison[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-188)if year and (100 > year) then-- years less than 100 not supported[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-189)return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-190)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-191)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-192)if 'pmc-embargo-date' == param then-- special case for |pmc-embargo-date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-193)return year and (year <= tonumber(os.date("%Y"))+2) or false;-- years more than two years in the future are not accepted[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-194)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-195)return year and (year <= year_limit) or false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-196)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-197)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-198)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-199)--[[--------------------------< I S _ V A L I D _ D A T E >----------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-200)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-201)Returns true if day is less than or equal to the number of days in month and year is no farther into the future[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-202)than next year; else returns false.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-203)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-204)Assumes Julian calendar prior to year 1582 and Gregorian calendar thereafter. Accounts for Julian calendar leap[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-205)years before 1582 and Gregorian leap years after 1582. Where the two calendars overlap (1582 to approximately[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-206)1923) dates are assumed to be Gregorian.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-207)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-208)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-209)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-210)local function is_valid_date (year, month, day, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-211)local days_in_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-212)local month_length;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-213)if not is_valid_year (year, param) then-- no farther into the future than next year except |pmc-embargo-date= no more than two years in the future[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-214)return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-215)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-216)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-217)month = tonumber (month);-- required for YYYY-MM-DD dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-218)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-219)if (2 == month) then-- if February[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-220)month_length = 28;-- then 28 days unless[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-221)if 1582 > tonumber(year) then-- Julian calendar[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-222)if 0 == (year%4) then-- is a leap year?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-223)month_length = 29;-- if leap year then 29 days in February[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-224)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-225)else-- Gregorian calendar[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-226)if (0 == (year%4) and (0 ~= (year%100) or 0 == (year%400))) then-- is a leap year?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-227)month_length = 29;-- if leap year then 29 days in February[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-228)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-229)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-230)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-231)month_length = days_in_month[month];[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-232)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-233)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-234)if tonumber (day) > month_length then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-235)return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-236)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-237)return true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-238)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-239)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-240)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-241)--[[--------------------------< I S _ V A L I D _ M O N T H _ R A N G E _ S T Y L E >--------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-242)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-243)Months in a range are expected to have the same style: Jan–Mar or October–December but not February–Mar or Jul–August. [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-244)This function looks in cfg.date_names{} to see if both month names are listed in the long subtable or both are[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-245)listed in the short subtable. When both have the same style (both are listed in the same table), returns true; false else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-246)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-247)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-248)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-249)local function is_valid_month_range_style (month1, month2)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-250)if (cfg.date_names.en.long[month1] and cfg.date_names.en.long[month2]) or-- are both English names listed in the long subtable?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-251)(cfg.date_names.en.short[month1] and cfg.date_names.en.short[month2]) or-- are both English names listed in the short subtable?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-252)(cfg.date_names['local'].long[month1] and cfg.date_names['local'].long[month2]) or-- are both local names listed in the long subtable?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-253)(cfg.date_names['local'].short[month1] and cfg.date_names['local'].short[month2]) then-- are both local names listed in the short subtable?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-254)return true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-255)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-256)return false;-- names are mixed[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-257)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-258)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-259)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-260)--[[--------------------------< I S _ V A L I D _ M O N T H _ S E A S O N _ R A N G E >------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-261)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-262)Check a pair of months or seasons to see if both are valid members of a month or season pair.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-263)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-264)Month pairs are expected to be left to right, earliest to latest in time.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-265)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-266)All season ranges are accepted as valid because there are publishers out there who have published a Summer–Spring YYYY issue, hence treat as ok[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-267)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-268)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-269)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-270)local function is_valid_month_season_range(range_start, range_end, param)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-271)local range_start_number = get_month_number (range_start);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-272)local range_end_number;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-273)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-274)if 0 == range_start_number then-- is this a month range?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-275)range_start_number = get_season_number (range_start, param);-- not a month; is it a season? get start season number[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-276)range_end_number = get_season_number (range_end, param);-- get end season number[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-277)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-278)if (0 ~= range_start_number) and (0 ~= range_end_number) and (range_start_number ~= range_end_number) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-279)return true;-- any season pairing is accepted except when both are the same[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-280)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-281)return false;-- range_start and/or range_end is not a season[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-282)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-283)-- here when range_start is a month[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-284)range_end_number = get_month_number (range_end);-- get end month number[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-285)if range_start_number < range_end_number and-- range_start is a month; does range_start precede range_end?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-286)is_valid_month_range_style (range_start, range_end) then-- do months have the same style?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-287)return true;-- proper order and same style[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-288)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-289)return false;-- range_start month number is greater than or equal to range end number; or range end isn't a month[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-290)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-291)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-292)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-293)--[[--------------------------< M A K E _ C O I N S _ D A T E >------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-294)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-295)This function receives a table of date parts for one or two dates and an empty table reference declared in[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-296)Module:Citation/CS1. The function is called only for |date= parameters and only if the |date= is [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-297)determined to be a valid date format. The question of what to do with invalid date formats is not answered here.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-298)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-299)The date parts in the input table are converted to an ISO 8601 conforming date string:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-300) single whole dates: yyyy-mm-dd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-301) month and year dates: yyyy-mm[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-302) year dates: yyyy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-303) ranges: yyyy-mm-dd/yyyy-mm-dd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-304) yyyy-mm/yyyy-mm[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-305) yyyy/yyyy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-306)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-307)Dates in the Julian calendar are reduced to year or year/year so that we don't have to do calendar conversion from[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-308)Julian to Proleptic Gregorian.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-309)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-310)The input table has:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-311) year, year2 – always present; if before 1582, ignore months and days if present[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-312) month, month2 – 0 if not provided, 1-12 for months, 21-24 for seasons; 99 Christmas[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-313) day, day2 – 0 if not provided, 1-31 for days[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-314)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-315)the output table receives:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-316) rftdate: an ISO 8601 formatted date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-317) rftchron: a free-form version of the date, usually without year which is in rftdate (season ranges and proper-name dates)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-318) rftssn: one of four season keywords: winter, spring, summer, fall (lowercase)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-319) rftquarter: one of four values: 1, 2, 3, 4[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-320)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-321)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-322)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-323)local function make_COinS_date (input, tCOinS_date)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-324)local date;-- one date or first date in a range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-325)local date2 = '';-- end of range date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-326)input.year = tonumber (input.year) or lang_object:parseFormattedNumber (input.year);-- language-aware tonumber()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-327)input.year2 = tonumber (input.year2) or lang_object:parseFormattedNumber (input.year2);-- COinS dates are pseudo-ISO 8601 so convert to Arabic numerals[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-328)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-329)if ((1582 == input.year) and (10 > tonumber(input.month))) or (1582 > input.year) then-- if a Julian calendar date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-330)tCOinS_date.rftdate = tostring (input.year);-- &rft.date gets year only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-331)return;-- done[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-332)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-333)-- here for all forms of Gregorian dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-334)if 20 < tonumber (input.month) then-- if season, quarter, or proper-name date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-335)date = input.year;-- &rft.date gets year only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-336)if 0 ~= input.year2 and input.year ~= input.year2 then-- if a range, only the second year portion when not the same as range start year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-337)date = string.format ('%.4d/%.4d', input.year, input.year2)-- assemble the date range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-338)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-339)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-340)local season = {[24] = 'winter', [21] = 'spring', [22] = 'summer', [23] = 'fall', [33] = '1', [34] = '2', [35] = '3', [36] = '4', [98] = 'Easter', [99] = 'Christmas'};-- seasons lowercase, no autumn; proper-names use title case[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-341)if 0 == input.month2 then-- single season, quarter, or proper-name date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-342)if 40 < tonumber(input.month) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-343)tCOinS_date.rftchron = season[input.month];-- proper-name date; used in journal metadata only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-344)elseif 30 < tonumber(input.month) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-345)tCOinS_date.rftquarter = season[input.month];-- quarter date; used in journal metadata only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-346)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-347)tCOinS_date.rftssn = season[input.month];-- season date; used in journal metadata only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-348)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-349)else-- season ranges are lumped into &rft.chron; &rft.ssn and &rft.quarter are left blank[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-350)if input.year ~= input.year2 then-- season year – season year range or season year–year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-351)if 0 ~= input.month2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-352)tCOinS_date.rftchron = string.format ('%s %s – %s %s', season[input.month], input.year, season[input.month2], input.year2);-- used in journal metadata only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-353)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-354)else-- season–season year range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-355)tCOinS_date.rftchron = season[input.month] .. '–' .. season[input.month2];-- season–season year range; used in journal metadata only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-356)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-357)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-358)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-359)tCOinS_date.rftdate = tostring (date);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-360)return;-- done[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-361)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-362)-- here for gregorian calendar dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-363)if 0 ~= input.day then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-364)date = string.format ('%s-%.2d-%.2d', input.year, tonumber(input.month), tonumber(input.day));-- whole date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-365)elseif 0 ~= input.month then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-366)date = string.format ('%s-%.2d', input.year, tonumber(input.month));-- year and month[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-367)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-368)date = string.format ('%s', input.year);-- just year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-369)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-370)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-371)if 0 ~= input.year2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-372)if 0 ~= input.day2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-373)date2 = string.format ('/%s-%.2d-%.2d', input.year2, tonumber(input.month2), tonumber(input.day2));-- whole date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-374)elseif 0 ~= input.month2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-375)date2 = string.format ('/%s-%.2d', input.year2, tonumber(input.month2));-- year and month[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-376)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-377)date2 = string.format ('/%s', input.year2);-- just year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-378)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-379)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-380)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-381)tCOinS_date.rftdate = date .. date2;-- date2 has the '/' separator[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-382)return;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-383)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-384)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-385)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-386)--[[--------------------------< P A T T E R N S _ T >----------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-387)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-388)this is the list of patterns for date formats that this module recognizes. Approximately the first half of these[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-389)patterns represent formats that might be reformatted into another format. Those that might be reformatted have[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-390)'indicator' letters that identify the content of the matching capture: 'd' (day), 'm' (month), 'a' (anchor year),[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-391)'y' (year); second day, month, year have a '2' suffix.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-392)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-393)These patterns are used for both date validation and for reformatting. This table should not be moved to ~/Configuration[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-394)because changes to this table require changes to check_date() and to reformatter() and reformat_date()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-395)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-396)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-397)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-398)local patterns_t = {[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-399) -- year-initial numerical year-month-day[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-400)['ymd'] = {'^([1-9]%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-401)-- month-initial: month day, year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-402)['Mdy'] = {'^(%D-) +([1-9]%d?), +(([1-9]%d%d%d?)%a?)$', 'm', 'd', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-403)-- month-initial day range: month day–day, year; days are separated by endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-404)['Md-dy'] = {'^(%D-) +([1-9]%d?)[%-–]([1-9]%d?), +(([1-9]%d%d%d?)%a?)$', 'm', 'd', 'd2', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-405)-- day-initial: day month year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-406)['dMy'] = {'^([1-9]%d?) +(%D-) +(([1-9]%d%d%d?)%a?)$', 'd', 'm', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-407)-- year-initial: year month day; day: 1 or 2 two digits, leading zero allowed; not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-408)-- ['yMd'] = {'^(([1-9]%d%d%d?)%a?) +(%D-) +(%d%d?)$', 'a', 'y', 'm', 'd'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-409)-- day-range-initial: day–day month year; days are separated by endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-410)['d-dMy'] = {'^([1-9]%d?)[%-–]([1-9]%d?) +(%D-) +(([1-9]%d%d%d?)%a?)$', 'd', 'd2', 'm', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-411)-- day initial month-day-range: day month - day month year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-412)['dM-dMy'] = {'^([1-9]%d?) +(%D-) +[%-–] +([1-9]%d?) +(%D-) +(([1-9]%d%d%d?)%a?)$', 'd', 'm', 'd2', 'm2', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-413)-- month initial month-day-range: month day – month day, year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-414)['Md-Mdy'] = {'^(%D-) +([1-9]%d?) +[%-–] +(%D-) +([1-9]%d?), +(([1-9]%d%d%d?)%a?)$','m', 'd', 'm2', 'd2', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-415)-- day initial month-day-year-range: day month year - day month year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-416)['dMy-dMy'] = {'^([1-9]%d?) +(%D-) +([1-9]%d%d%d?) +[%-–] +([1-9]%d?) +(%D-) +(([1-9]%d%d%d?)%a?)$', 'd', 'm', 'y', 'd2', 'm2', 'a', 'y2'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-417)-- month initial month-day-year-range: month day, year – month day, year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-418)['Mdy-Mdy'] = {'^(%D-) +([1-9]%d?), +([1-9]%d%d%d?) +[%-–] +(%D-) +([1-9]%d?), +(([1-9]%d%d%d?)%a?)$', 'm', 'd', 'y', 'm2', 'd2', 'a', 'y2'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-419)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-420)-- these date formats cannot be converted, per se, but month name can be rendered short or long[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-421)-- month/season year - month/season year; separated by spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-422)['My-My'] = {'^(%D-) +([1-9]%d%d%d?) +[%-–] +(%D-) +(([1-9]%d%d%d?)%a?)$', 'm', 'y', 'm2', 'a', 'y2'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-423)-- month/season range year; months separated by endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-424)['M-My'] = {'^(%D-)[%-–](%D-) +(([1-9]%d%d%d?)%a?)$', 'm', 'm2', 'a', 'y'},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-425)-- month/season year or proper-name year; quarter year when First Quarter YYYY etc.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-426)['My'] = {'^([^%d–]-) +(([1-9]%d%d%d?)%a?)$', 'm', 'a', 'y'},-- this way because endash is a member of %D; %D- will match January–March 2019 when it shouldn't[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-427)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-428)-- these date formats cannot be converted[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-429)['Sy4-y2'] = {'^(%D-) +(([1-9]%d)%d%d)[%-–]((%d%d)%a?)$'},-- special case Winter/Summer year-year (YYYY-YY); year separated with unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-430)['Sy-y'] = {'^(%D-) +([1-9]%d%d%d?)[%-–](([1-9]%d%d%d?)%a?)$'},-- special case Winter/Summer year-year; year separated with unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-431)['y-y'] = {'^([1-9]%d%d%d?)[%-–](([1-9]%d%d%d?)%a?)$'},-- year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-432)['y4-y2'] = {'^(([1-9]%d)%d%d)[%-–]((%d%d)%a?)$'},-- year range: YYYY–YY; separated by unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-433)['y'] = {'^(([1-9]%d%d%d?)%a?)$'},-- year; here accept either YYY or YYYY[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-434)}[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-435)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-436)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-437)--[[--------------------------< I S _ V A L I D _ E M B A R G O _ D A T E >------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-438)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-439)returns true and date value if that value has proper dmy, mdy, ymd format.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-440)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-441)returns false and 9999 (embargoed forever) when date value is not proper format; assumes that when |pmc-embargo-date= is[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-442)set, the editor intended to embargo a PMC but |pmc-embargo-date= does not hold a single date.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-443)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-444)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-445)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-446)local function is_valid_embargo_date (v)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-447)if v:match (patterns_t['ymd'][1]) or-- ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-448)v:match (patterns_t['Mdy'][1]) or-- dmy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-449)v:match (patterns_t['dMy'][1]) then-- mdy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-450)return true, v;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-451)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-452)return false, '9999';-- if here not good date so return false and set embargo date to long time in future[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-453)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-454)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-455)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-456)--[[--------------------------< C H E C K _ D A T E >----------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-457)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-458)Check date format to see that it is one of the formats approved by WP:DATESNO or WP:DATERANGE. Exception: only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-459)allowed range separator is endash. Additionally, check the date to see that it is a real date: no 31 in 30-day[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-460)months; no 29 February when not a leap year. Months, both long-form and three character abbreviations, and seasons[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-461)must be spelled correctly. Future years beyond next year are not allowed.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-462)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-463)If the date fails the format tests, this function returns false and does not return values for anchor_year and[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-464)COinS_date. When this happens, the date parameter is (DEBUG: not?) used in the COinS metadata and the CITEREF identifier gets[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-465)its year from the year parameter if present otherwise CITEREF does not get a date value.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-466)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-467)Inputs:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-468) date_string - date string from date-holding parameters (date, year, publication-date, access-date, pmc-embargo-date, archive-date, lay-date)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-469)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-470)Returns:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-471) false if date string is not a real date; else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-472) true, anchor_year, COinS_date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-473) anchor_year can be used in CITEREF anchors[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-474) COinS_date is ISO 8601 format date; see make_COInS_date()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-475)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-476)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-477)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-478)local function check_date (date_string, param, tCOinS_date)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-479)local year;-- assume that year2, months, and days are not used;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-480)local year2 = 0;-- second year in a year range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-481)local month = 0;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-482)local month2 = 0;-- second month in a month range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-483)local day = 0;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-484)local day2 = 0;-- second day in a day range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-485)local anchor_year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-486)local coins_date;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-487)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-488)if date_string:match (patterns_t['ymd'][1]) then-- year-initial numerical year month day format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-489)year, month, day = date_string:match (patterns_t['ymd'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-490)if 12 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) or 0 == tonumber(day) then return false; end-- month or day number not valid or not Gregorian calendar[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-491)anchor_year = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-492)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-493)elseif mw.ustring.match(date_string, patterns_t['Mdy'][1]) then-- month-initial: month day, year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-494)month, day, anchor_year, year = mw.ustring.match(date_string, patterns_t['Mdy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-495)month = get_month_number (month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-496)if 0 == month then return false; end-- return false if month text isn't one of the twelve months[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-497)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-498)elseif mw.ustring.match(date_string, patterns_t['Md-dy'][1]) then-- month-initial day range: month day–day, year; days are separated by endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-499)month, day, day2, anchor_year, year = mw.ustring.match(date_string, patterns_t['Md-dy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-500)if tonumber(day) >= tonumber(day2) then return false; end-- date range order is left to right: earlier to later; dates may not be the same;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-501)month = get_month_number (month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-502)if 0 == month then return false; end-- return false if month text isn't one of the twelve months[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-503)month2=month;-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-504)year2 = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-505)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-506)elseif mw.ustring.match(date_string, patterns_t['dMy'][1]) then-- day-initial: day month year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-507)day, month, anchor_year, year = mw.ustring.match(date_string, patterns_t['dMy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-508)month = get_month_number (month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-509)if 0 == month then return false; end-- return false if month text isn't one of the twelve months[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-510)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-511)--[[ NOT supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-512) elseif mw.ustring.match(date_string, patterns_t['yMd'][1]) then -- year-initial: year month day; day: 1 or 2 two digits, leading zero allowed[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-513) anchor_year, year, month, day = mw.ustring.match(date_string, patterns_t['yMd'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-514) month = get_month_number (month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-515) if 0 == month then return false; end -- return false if month text isn't one of the twelve months[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-516)-- end NOT supported at en.wiki ]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-517)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-518)elseif mw.ustring.match(date_string, patterns_t['d-dMy'][1]) then-- day-range-initial: day–day month year; days are separated by endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-519)day, day2, month, anchor_year, year = mw.ustring.match(date_string, patterns_t['d-dMy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-520)if tonumber(day) >= tonumber(day2) then return false; end-- date range order is left to right: earlier to later; dates may not be the same;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-521)month = get_month_number (month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-522)if 0 == month then return false; end-- return false if month text isn't one of the twelve months[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-523)month2 = month;-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-524)year2 = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-525)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-526)elseif mw.ustring.match(date_string, patterns_t['dM-dMy'][1]) then-- day initial month-day-range: day month - day month year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-527)day, month, day2, month2, anchor_year, year = mw.ustring.match(date_string, patterns_t['dM-dMy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-528)if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end-- date range order is left to right: earlier to later;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-529)month = get_month_number (month);-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-530)month2 = get_month_number (month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-531)year2 = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-532)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-533)elseif mw.ustring.match(date_string, patterns_t['Md-Mdy'][1]) then-- month initial month-day-range: month day – month day, year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-534)month, day, month2, day2, anchor_year, year = mw.ustring.match(date_string, patterns_t['Md-Mdy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-535)if (not is_valid_month_season_range(month, month2, param)) or not is_valid_year(year) then return false; end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-536)month = get_month_number (month);-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-537)month2 = get_month_number (month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-538)year2 = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-539)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-540)elseif mw.ustring.match(date_string, patterns_t['dMy-dMy'][1]) then-- day initial month-day-year-range: day month year - day month year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-541)day, month, year, day2, month2, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['dMy-dMy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-542)if tonumber(year2) <= tonumber(year) then return false; end-- must be sequential years, left to right, earlier to later[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-543)if not is_valid_year(year2) or not is_valid_month_range_style(month, month2) then return false; end-- year2 no more than one year in the future; months same style[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-544)month = get_month_number (month);-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-545)month2 = get_month_number (month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-546)if 0 == month or 0 == month2 then return false; end-- both must be valid[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-547)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-548)elseif mw.ustring.match(date_string, patterns_t['Mdy-Mdy'][1]) then-- month initial month-day-year-range: month day, year – month day, year; uses spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-549)month, day, year, month2, day2, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['Mdy-Mdy'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-550)if tonumber(year2) <= tonumber(year) then return false; end-- must be sequential years, left to right, earlier to later[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-551)if not is_valid_year(year2) or not is_valid_month_range_style(month, month2) then return false; end-- year2 no more than one year in the future; months same style[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-552)month = get_month_number (month);-- for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-553)month2 = get_month_number(month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-554)if 0 == month or 0 == month2 then return false; end-- both must be valid[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-555)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-556)elseif mw.ustring.match(date_string, patterns_t['Sy4-y2'][1]) then-- special case Winter/Summer year-year (YYYY-YY); year separated with unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-557)local century;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-558)month, year, century, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['Sy4-y2'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-559)if 'Winter' ~= month and 'Summer' ~= month then return false end;-- 'month' can only be Winter or Summer[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-560)anchor_year = year .. '–' .. anchor_year;-- assemble anchor_year from both years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-561)year2 = century..year2;-- add the century to year2 for comparisons[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-562)if 1 ~= tonumber(year2) - tonumber(year) then return false; end-- must be sequential years, left to right, earlier to later[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-563)if not is_valid_year(year2) then return false; end-- no year farther in the future than next year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-564)month = get_season_number(month, param);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-565)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-566)elseif mw.ustring.match(date_string, patterns_t['Sy-y'][1]) then-- special case Winter/Summer year-year; year separated with unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-567)month, year, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['Sy-y'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-568)month = get_season_number (month, param);-- can only be winter or summer; also for metadata[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-569)if (month ~= cfg.date_names['en'].season['Winter']) and (month ~= cfg.date_names['en'].season['Summer']) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-570)return false;-- not Summer or Winter; abandon[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-571)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-572)anchor_year = year .. '–' .. anchor_year;-- assemble anchor_year from both years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-573)if 1 ~= tonumber(year2) - tonumber(year) then return false; end-- must be sequential years, left to right, earlier to later[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-574)if not is_valid_year(year2) then return false; end-- no year farther in the future than next year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-575)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-576)elseif mw.ustring.match(date_string, patterns_t['My-My'][1]) then-- month/season year - month/season year; separated by spaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-577)month, year, month2, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['My-My'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-578)anchor_year = year .. '–' .. anchor_year;-- assemble anchor_year from both years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-579)if tonumber(year) >= tonumber(year2) then return false; end-- left to right, earlier to later, not the same[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-580)if not is_valid_year(year2) then return false; end-- no year farther in the future than next year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-581)if 0 ~= get_month_number(month) and 0 ~= get_month_number(month2) and is_valid_month_range_style(month, month2) then -- both must be month year, same month style[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-582)month = get_month_number(month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-583)month2 = get_month_number(month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-584)elseif 0 ~= get_season_number(month, param) and 0 ~= get_season_number(month2, param) then-- both must be season year, not mixed[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-585)month = get_season_number(month, param);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-586)month2 = get_season_number(month2, param);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-587)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-588) return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-589)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-590)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-591)elseif mw.ustring.match(date_string, patterns_t['M-My'][1]) then-- month/season range year; months separated by endash [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-592)month, month2, anchor_year, year = mw.ustring.match(date_string, patterns_t['M-My'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-593)if (not is_valid_month_season_range(month, month2, param)) or (not is_valid_year(year)) then return false; end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-594)if 0 ~= get_month_number(month) then-- determined to be a valid range so just check this one to know if month or season[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-595)month = get_month_number(month);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-596)month2 = get_month_number(month2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-597)if 0 == month or 0 == month2 then return false; end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-598)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-599)month = get_season_number(month, param);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-600)month2 = get_season_number(month2, param);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-601)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-602)year2 = year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-603)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-604)elseif mw.ustring.match(date_string, patterns_t['My'][1]) then-- month/season/quarter/proper-name year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-605)month, anchor_year, year = mw.ustring.match(date_string, patterns_t['My'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-606)if not is_valid_year(year) then return false; end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-607)month = get_element_number(month, param);-- get month season quarter proper-name number or nil[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-608)if not month then return false; end-- not valid whatever it is[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-609)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-610)elseif mw.ustring.match(date_string, patterns_t['y-y'][1]) then-- Year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-611)year, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['y-y'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-612)anchor_year = year .. '–' .. anchor_year;-- assemble anchor year from both years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-613)if tonumber(year) >= tonumber(year2) then return false; end-- left to right, earlier to later, not the same[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-614)if not is_valid_year(year2) then return false; end-- no year farther in the future than next year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-615)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-616)elseif mw.ustring.match(date_string, patterns_t['y4-y2'][1]) then-- Year range: YYYY–YY; separated by unspaced endash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-617)local century;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-618)year, century, anchor_year, year2 = mw.ustring.match(date_string, patterns_t['y4-y2'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-619)anchor_year = year .. '–' .. anchor_year;-- assemble anchor year from both years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-620)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-621)if 13 > tonumber(year2) then return false; end-- don't allow 2003-05 which might be May 2003[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-622)year2 = century .. year2;-- add the century to year2 for comparisons[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-623)if tonumber(year) >= tonumber(year2) then return false; end-- left to right, earlier to later, not the same[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-624)if not is_valid_year(year2) then return false; end-- no year farther in the future than next year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-625)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-626)if in_array (param, {'date', 'publication-date', 'year'}) then-- here when 'valid' abbreviated year range; if one of these parameters[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-627)add_prop_cat ('year-range-abbreviated');-- add properties cat[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-628)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-629)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-630)elseif mw.ustring.match(date_string, patterns_t['y'][1]) then-- year; here accept either YYY or YYYY[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-631)anchor_year, year = mw.ustring.match(date_string, patterns_t['y'][1]);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-632)if false == is_valid_year(year) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-633)return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-634)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-635)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-636)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-637)return false;-- date format not one of the MOS:DATE approved formats[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-638)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-639)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-640)if param ~= 'date' then-- CITEREF disambiguation only allowed in |date=; |year= & |publication-date= promote to date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-641)if anchor_year:match ('%l$') then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-642)return false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-643)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-644)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-645)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-646)if 'access-date' == param then-- test access-date here because we have numerical date parts[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-647)if 0 ~= year and 0 ~= month and 0 ~= day and -- all parts of a single date required[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-648)0 == year2 and 0 == month2 and 0 == day2 then-- none of these; access-date must not be a range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-649)if not is_valid_accessdate(year .. '-' .. month .. '-' .. day) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-650)return false;-- return false when access-date out of bounds[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-651)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-652)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-653)return false;-- return false when access-date is a range of two dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-654)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-655)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-656)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-657)if 'archive-date' == param then-- test archive-date here because we have numerical date parts[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-658)if not (0 ~= year and 0 ~= month and 0 ~= day and-- all parts of a single date required[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-659)0 == year2 and 0 == month2 and 0 == day2) then-- none of these; archive-date must not be a range[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-660)return false;-- return false when archive-date is a range of two dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-661)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-662)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-663)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-664)local result=true;-- check whole dates for validity; assume true because not all dates will go through this test[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-665)if 0 ~= year and 0 ~= month and 0 ~= day and 0 == year2 and 0 == month2 and 0 == day2 then-- YMD (simple whole date)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-666)result = is_valid_date (year, month, day, param);-- for |pmc-embargo-date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-667)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-668)elseif 0 ~= year and 0 ~= month and 0 ~= day and 0 == year2 and 0 == month2 and 0 ~= day2 then-- YMD-d (day range)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-669)result = is_valid_date (year, month, day);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-670)result = result and is_valid_date (year, month, day2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-671)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-672)elseif 0 ~= year and 0 ~= month and 0 ~= day and 0 == year2 and 0 ~= month2 and 0 ~= day2 then-- YMD-md (day month range)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-673)result = is_valid_date (year, month, day);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-674)result = result and is_valid_date (year, month2, day2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-675)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-676)elseif 0 ~= year and 0 ~= month and 0 ~= day and 0 ~= year2 and 0 ~= month2 and 0 ~= day2 then-- YMD-ymd (day month year range)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-677)result = is_valid_date(year, month, day);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-678)result = result and is_valid_date(year2, month2, day2);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-679)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-680)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-681)if false == result then return false; end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-682)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-683)if nil ~= tCOinS_date then-- this table only passed into this function when testing |date= parameter values[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-684)make_COinS_date ({year = year, month = month, day = day, year2 = year2, month2 = month2, day2 = day2}, tCOinS_date);-- make an ISO 8601 date string for COinS[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-685)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-686)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-687)return true, anchor_year;-- format is good and date string represents a real date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-688)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-689)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-690)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-691)--[[--------------------------< D A T E S >--------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-692)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-693)Cycle the date-holding parameters in passed table date_parameters_list through check_date() to check compliance with MOS:DATE. For all valid dates, check_date() returns[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-694)true. The |date= parameter test is unique, it is the only date holding parameter from which values for anchor_year (used in CITEREF identifiers) and COinS_date (used in[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-695)the COinS metadata) are derived. The |date= parameter is the only date-holding parameter that is allowed to contain the no-date keywords "n.d." or "nd" (without quotes).[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-696)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-697)Unlike most error messages created in this module, only one error message is created by this function. Because all of the date holding parameters are processed serially,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-698)parameters with errors are added to the sequence table as the dates are tested.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-699)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-700)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-701)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-702)local function dates(date_parameters_list, tCOinS_date, error_list)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-703)local anchor_year;-- will return as nil if the date being tested is not |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-704)local COinS_date;-- will return as nil if the date being tested is not |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-705)local embargo_date;-- if embargo date is a good dmy, mdy, ymd date then holds original value else reset to 9999[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-706)local good_date = false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-707)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-708)for k, v in pairs(date_parameters_list) do-- for each date-holding parameter in the list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-709)if is_set(v.val) then-- if the parameter has a value[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-710)v.val = mw.ustring.gsub(v.val, '%d', cfg.date_names.local_digits);-- translate 'local' digits to Western 0-9[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-711)if v.val:match("^c%. [1-9]%d%d%d?%a?$") then-- special case for c. year or with or without CITEREF disambiguator - only |date= and |year=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-712)local year = v.val:match("c%. ([1-9]%d%d%d?)%a?");-- get the year portion so it can be tested[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-713)if 'date' == k then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-714)anchor_year, COinS_date = v.val:match("((c%. [1-9]%d%d%d?)%a?)");-- anchor year and COinS_date only from |date= parameter[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-715)good_date = is_valid_year(year);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-716)elseif 'year' == k then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-717)good_date = is_valid_year(year);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-718)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-719)elseif 'date' == k then-- if the parameter is |date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-720)if v.val:match("^n%.d%.%a?$") then -- ToDo: I18N -- if |date=n.d. with or without a CITEREF disambiguator[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-721)good_date, anchor_year, COinS_date = true, v.val:match("((n%.d%.)%a?)"); -- ToDo: I18N -- "n.d."; no error when date parameter is set to no date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-722)elseif v.val:match("^nd%a?$") then -- ToDo: I18N -- if |date=nd with or without a CITEREF disambiguator[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-723)good_date, anchor_year, COinS_date = true, v.val:match("((nd)%a?)"); -- ToDo: I18N -- "nd"; no error when date parameter is set to no date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-724)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-725)good_date, anchor_year, COinS_date = check_date (v.val, k, tCOinS_date);-- go test the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-726)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-727)elseif 'year' == k then-- if the parameter is |year= it should hold only a year value[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-728)if v.val:match("^[1-9]%d%d%d?%a?$") then-- if |year = 3 or 4 digits only with or without a CITEREF disambiguator[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-729)good_date, anchor_year, COinS_date = true, v.val:match("((%d+)%a?)");[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-730)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-731)elseif 'pmc-embargo-date' == k then-- if the parameter is |pmc-embargo-date=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-732)good_date = check_date (v.val, k);-- go test the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-733)if true == good_date then-- if the date is a valid date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-734)good_date, embargo_date = is_valid_embargo_date (v.val);-- is |pmc-embargo-date= date a single dmy, mdy, or ymd formatted date? yes: returns embargo date; no: returns 9999[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-735)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-736)else-- any other date-holding parameter[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-737)good_date = check_date (v.val, k);-- go test the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-738)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-739)if false == good_date then-- assemble one error message so we don't add the tracking category multiple times[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-740)table.insert (error_list, wrap_style ('parameter', v.name));-- make parameter name suitable for error message list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-741)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-742)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-743)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-744)return anchor_year, embargo_date;-- and done[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-745)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-746)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-747)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-748)--[[--------------------------< Y E A R _ C H E C K >----------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-749)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-750)Temporary function to test |year= for acceptable values:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-751) YYY, YYYY, year-only ranges, their circa forms, with or without CITEREF disambiguators.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-752)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-753)When |year= holds some form of date that is not one of these year-only dates, emit a maintenance message.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-754)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-755)This function necessary because many non-cs1|2 templates have a |year= parameter so cirrus searches are more-or-[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-756)less useless[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-757)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-758)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-759)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-760)local function year_check (year)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-761)year = year:gsub ('c%. *', '');-- remove circa annotation (if present) before testing [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-762)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-763)for _, index in ipairs ({'y-y', 'y4-y2', 'y'}) do-- spin through these indexes into patterns_t[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-764)if mw.ustring.match (year, patterns_t[index][1]) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-765)return;-- if a match then |year= holds a valid 'year'[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-766)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-767)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-768)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-769)set_message ('maint_year');-- if here, |year= value is not an accepted value; add a maint cat[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-770)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-771)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-772)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-773)--[[--------------------------< Y E A R _ D A T E _ C H E C K >------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-774)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-775)Compare the value provided in |year= with the year value(s) provided in |date=. This function sets a local numeric value:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-776) 0 - year value does not match the year value in date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-777) 1 - (default) year value matches the year value in date or one of the year values when date contains two years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-778) 2 - year value matches the year value in date when date is in the form YYYY-MM-DD and year is disambiguated (|year=YYYYx)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-779)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-780)the numeric value in determines the 'output' if any from this function:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-781) 0 – adds error message to error_list sequence table[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-782) 1 – adds maint cat[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-783) 2 – does nothing[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-784)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-785)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-786)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-787)local function year_date_check (year_string, year_origin, date_string, date_origin, error_list)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-788)local year;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-789)local date1;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-790)local date2;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-791)local result = 1;-- result of the test; assume that the test passes[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-792)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-793)year = year_string:match ('(%d%d%d%d?)');[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-794)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-795)if date_string:match ('%d%d%d%d%-%d%d%-%d%d') then--special case where both date and year are required YYYY-MM-DD and YYYYx[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-796)date1 = date_string:match ('(%d%d%d%d)');[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-797)year = year_string:match ('(%d%d%d%d)');[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-798)if year ~= date1 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-799)result = 0;-- years don't match[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-800)elseif year_string:match ('%d%d%d%d%a') then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-801)result = 2;-- years match; but because disambiguated, don't add to maint cat[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-802)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-803)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-804)elseif date_string:match ("%d%d%d%d?.-%d%d%d%d?") then-- any of the standard range formats of date with two three- or four-digit years[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-805)date1, date2 = date_string:match ("(%d%d%d%d?).-(%d%d%d%d?)");[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-806)if year ~= date1 and year ~= date2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-807)result = 0;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-808)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-809)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-810)elseif mw.ustring.match(date_string, "%d%d%d%d[%-–]%d%d") then-- YYYY-YY date ranges[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-811)local century;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-812)date1, century, date2 = mw.ustring.match(date_string, "((%d%d)%d%d)[%-–]+(%d%d)");[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-813)date2 = century..date2;-- convert YY to YYYY[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-814)if year ~= date1 and year ~= date2 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-815)result = 0;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-816)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-817)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-818)elseif date_string:match ("%d%d%d%d?") then-- any of the standard formats of date with one year[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-819)date1 = date_string:match ("(%d%d%d%d?)");[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-820)if year ~= date1 then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-821)result = 0;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-822)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-823)else-- should never get here; this function called only when no other date errors[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-824)result = 0;-- no recognizable year in date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-825)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-826)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-827)if 0 == result then-- year / date mismatch[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-828)table.insert (error_list, substitute (cfg.messages['mismatch'], {year_origin, date_origin}));-- add error message to error_list sequence table[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-829)elseif 1 == result then-- redundant year / date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-830)set_message ('maint_date_year');-- add a maint cat[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-831)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-832)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-833)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-834)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-835)--[[--------------------------< R E F O R M A T T E R >--------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-836)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-837)reformat 'date' into new format specified by format_param if pattern_idx (the current format of 'date') can be[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-838)reformatted. Does the grunt work for reformat_dates().[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-839)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-840)The table re_formats maps pattern_idx (current format) and format_param (desired format) to a table that holds:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-841) format string used by string.format()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-842) identifier letters ('d', 'm', 'y', 'd2', 'm2', 'y2') that serve as indexes into a table t{} that holds captures[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-843) from mw.ustring.match() for the various date parts specified by patterns_t[pattern_idx][1][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-844)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-845)Items in patterns_t{} have the general form:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-846) ['ymd'] = {'^(%d%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'}, where:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-847) ['ymd'] is pattern_idx[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-848) patterns_t['ymd'][1] is the match pattern with captures for mw.ustring.match()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-849) patterns_t['ymd'][2] is an indicator letter identifying the content of the first capture[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-850) patterns_t['ymd'][3] ... the second capture etc.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-851)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-852)when a pattern matches a date, the captures are loaded into table t{} in capture order using the idemtifier[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-853)characters as indexes into t{} For the above, a ymd date is in t{} as:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-854) t.y = first capture (year), t.m = second capture (month), t.d = third capture (day)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-855)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-856)To reformat, this function is called with the pattern_idx that matches the current format of the date and with[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-857)format_param set to the desired format. This function loads table t{} as described and then calls string.format()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-858)with the format string specified by re_format[pattern_idx][format_param][1] using values taken from t{} according[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-859)to the capture identifier letters specified by patterns_t[pattern_idx][format_param][n] where n is 2..[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-860)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-861)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-862)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-863)local re_formats = {[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-864)['ymd'] = {-- date format is ymd; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-865)['mdy'] = {'%s %s, %s', 'm', 'd', 'y'},-- |df=mdy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-866)['dmy'] = {'%s %s %s', 'd', 'm', 'y'},-- |df=dmy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-867)-- ['yMd'] = {'%s %s %s', 'y', 'm', 'd'}, -- |df=yMd; not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-868)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-869)['Mdy'] = {-- date format is Mdy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-870)['mdy'] = {'%s %s, %s', 'm', 'd', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-871)['dmy'] = {'%s %s %s', 'd', 'm', 'y'},-- |df=dmy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-872)['ymd'] = {'%s-%s-%s', 'y', 'm', 'd'},-- |df=ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-873)-- ['yMd'] = {'%s %s %s', 'y', 'm', 'd'}, -- |df=yMd; not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-874)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-875)['dMy'] = {-- date format is dMy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-876)['dmy'] = {'%s %s %s', 'd', 'm', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-877)['mdy'] = {'%s %s, %s', 'm', 'd', 'y'},-- |df=mdy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-878)['ymd'] = {'%s-%s-%s', 'y', 'm', 'd'},-- |df=ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-879)-- ['yMd'] = {'%s %s %s', 'y', 'm', 'd'}, -- |df=yMd; not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-880)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-881)['Md-dy'] = {-- date format is Md-dy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-882)['mdy'] = {'%s %s–%s, %s', 'm', 'd', 'd2', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-883)['dmy'] = {'%s–%s %s %s', 'd', 'd2', 'm', 'y'},-- |df=dmy -> d-dMy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-884)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-885)['d-dMy'] = {-- date format is d-d>y; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-886)['dmy'] = {'%s–%s %s %s', 'd', 'd2', 'm', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-887)['mdy'] = {'%s %s–%s, %s', 'm', 'd', 'd2', 'y'},-- |df=mdy -> Md-dy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-888)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-889)['dM-dMy'] = {-- date format is dM-dMy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-890)['dmy'] = {'%s %s – %s %s %s', 'd', 'm', 'd2', 'm2', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-891)['mdy'] = {'%s %s – %s %s, %s', 'm', 'd', 'm2', 'd2', 'y'},-- |df=mdy -> Md-Mdy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-892)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-893)['Md-Mdy'] = {-- date format is Md-Mdy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-894)['mdy'] = {'%s %s – %s %s, %s', 'm', 'd', 'm2', 'd2', 'y'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-895)['dmy'] = {'%s %s – %s %s %s', 'd', 'm', 'd2', 'm2', 'y'},-- |df=dmy -> dM-dMy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-896)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-897)['dMy-dMy'] = {-- date format is dMy-dMy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-898)['dmy'] = {'%s %s %s – %s %s %s', 'd', 'm', 'y', 'd2', 'm2', 'y2'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-899)['mdy'] = {'%s %s, %s – %s %s, %s', 'm', 'd', 'y', 'm2', 'd2', 'y2'},-- |df=mdy -> Mdy-Mdy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-900)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-901)['Mdy-Mdy'] = {-- date format is Mdy-Mdy; reformat to:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-902)['mdy'] = {'%s %s, %s – %s %s, %s', 'm', 'd', 'y', 'm2', 'd2', 'y2'},-- for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-903)['dmy'] = {'%s %s %s – %s %s %s', 'd', 'm', 'y', 'd2', 'm2', 'y2'},-- |df=dmy -> dMy-dMy [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-904)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-905)['My-My'] = {-- these for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-906)['any'] = {'%s %s – %s %s', 'm', 'y', 'm2', 'y2'},-- dmy/mdy agnostic[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-907)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-908)['M-My'] = {-- these for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-909)['any'] = {'%s–%s %s', 'm', 'm2', 'y'},-- dmy/mdy agnostic[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-910)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-911)['My'] = {-- these for long/short reformatting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-912)['any'] = {'%s %s', 'm', 'y'},-- dmy/mdy agnostic[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-913)},[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-914)-- ['yMd'] = { -- not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-915)-- ['mdy'] = {'%s %s, %s', 'm', 'd', 'y'}, -- |df=mdy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-916)-- ['dmy'] = {'%s %s %s', 'd', 'm', 'y'}, -- |df=dmy[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-917)-- ['ymd'] = {'%s-%s-%s', 'y', 'm', 'd'}, -- |df=ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-918)-- },[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-919)}[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-920)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-921)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-922)local function reformatter (date, pattern_idx, format_param, mon_len)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-923)if not in_array (pattern_idx, {'ymd', 'Mdy', 'Md-dy', 'dMy', 'yMd', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My'}) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-924)return;-- not in this set of date format patterns_t then not a reformattable date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-925)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-926)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-927)if 'ymd' == format_param and in_array (pattern_idx, {'ymd', 'Md-dy', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My'}) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-928)return;-- ymd date ranges not supported at en.wiki; no point in reformatting ymd to ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-929)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-930)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-931)if in_array (pattern_idx, {'My', 'M-My', 'My-My'}) then-- these are not dmy/mdy so can't be 'reformatted' into either[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-932)format_param = 'any';-- so format-agnostic [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-933)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-934)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-935)-- yMd is not supported at en.wiki; when yMd is supported at your wiki, uncomment the next line[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-936)-- if 'yMd' == format_param and in_array (pattern_idx, {'yMd', 'Md-dy', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy'}) then -- these formats not convertable; yMd not supported at en.wiki[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-937)if 'yMd' == format_param then-- yMd not supported at en.wiki; when yMd is supported at your wiki, remove or comment-out this line[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-938)return;-- not a reformattable date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-939)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-940)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-941)local c1, c2, c3, c4, c5, c6, c7;-- these hold the captures specified in patterns_t[pattern_idx][1][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-942)c1, c2, c3, c4, c5, c6, c7 = mw.ustring.match (date, patterns_t[pattern_idx][1]);-- get the captures[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-943)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-944)local t = {-- table that holds k/v pairs of date parts from the captures and patterns_t[pattern_idx][2..][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-945)[patterns_t[pattern_idx][2]] = c1;-- at minimum there is always one capture with a matching indicator letter[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-946)[patterns_t[pattern_idx][3] or 'x'] = c2;-- patterns_t can have a variable number of captures; each capture requires an indicator letter;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-947)[patterns_t[pattern_idx][4] or 'x'] = c3;-- where there is no capture, there is no indicator letter so n in patterns_t[pattern_idx][n] will be nil;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-948)[patterns_t[pattern_idx][5] or 'x'] = c4;-- the 'x' here spoofs an indicator letter to prevent 'table index is nil' error[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-949)[patterns_t[pattern_idx][6] or 'x'] = c5;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-950)[patterns_t[pattern_idx][7] or 'x'] = c6;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-951)[patterns_t[pattern_idx][8] or 'x'] = c7;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-952)};[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-953)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-954)if t.a then-- if this date has an anchor year capture (all convertable date formats except ymd)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-955)if t.y2 then-- for year range date formats [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-956)t.y2 = t.a;-- use the anchor year capture when reassembling the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-957)else-- here for single date formats (except ymd)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-958)t.y = t.a;-- use the anchor year capture when reassembling the date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-959)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-960)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-961)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-962)if tonumber(t.m) then-- if raw month is a number (converting from ymd)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-963)if 's' == mon_len then-- if we are to use abbreviated month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-964)t.m = cfg.date_names['inv_local_short'][tonumber(t.m)];-- convert it to a month name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-965)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-966)t.m = cfg.date_names['inv_local_long'][tonumber(t.m)];-- convert it to a month name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-967)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-968)t.d = t.d:gsub ('0(%d)', '%1');-- strip leading '0' from day if present[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-969)elseif 'ymd' == format_param then-- when converting to ymd[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-970)t.y = t.y:gsub ('%a', '');-- strip CITREF disambiguator if present; anchor year already known so process can proceed; TODO: maint message?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-971)if 1582 > tonumber (t.y) then-- ymd format dates not allowed before 1582[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-972)return;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-973)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-974)t.m = string.format ('%02d', get_month_number (t.m));-- make sure that month and day are two digits[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-975)t.d = string.format ('%02d', t.d);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-976)elseif mon_len then-- if mon_len is set to either 'short' or 'long'[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-977)for _, mon in ipairs ({'m', 'm2'}) do-- because there can be two month names, check both [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-978)if t[mon] then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-979)t[mon] = get_month_number (t[mon]);-- get the month number for this month (is length agnostic)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-980)if 0 == t[mon] then return; end-- seasons and named dates can't be converted[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-981)t[mon] = (('s' == mon_len) and cfg.date_names['inv_local_short'][t[mon]]) or cfg.date_names['inv_local_long'][t[mon]];-- fetch month name according to length[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-982)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-983)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-984)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-985)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-986)local new_date = string.format (re_formats[pattern_idx][format_param][1],-- format string[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-987)t[re_formats[pattern_idx][format_param][2]],-- named captures from t{}[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-988)t[re_formats[pattern_idx][format_param][3]],[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-989)t[re_formats[pattern_idx][format_param][4]],[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-990)t[re_formats[pattern_idx][format_param][5]],[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-991)t[re_formats[pattern_idx][format_param][6]],[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-992)t[re_formats[pattern_idx][format_param][7]],[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-993)t[re_formats[pattern_idx][format_param][8]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-994));[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-995)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-996)return new_date;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-997)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-998)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-999)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1000)--[[-------------------------< R E F O R M A T _ D A T E S >--------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1001)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1002)Reformats existing dates into the format specified by format.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1003)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1004)format is one of several manual keywords: dmy, dmy-all, mdy, mdy-all, ymd, ymd-all. The -all version includes[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1005)access- and archive-dates; otherwise these dates are not reformatted.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1006)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1007)This function allows automatic date formatting. In ~/Configuration, the article source is searched for one of[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1008)the {{[use xxx dates](https://freemwiki.com/wiki/Template:Use_xxx_dates "Template:Use xxx dates")}} templates. If found, xxx becomes the global date format as xxx-all. If |cs1-dates= in[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1009){{[use xxx dates](https://freemwiki.com/wiki/Template:Use_xxx_dates "Template:Use xxx dates")}} has legitimate value then that value determines how cs1|2 dates will be rendered. Legitimate[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1010)values for |cs1-dates= are:[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1011) l - all dates are rendered with long month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1012) ls - publication dates use long month names; access-/archive-dates use abbreviated month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1013) ly - publication dates use long month names; access-/archive-dates rendered in ymd format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1014) s - all dates are rendered with abbreviated (short) month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1015) sy - publication dates use abbreviated month names; access-/archive-dates rendered in ymd format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1016) y - all dates are rendered in ymd format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1017)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1018)the format argument for automatic date formatting will be the format specified by {{[use xxx dates](https://freemwiki.com/wiki/Template:Use_xxx_dates "Template:Use xxx dates")}} with the[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1019)value supplied by |cs1-dates so one of: xxx-l, xxx-ls, xxx-ly, xxx-s, xxx-sy, xxx-y, or simply xxx (|cs1-dates=[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1020)empty, omitted, or invalid) where xxx shall be either of dmy or mdy.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1021)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1022)dates are extracted from date_parameters_list, reformatted (if appropriate), and then written back into the[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1023)list in the new format. Dates in date_parameters_list are presumed here to be valid (no errors). This function[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1024)returns true when a date has been reformatted, false else. Actual reformatting is done by reformatter().[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1025)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1026)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1027)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1028)local function reformat_dates (date_parameters_list, format)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1029)local all = false;-- set to false to skip access- and archive-dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1030)local len_p = 'l';-- default publication date length shall be long[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1031)local len_a = 'l';-- default access-/archive-date length shall be long[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1032)local result = false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1033)local new_date;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1034)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1035)if format:match('%a+%-all') then-- manual df keyword; auto df keyword when length not specified in {{[use xxx dates](https://freemwiki.com/wiki/Template:Use_xxx_dates "Template:Use xxx dates")}}; [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1036)format = format:match('(%a+)%-all');-- extract the format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1037)all = true;-- all dates are long format dates because this keyword doesn't specify length[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1038)elseif format:match('%a+%-[lsy][sy]?') then-- auto df keywords; internal only[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1039)all = true;-- auto df applies to all dates; use length specified by capture len_p for all dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1040)format, len_p, len_a = format:match('(%a+)%-([lsy])([sy]?)');-- extract the format and length keywords[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1041)if 'y' == len_p then-- because allowed by MOS:DATEUNIFY (sort of) range dates and My dates not reformatted[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1042)format = 'ymd';-- override {{[use xxx dates](https://freemwiki.com/wiki/Template:Use_xxx_dates "Template:Use xxx dates")}}[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1043)elseif (not is_set(len_a)) or (len_p == len_a) then-- no access-/archive-date length specified or same length as publication dates then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1044)len_a = len_p;-- in case len_a not set[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1045)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1046)end-- else only publication dates and they are long[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1047)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1048)for param_name, param_val in pairs (date_parameters_list) do-- for each date-holding parameter in the list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1049)if is_set (param_val.val) then-- if the parameter has a value[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1050)if not (not all and in_array (param_name, {'access-date', 'archive-date'})) then-- skip access- or archive-date unless format is xxx-all; yeah, ugly; TODO: find a better way[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1051)for pattern_idx, pattern in pairs (patterns_t) do[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1052)if mw.ustring.match (param_val.val, pattern[1]) then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1053)if all and in_array (param_name, {'access-date', 'archive-date'}) then-- if this date is an access- or archive-date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1054)new_date = reformatter (param_val.val, pattern_idx, (('y' == len_a) and 'ymd') or format, len_a);-- choose ymd or dmy/mdy according to len_a setting[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1055)else-- all other dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1056)new_date = reformatter (param_val.val, pattern_idx, format, len_p);[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1057)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1058)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1059)if new_date then-- set when date was reformatted[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1060)date_parameters_list[param_name].val = new_date;-- update date in date list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1061)result = true;-- and announce that changes have been made[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1062)break;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1063)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1064)end-- if[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1065)end-- for[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1066)end-- if[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1067)end-- if[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1068)end-- for[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1069)return result;-- declare boolean result and done[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1070)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1071)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1072)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1073)--[[--------------------------< D A T E _ H Y P H E N _ T O _ D A S H >----------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1074)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1075)Loops through the list of date-holding parameters and converts any hyphen to an ndash. Not called if the cs1|2[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1076)template has any date errors.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1077)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1078)Modifies the date_parameters_list and returns true if hyphens are replaced, else returns false.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1079)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1080)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1081)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1082)local function date_hyphen_to_dash (date_parameters_list)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1083)local result = false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1084)local n;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1085)for param_name, param_val in pairs(date_parameters_list) do-- for each date-holding parameter in the list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1086)if is_set (param_val.val) and[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1087)not mw.ustring.match (param_val.val, patterns_t.ymd[1]) then-- for those that are not ymd dates (ustring because here digits may not be Western)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1088)param_val.val, n = param_val.val:gsub ('%-', '–');-- replace any hyphen with ndash[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1089)if 0 ~= n then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1090)date_parameters_list[param_name].val = param_val.val;-- update the list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1091)result = true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1092)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1093)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1094)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1095)return result;-- so we know if any hyphens were replaced[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1096)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1097)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1098)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1099)--[[-------------------------< D A T E _ N A M E _ X L A T E >------------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1100)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1101)Attempts to translate English date names to local-language date names using names supplied by MediaWiki's[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1102)date parser function. This is simple name-for-name replacement and may not work for all languages.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1103)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1104)if xlat_dig is true, this function will also translate Western (English) digits to the local language's digits.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1105)This will also translate ymd dates.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1106)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1107)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1108)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1109)local function date_name_xlate (date_parameters_list, xlt_dig)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1110)local xlate;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1111)local mode;-- long or short month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1112)local modified = false;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1113)local date;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1114)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1115)local sources_t = {[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1116){cfg.date_names.en.long, cfg.date_names.inv_local_long},-- for translating long English month names to long local month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1117){cfg.date_names.en.short, cfg.date_names.inv_local_short},-- short month names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1118){cfg.date_names.en.quarter, cfg.date_names.inv_local_quarter},-- quarter date names[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1119){cfg.date_names.en.season, cfg.date_names.inv_local_season},-- season date nam[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1120){cfg.date_names.en.named, cfg.date_names.inv_local_named},-- named dates[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1121)}[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1122)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1123)local function is_xlateable (month)-- local function to get local date name that replaces existing English-language date name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1124)for _, date_names_t in ipairs (sources_t) do-- for each sequence table in date_names_t[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1125)if date_names_t[1][month] then-- if date name is English month (long or short), quarter, season or named and[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1126)if date_names_t[2][date_names_t[1][month]] then-- if there is a matching local date name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1127)return date_names_t[2][date_names_t[1][month]];-- return the local date name[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1128)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1129)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1130)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1131)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1132)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1133)for param_name, param_val in pairs(date_parameters_list) do-- for each date-holding parameter in the list[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1134)if is_set(param_val.val) then-- if the parameter has a value[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1135)date = param_val.val;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1136)for month in mw.ustring.gmatch (date, '[%a ]+') do-- iterate through all date names in the date (single date or date range)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1137)month = mw.text.trim (month);-- this because quarterly dates contain whitespace[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1138)xlate = is_xlateable (month);-- get translate ; returns translation or nil[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1139)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1140)if xlate then[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1141)date = mw.ustring.gsub (date, month, xlate);-- replace the English with the translation[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1142)date_parameters_list[param_name].val = date;-- save the translated date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1143)modified = true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1144)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1145)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1146)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1147)if xlt_dig then-- shall we also translate digits?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1148)date = date:gsub ('%d', cfg.date_names.xlate_digits);-- translate digits from Western to 'local digits'[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1149)date_parameters_list[param_name].val = date;-- save the translated date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1150)modified = true;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1151)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1152)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1153)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1154)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1155)return modified;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1156)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1157)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1158)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1159)--[[--------------------------< S E T _ S E L E C T E D _ M O D U L E S >--------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1160)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1161)Sets local imported functions table to same (live or sandbox) as that used by the other modules.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1162)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1163)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1164)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1165)local function set_selected_modules (cfg_table_ptr, utilities_page_ptr)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1166)add_prop_cat = utilities_page_ptr.add_prop_cat ;-- import functions from selected Module:Citation/CS1/Utilities module[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1167)is_set = utilities_page_ptr.is_set;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1168)in_array = utilities_page_ptr.in_array;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1169)set_message = utilities_page_ptr.set_message;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1170)substitute = utilities_page_ptr.substitute;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1171)wrap_style = utilities_page_ptr.wrap_style;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1172)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1173)cfg = cfg_table_ptr;-- import tables from selected Module:Citation/CS1/Configuration[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1174)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1175)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1176)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1177)--[[--------------------------< A R C H I V E _ D A T E _ C H E C K >------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1178)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1179)Compare value in |archive-date= with the timestamp in Wayback machine urls. Emits an error message with suggested[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1180)date from the |archive-url= timestamp in an appropriate format when the value in |archive-date= does not match[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1181)the timestamp.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1182)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1183)this function never called when any date in a cs1|2 template has errors[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1184)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1185)error message suggests new |archive-date= value in an appropriate format specified by . is either [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1186)|df= or cfg.global_df in that order. If is nil, suggested date has format from |archive-date=. There is[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1187)a caveat: when |df=dmy or |df=mdy, the reformatter leaves |access-date= and |archive-date= formats as they are.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1188)The error message suggested date is passed to the formatter as YYYY-MM-DD so when |df=dmy or |df=mdy, the format[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1189)is not changed.[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1190)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1191)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1192)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1193)local function archive_date_check (archive_date, archive_url_timestamp, df)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1194)local archive_date_format = 'dmy-y';-- holds the date format of date in |archive-date; default to ymd; 'dmy' used here to spoof reformat_dates() [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1195)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1196)for _, v_t in ipairs ({{'dMy', 'dmy-all'}, {'Mdy', 'mdy-all'}}) do-- is |archive-date= format dmy or mdy?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1197)if archive_date:match (patterns_t[v_t[1]][1]) then-- does the pattern match?[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1198)archive_date_format = cfg.keywords_xlate[v_t[2]];-- get appropriate |df= supported keyword from the i18n translator table[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1199)break;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1200)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1201)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1202)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1203)local dates_t = {};[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1204)dates_t['archive-date'] = {val=archive_date, name=''};-- setup to call reformat_dates(); never called when errors so unset as not needed[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1205)reformat_dates (dates_t, 'dmy-y');-- reformat |archive-date= to ymd; 'dmy' used here to spoof reformat_dates()[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1206)local archive_url_date = archive_url_timestamp:gsub ('(%d%d%d%d)(%d%d)(%d%d)%d*', '%1-%2-%3');-- make ymd format date from timestamp[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1207)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1208)if dates_t['archive-date'].val == archive_url_date then-- are the two dates the same[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1209)return;-- yes, done[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1210)else[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1211)dates_t['archive-date'] = {val=archive_url_date, name=''};-- setup to call reformat_dates() with the timestamp date[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1212)reformat_dates (dates_t, df or archive_date_format);-- reformat timestamp to format specified by or format used in |archive-date= [](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1213)archive_url_date = dates_t['archive-date'].val;[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1214)set_message ('err_archive_date_url_ts_mismatch', archive_url_date);-- emit an error message[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1215)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1216)end[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1217)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1218)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1219)--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1220)]][](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1221)[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1222)return {-- return exported functions[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1223)archive_date_check = archive_date_check,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1224)date_hyphen_to_dash = date_hyphen_to_dash,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1225)date_name_xlate = date_name_xlate,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1226)dates = dates,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1227)reformat_dates = reformat_dates,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1228)set_selected_modules = set_selected_modules,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1229)year_check = year_check,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1230)year_date_check = year_date_check,[](https://freemwiki.com/index.php?oldid=579716&title=Module%3ACitation%2FCS1%2FDate_validation#L-1231)} Retrieved from "[https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&oldid=579716](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&oldid=579716)" * This page was last edited on 21 October 2025, at 06:18. * Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727). * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) * [Mobile view](https://freemwiki.com/index.php?title=Module:Citation/CS1/Date_validation&oldid=579716&mobileaction=toggle_view_mobile)