https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AComplex_date Modul:Complex date - Versionsgeschichte 2025-06-06T18:01:36Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.4 https://de.wikipedia.org/w/index.php?title=Modul:Complex_date&diff=195600313&oldid=prev Ederporto: Modul:WikidataIB hat dieses Modul als Abhängigkeit, daher importiere ich das englische Äquivalent, damit es richtig funktioniert. 2020-01-07T16:46:38Z <p>Modul:WikidataIB hat dieses Modul als Abhängigkeit, daher importiere ich das englische Äquivalent, damit es richtig funktioniert.</p> <p><b>Neue Seite</b></p><div>--[[ <br /> __ __ _ _ ____ _ _ _ <br /> | \/ | ___ __| |_ _| | ___ _ / ___|___ _ __ ___ _ __ | | _____ __ __| | __ _| |_ ___ <br /> | |\/| |/ _ \ / _` | | | | |/ _ (_) | / _ \| &#039;_ ` _ \| &#039;_ \| |/ _ \ \/ / / _` |/ _` | __/ _ \<br /> | | | | (_) | (_| | |_| | | __/_| |__| (_) | | | | | | |_) | | __/&gt; &lt; | (_| | (_| | || __/<br /> |_| |_|\___/ \__,_|\__,_|_|\___(_)\____\___/|_| |_| |_| .__/|_|\___/_/\_\ \__,_|\__,_|\__\___|<br /> |_| <br /> <br /> This module is intended for creation of complex date phrases in variety of languages.<br /> <br /> Once deployed, please do not modify this code without applying the changes first at Module:Complex date/sandbox and testing <br /> at Module:Complex date/sandbox/testcases.<br /> <br /> Authors and maintainers:<br /> * User:Sn1per - first draft of the original version <br /> * User:Jarekt - corrections and expansion of the original version <br /> <br /> ]]<br /> <br /> -- List of external modules and functions<br /> local p = {Error = nil}<br /> local i18n = require(&#039;Module:i18n/complex date&#039;)<br /> local ISOdate = require(&#039;Module:ISOdate&#039;)._ISOdate<br /> local Calendar -- loaded lazily<br /> <br /> -- ==================================================<br /> -- === Internal functions ===========================<br /> -- ==================================================<br /> <br /> local function langSwitch(list,lang)<br /> local langList = mw.language.getFallbacksFor(lang)<br /> table.insert(langList,1,lang)<br /> table.insert(langList,math.max(#langList,2),&#039;default&#039;)<br /> for i,language in ipairs(langList) do<br /> if list[language] then<br /> return list[language]<br /> end<br /> end<br /> end<br /> <br /> local function formatnum1(numStr, lang)<br /> -- mostly require(&#039;Module:Formatnum&#039;).formatNum function used to translate a number to use different numeral characters, <br /> -- except that it it does not call that function unless the language is on the list &quot;LList&quot;<br /> local LList = {bn=1,bpy=1,kn=1,hi=1,mr=1,new=1,pa=1,gu=1,fa=1,glk=1,mzn=1,ur=1,ar=1,ckb=1,ks=1,lo=1,[&#039;or&#039;]=1,bo=1,[&#039;ml-old&#039;]=1,mn=1,te=1,th=1}<br /> if LList[lang] then -- call only when the language is on the list<br /> numStr = require(&#039;Module:Formatnum&#039;).formatNum(numStr, lang, 1)<br /> end<br /> return numStr<br /> end<br /> <br /> local function getISODate(datestr, datetype, lang, num, case)<br /> -- translate dates in the format YYYY, YYYY-MM, and YYYY-MM-DD<br /> if not case and i18n.Translations[datetype] then<br /> -- look up the grammatical case needed and call ISOdate module<br /> local rec = langSwitch(i18n.Translations[datetype], lang)<br /> if type(rec)==&#039;table&#039; then<br /> case = rec.case[num]<br /> end<br /> end<br /> return ISOdate(datestr, lang, case, &#039;&#039;, 1)<br /> end<br /> <br /> local function translatePhrase(date1, date2, operation, lang, state)<br /> -- use tables in Module:i18n/complex date to translate a phrase<br /> if not i18n.Translations[operation] then<br /> p.Error = string.format(&#039;&lt;span style=&quot;background-color:red;&quot;&gt;Error in [[Module:Complex date]]: input parameter &quot;%s&quot; is not recognized.&lt;/span&gt;&#039;, operation or &#039;nil&#039;)<br /> return &#039;&#039;<br /> end<br /> local dateStr = langSwitch(i18n.Translations[operation], lang)<br /> if type(dateStr)==&#039;table&#039; then<br /> dateStr = dateStr[1]<br /> end<br /> if type(dateStr)==&#039;function&#039; then<br /> local success<br /> local nDates = i18n.Translations[operation][&#039;nDates&#039;]<br /> if nDates==2 then -- 2 date phrase<br /> success, dateStr = pcall(dateStr, date1, date2, state)<br /> else -- 1 date phrase<br /> success, dateStr = pcall(dateStr, date1, state)<br /> end<br /> end<br /> <br /> if type(dateStr)==&#039;string&#039; then<br /> -- replace parts of the string &#039;$date1&#039; and &#039;$date2&#039; with date1 and date2 strings<br /> dateStr = mw.ustring.gsub(dateStr, &#039;$date1&#039;, date1)<br /> dateStr = mw.ustring.gsub(dateStr, &#039;$date2&#039;, date2)<br /> else<br /> -- Special case of more complex phrases that can be build out of simple phrases<br /> -- If complex case is not translated to &quot;lang&quot; than build it out of simpler ones<br /> local x = dateStr<br /> dateStr = p._complex_date(x.conj, x.adj1, date1, x.units1, x.era1, x.adj2, date2, x.units2, x.era2, lang, 2)<br /> end<br /> return dateStr<br /> end<br /> <br /> local function oneDatePhrase(dateStr, adj, era, units, lang, num, case, state)<br /> -- translate a single date phrase<br /> if num==2 then<br /> state.adj, state.era, state.units, state.precision = state.adj2, state.era2, state.units2, state.precision2 <br /> end<br /> <br /> -- dateStr can have many forms: ISO date, year or a number for <br /> -- decade, century or millennium<br /> if units == &#039;&#039; then -- unit is &quot;year&quot;, &quot;month&quot;, &quot;day&quot;<br /> dateStr = getISODate(dateStr, adj, lang, num, case)<br /> else -- units is &quot;decade&quot;, &quot;century&quot;, &quot;millennium&#039;&#039;<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, units, lang, state)<br /> end<br /> <br /> -- add adjective (&quot;early&quot;, &quot;mid&quot;, etc.) or preposition (&quot;before&quot;, &quot;after&quot;, <br /> -- &quot;circa&quot;, etc.) to the date<br /> if adj ~= &#039;&#039; then<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, adj, lang, state)<br /> else -- only era?<br /> dateStr = formatnum1(dateStr, lang)<br /> end<br /> <br /> -- add era<br /> if era ~= &#039;&#039; then<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, era, lang, state)<br /> end<br /> return dateStr<br /> end<br /> <br /> local function twoDatePhrase(date1, date2, state, lang)<br /> -- translate a double date phrase<br /> local dateStr, case<br /> local era=&#039;&#039;<br /> if state.era1 == state.era2 then<br /> -- if both eras are the same than add it only once<br /> era = state.era1<br /> state.era1 = &#039;&#039;<br /> state.era2 = &#039;&#039;<br /> end<br /> case = {nil, nil}<br /> if i18n.Translations[state.conj] then<br /> local rec = langSwitch(i18n.Translations[state.conj], lang)<br /> if type(rec)==&#039;table&#039; then<br /> case = rec.case<br /> end<br /> end<br /> date1 = oneDatePhrase(date1, state.adj1, state.era1, state.units1, lang, 1, case[1], state)<br /> date2 = oneDatePhrase(date2, state.adj2, state.era2, state.units2, lang, 2, case[2], state)<br /> dateStr = translatePhrase(date1, date2, state.conj, lang, state)<br /> if era ~= &#039;&#039; then<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, era, lang, state)<br /> end<br /> return dateStr<br /> end<br /> <br /> local function otherPhrases(date1, date2, operation, era, lang, state)<br /> -- translate specialized phrases<br /> local dateStr = &#039;&#039;<br /> <br /> if operation == &#039;islamic&#039; then<br /> if date2==&#039;&#039; then date2 = mw.getCurrentFrame():callParserFunction(&#039;#time&#039;, &#039;xmY&#039;, date1) end<br /> date1 = getISODate(date1, operation, lang, 1, nil)<br /> date2 = getISODate(date2, operation, lang, 2, nil)<br /> if era == &#039;&#039; then era = &#039;ad&#039; end<br /> dateStr = translatePhrase(date1, &#039;&#039;, era, lang, state) .. &#039; (&#039; .. translatePhrase(date2, &#039;&#039;, &#039;ah&#039;, lang, state) .. &#039;)&#039;<br /> era = &#039;&#039;<br /> elseif operation == &#039;julian&#039; then<br /> if not date2 and date1 then -- Convert from Julian to Gregorian calendar date<br /> if Calendar == nil then<br /> Calendar = require(&quot;Module:Calendar&quot;)<br /> end<br /> local JDN = Calendar._date2jdn(date1, 0)<br /> if JDN then<br /> date2 = date1 -- first date is assumed to be Julian<br /> date1 = Calendar._jdn2date(JDN, 1)<br /> end<br /> end<br /> date1 = getISODate(date1, operation, lang, 1, nil)<br /> date2 = getISODate(date2, operation, lang, 2, nil)<br /> dateStr = translatePhrase(date1, date2, operation, lang, state)<br /> dateStr = mw.ustring.gsub(mw.ustring.gsub(dateStr, &#039;%( &#039;, &#039;(&#039;), &#039; %)&#039;, &#039;)&#039;) -- in case date2 is empty<br /> elseif operation == &#039;turn of the year&#039; or operation == &#039;turn of the decade&#039; or operation == &#039;turn of the century&#039; then<br /> local dt = 1<br /> if operation == &#039;turn of the decade&#039; then dt=10 end<br /> if not date2 or date2==&#039;&#039; then date2=tostring(tonumber(date1)-dt) end<br /> if era~=&#039;bp&#039; and era~=&#039;bc&#039; then date1, date2 = date2, date1 end<br /> if operation == &#039;turn of the year&#039; then<br /> date1 = ISOdate(date1, lang, &#039;&#039;, &#039;&#039;, 1)<br /> date2 = ISOdate(date2, lang, &#039;&#039;, &#039;&#039;, 1)<br /> else<br /> date1 = formatnum1(date1, lang)<br /> date2 = formatnum1(date2, lang)<br /> end<br /> dateStr = translatePhrase(date1, date2, operation, lang, state)<br /> elseif operation == &#039;year unknown&#039; then<br /> dateStr = translatePhrase(&#039;&#039;, &#039;&#039;, operation, lang, state)<br /> elseif operation == &#039;unknown&#039; then<br /> dateStr = tostring(mw.message.new( &quot;exif-unknowndate&quot; ):inLanguage( lang ))<br /> end<br /> <br /> -- add era<br /> if era ~= &#039;&#039; then<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, era, lang, state)<br /> end<br /> return dateStr<br /> end<br /> <br /> local function checkAliases(str1, str2, sType)<br /> -- some inputs have many aliases - reconcile them and ensure string is playing a proper role <br /> local out = &#039;&#039;<br /> if str1 and str1~=&#039;&#039; then<br /> a = i18n.Synonyms[str1] -- look up synonyms of &quot;str1&quot;<br /> if a then<br /> out = a[1]<br /> else<br /> p.Error = string.format(&#039;&lt;span style=&quot;background-color:red;&quot;&gt;Error in [[Module:Complex date]]: %s is not recognized.&lt;/span&gt;&#039;, str1)<br /> end<br /> elseif str2 and str2~=&#039;&#039; then -- if &quot;str1&quot; of type &quot;sType&quot; is empty than maybe ...<br /> a = i18n.Synonyms[str2] -- ...&quot;str2&quot; is of the same type and is not empty<br /> if a and a[2]==sType then<br /> out = a[1]<br /> str2 = &#039;&#039;<br /> end<br /> end<br /> return out, str2<br /> end<br /> <br /> local function datePrecision(dateStr, units) <br /> -- &quot;in this module &quot;Units&quot; is a string like millennium, century, or decade<br /> -- &quot;precision&quot; is wikibase compatible date precision number: 6=millennium, 7=century, 8=decade, 9=year, 10=month, 11=day<br /> -- based on string or numeric input calculate &quot;Units&quot; and &quot;precision&quot;<br /> local dateNum = tonumber(dateStr);<br /> if type(units)==&#039;number&#039; then<br /> precision = units<br /> if precision&gt;11 then precision=11 end -- clip the range of precision values<br /> if precision==6 then units=&#039;millennium&#039; <br /> elseif precision==7 then units=&#039;century&#039;<br /> elseif precision==8 then units=&#039;decade&#039;<br /> else units = &#039;&#039;<br /> end<br /> elseif type(units)==&#039;string&#039; then<br /> units = string.lower(units);<br /> if units==&#039;millennium&#039; then precision=6<br /> elseif units==&#039;century&#039; then precision=7<br /> elseif units==&#039;decade&#039; then precision=8<br /> else precision=9<br /> end<br /> end<br /> if units==&#039;&#039; or precision==9 then<br /> local sLen = mw.ustring.len(dateStr)<br /> if sLen&lt;= 4 then precision=9<br /> elseif sLen== 7 then precision=10<br /> elseif sLen&gt;=10 then precision=11<br /> end<br /> units=&#039;&#039;<br /> end<br /> if precision==6 and dateStr.match( dateStr, &#039;%d000&#039; )~=nil then <br /> dateStr = tostring(math.floor(tonumber(dateStr)/1000) +1)<br /> elseif precision==7 and mw.ustring.match( dateStr, &#039;%d%d00&#039; )~=nil then<br /> dateStr = tostring(math.floor(tonumber(dateStr)/100) +1)<br /> end<br /> <br /> return dateStr, units, precision<br /> end<br /> <br /> <br /> local function isodate2timestamp(dateStr, precision, era)<br /> -- convert date string to timestamps used by Quick Statements<br /> local tStamp = nil<br /> if era == &#039;ah&#039; or precision&lt;6 then<br /> return nil<br /> elseif era ~= &#039;&#039; then<br /> eraLUT = {ad=&#039;+&#039;, bc=&#039;-&#039;, bp=&#039;-&#039; }<br /> era = eraLUT[era]<br /> else<br /> era=&#039;+&#039;<br /> end<br /> <br /> -- convert isodate to timestamp used by quick statements<br /> if precision&gt;=9 then <br /> if string.match(dateStr,&quot;^%d%d%d%d$&quot;) then -- if YYYY format <br /> tStamp = era .. dateStr .. &#039;-00-00T00:00:00Z/9&#039;<br /> elseif string.match(dateStr,&quot;^%d%d%d%d%-%d%d$&quot;) then -- if YYYY-MM format <br /> tStamp = era .. dateStr .. &#039;-00T00:00:00Z/10&#039;<br /> elseif string.match(dateStr,&quot;^%d%d%d%d%-%d%d%-%d%d$&quot;) then -- if YYYY-MM-DD format <br /> tStamp = era .. dateStr .. &#039;T00:00:00Z/11&#039;<br /> end<br /> elseif precision==8 then -- decade<br /> tStamp = era .. dateStr .. &#039;-00-00T00:00:00Z/8&#039;<br /> elseif precision==7 then -- century<br /> local d = tostring(tonumber(dateStr)-1)<br /> tStamp = era .. d .. &#039;50-00-00T00:00:00Z/7&#039;<br /> elseif precision==6 then<br /> local d = tostring(tonumber(dateStr)-1)<br /> tStamp = era .. d .. &#039;500-00-00T00:00:00Z/6&#039;<br /> end<br /> <br /> return tStamp<br /> end<br /> <br /> local function oneDateQScode(dateStr, adj, era, precision)<br /> -- create QuickStatements string for &quot;one date&quot; dates<br /> local outputStr = &#039;&#039;<br /> <br /> local d = isodate2timestamp(dateStr, precision, era)<br /> if not d then<br /> return &#039;&#039;<br /> end<br /> local rLUT = { early=&#039;Q40719727&#039; , mid=&#039;Q40719748&#039;, late=&#039;Q40719766&#039;,<br /> [&#039;1quarter&#039;]=&#039;Q40690303&#039; , [&#039;2quarter&#039;]=&#039;Q40719649&#039; , [&#039;3quarter&#039;]=&#039;Q40719662&#039;, [&#039;4quarter&#039;]=&#039;Q40719674&#039;,<br /> spring=&#039;Q40720559&#039; , summer=&#039;Q40720564&#039; , autumn=&#039;Q40720568&#039; , winter=&#039;Q40720553&#039;,<br /> firsthalf=&#039;Q40719687&#039;, secondhalf=&#039;Q40719707&#039; }<br /> local qLUT = {[&#039;from&#039;]=&#039;P580&#039;, [&#039;until&#039;]=&#039;P582&#039;, [&#039;after&#039;]=&#039;P1319&#039;, [&#039;before&#039;]=&#039;P1326&#039;}<br /> <br /> local refine = rLUT[adj]<br /> local qualitier = qLUT[adj]<br /> <br /> if adj==&#039;&#039; then<br /> outputStr = d<br /> elseif adj==&#039;circa&#039; then<br /> outputStr = d..&quot;,P1480,Q5727902&quot;<br /> elseif refine then<br /> outputStr = d..&quot;,P4241,&quot;..refine<br /> elseif precision&gt;7 and qualitier then<br /> local century = string.gsub(d, &#039;Z%/%d+&#039;, &#039;Z/7&#039;)<br /> outputStr = century ..&quot;,&quot;.. qualitier ..&quot;,&quot;..d<br /> end<br /> return outputStr <br /> end<br /> <br /> local function twoDateQScode(date1, date2, state)<br /> -- create QuickStatements string for &quot;two date&quot; dates<br /> if state.adj1~=&#039;&#039; or state.adj2~=&#039;&#039; or state.era1~=state.era2 then<br /> return &#039;&#039;<br /> end<br /> local outputStr = &#039;&#039;<br /> local d1 = isodate2timestamp(date1, state.precision1, state.era1)<br /> local d2 = isodate2timestamp(date2, state.precision2, state.era2)<br /> if (not d1) or (not d2) then<br /> return &#039;&#039;<br /> end <br /> -- find date with lower precision in common to both dates<br /> local cd<br /> local year1 = string.sub(d1,2,5)<br /> local k = 0<br /> for i = 1,10,1 do <br /> if string.sub(d1,1,i)==string.sub(d2,1,i) then <br /> k = i -- find last matching letter<br /> end<br /> end<br /> if k&gt;=9 then -- same month, since &quot;+YYYY-MM-&quot; is in common<br /> cd = isodate2timestamp(string.sub(d1,2,8), 10, state.era1)<br /> elseif k&gt;=6 and k&lt;9 then -- same year, since &quot;+YYYY-&quot; is in common<br /> cd = isodate2timestamp(year1, 9, state.era1)<br /> elseif k==4 then -- same decade(k=4, precision=8), since &quot;+YYY&quot; is in common<br /> cd = isodate2timestamp(year1, 8, state.era1)<br /> elseif k==3 then -- same century(k=3, precision=7) since &quot;+YY&quot; is in common<br /> local d = tostring(math.floor(tonumber(year1)/100) +1) -- convert 1999 -&gt; 20<br /> cd = isodate2timestamp( d, 7, state.era1)<br /> elseif k==2 then -- same millennium (k=2, precision=6), since &quot;+Y&quot; is in common<br /> local d = tostring(math.floor(tonumber(year1)/1000) +1) -- convert 1999 -&gt; 2<br /> cd = isodate2timestamp( d, 6, state.era1)<br /> else<br /> return &#039;&#039;<br /> end<br /> --if not cd then<br /> -- return &#039; &lt;br/&gt;error: &#039; .. d1..&quot; / &quot; .. d2..&quot; / &quot;.. (cd or &#039;&#039;) ..&quot; / &quot;.. string.sub(d1,2,5)..&quot; / &quot; .. string.sub(d2,2,5)..&quot; / &quot; .. tostring(k)<br /> --end<br /> <br /> --<br /> if state.conj==&#039;from-until&#039; then<br /> outputStr = cd ..&quot;,P580,&quot;.. d1 ..&quot;,P582,&quot;.. d2<br /> elseif state.conj==&#039;between&#039; then<br /> outputStr = cd ..&quot;,P1319,&quot;.. d1 ..&quot;,P1326,&quot;.. d2<br /> elseif state.conj==&#039;circa2&#039; then<br /> outputStr = cd ..&quot;,P1319,&quot;.. d1 ..&quot;,P1326,&quot;.. d2 ..&quot;,P1480,Q5727902&quot;<br /> end<br /> <br /> return outputStr<br /> end<br /> <br /> -- ==================================================<br /> -- === External functions ===========================<br /> -- ==================================================<br /> <br /> function p.Era(frame)<br /> -- process inputs<br /> local dateStr<br /> local args = frame.args<br /> if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then <br /> args.lang = frame:callParserFunction( &quot;int&quot;, &quot;lang&quot; ) -- get user&#039;s chosen language <br /> end<br /> local lang = args[&#039;lang&#039;]<br /> local dateStr = args[&#039;date&#039;] or &#039;&#039;<br /> local eraType = string.lower(args[&#039;era&#039;] or &#039;&#039;)<br /> <br /> dateStr = ISOdate(dateStr, lang, &#039;&#039;, &#039;&#039;, 1)<br /> if eraType then <br /> eraType = checkAliases(eraType ,&#039;&#039;,&#039;e&#039;)<br /> dateStr = translatePhrase(dateStr, &#039;&#039;, eraType, lang, {}) <br /> end<br /> return dateStr<br /> end<br /> <br /> function p._complex_date(conj, adj1, date1, units1, era1, adj2, date2, units2, era2, lang, passNr)<br /> local Output=&#039;&#039;<br /> <br /> -- process inputs and save date in state array<br /> local state = {} <br /> state.conj = string.lower(conj or &#039;&#039;)<br /> state.adj1 = string.lower(adj1 or &#039;&#039;)<br /> state.adj2 = string.lower(adj2 or &#039;&#039;)<br /> state.era1 = string.lower(era1 or &#039;&#039;)<br /> state.era2 = string.lower(era2 or &#039;&#039;)<br /> state.units1 = string.lower(units1 or &#039;&#039;)<br /> state.units2 = string.lower(units2 or &#039;&#039;)<br /> <br /> -- if date 1 is missing but date 2 is provided than swap them<br /> if date1 == &#039;&#039; and date2 ~= &#039;&#039; then<br /> date1 = date2<br /> date2 = &#039;&#039;<br /> state = {adj1 = state.adj2, era1 = state.era2, units1 = state.units2, <br /> adj2 = &#039;&#039;, era2 = &#039;&#039;, units2 = &#039;&#039;, conj=state.conj, num=1}<br /> end<br /> if date2 ~= &#039;&#039; then state.nDates = 2 <br /> elseif date1 ~= &#039;&#039; then state.nDates = 1 <br /> else state.nDates = 0<br /> end<br /> <br /> -- reconcile alternative names for text inputs<br /> local conj = checkAliases(state.conj ,&#039;&#039; ,&#039;j&#039;)<br /> state.adj1 ,conj = checkAliases(state.adj1 ,conj,&#039;a&#039;)<br /> state.units1,conj = checkAliases(state.units1,conj,&#039;p&#039;)<br /> state.era1 ,conj = checkAliases(state.era1 ,conj,&#039;e&#039;)<br /> state.special,conj = checkAliases(&#039;&#039;,conj,&#039;c&#039;)<br /> state.adj2 = checkAliases(state.adj2 ,&#039;&#039;,&#039;a&#039;)<br /> state.units2 = checkAliases(state.units2,&#039;&#039;,&#039;p&#039;)<br /> state.era2 = checkAliases(state.era2 ,&#039;&#039;,&#039;e&#039;)<br /> state.conj = conj<br /> state.lang = lang<br /> if p.Error~=nil then<br /> return nil<br /> end<br /> <br /> -- calculate date precision value<br /> date1, state.units1, state.precision1 = datePrecision(date1, state.units1)<br /> date2, state.units2, state.precision2 = datePrecision(date2, state.units2)<br /> <br /> -- Handle special cases <br /> -- Some complex phrases can be created out of simpler ones. Therefore on pass # 1 we try to create <br /> -- the phrase using complex phrase and if that is not found than on the second pass we try to build<br /> -- the phrase out of the simpler ones<br /> if passNr==1 then<br /> if state.adj1==&#039;circa&#039; and state.nDates == 2 then<br /> state.conj = &#039;circa2&#039;<br /> state.adj1 = &#039;&#039;<br /> state.adj2 = &#039;&#039;<br /> end<br /> if state.nDates == 2 and state.adj1==&#039;late&#039; and state.adj2==&#039;early&#039; and state.conj==&#039;and&#039; <br /> and state.units1==state.units2 and state.era1==state.era2 then<br /> if state.units1==&#039;century&#039; then<br /> state.conj=&#039;turn of the century&#039;<br /> elseif state.units1==&#039;decade&#039; then<br /> state.conj=&#039;turn of the decade&#039;<br /> elseif state.units1==&#039;&#039; then<br /> state.conj=&#039;turn of the year&#039;<br /> end<br /> state.adj1 = &#039;&#039;<br /> state.adj2 = &#039;&#039;<br /> state.units1 = &#039;&#039;<br /> state.units2 = &#039;&#039;<br /> end<br /> end<br /> <br /> local errorStr = string.format(<br /> &#039;\n*conj=%s, adj1=%s, era1=%s, unit1=%s, prec1=%i, adj2=%s, era2=%s, unit2=%s, prec2=%i, special=%s&#039;, <br /> state.conj, state.adj1, state.era1, state.units1, state.precision1,<br /> state.adj2, state.era2, state.units2, state.precision2, state.special) <br /> state.adj, state.era, state.units, state.precision = state.adj1, state.era1, state.units1, state.precision1 <br /> <br /> -- call specialized functions<br /> local QScode = &#039;&#039;<br /> if state.special~=&#039;&#039; then<br /> Output = otherPhrases(date1, date2, state.special, state.era1, lang, state) <br /> elseif state.conj~=&#039;&#039; then<br /> QScode = twoDateQScode(date1, date2, state)<br /> Output = twoDatePhrase(date1, date2, state, lang)<br /> elseif state.adj1~=&#039;&#039; or state.era1~=&#039;&#039; or state.units1~=&#039;&#039; then<br /> Output = oneDatePhrase(date1, state.adj1, state.era1, state.units1, lang, 1, nil, state)<br /> QScode = oneDateQScode(date1, state.adj1, state.era1, state.precision1)<br /> elseif date1~=&#039;&#039; then<br /> Output = ISOdate(date1, lang, &#039;&#039;, &#039;dtstart&#039;, &#039;100-999&#039;)<br /> end<br /> if p.Error~=nil then<br /> return errorStr<br /> end<br /> <br /> -- if there is any wikicode in the string than execute it<br /> if mw.ustring.find(Output, &#039;{&#039;) then<br /> Output = mw.getCurrentFrame():preprocess(Output)<br /> end<br /> if QScode and #QScode&gt;0 then<br /> QScode = &#039; &lt;div style=&quot;display: none;&quot;&gt;date QS:P,&#039; .. QScode .. &#039;&lt;/div&gt;&#039;<br /> end<br /> <br /> return Output .. QScode<br /> end<br /> <br /> function p.complex_date(frame)<br /> -- process inputs<br /> local dateStr, Error<br /> local args = frame.args<br /> if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then <br /> args.lang = frame:callParserFunction( &quot;int&quot;, &quot;lang&quot; ) -- get user&#039;s chosen language <br /> end<br /> local date1 = args[&#039;date1&#039;] or args[&#039;2&#039;] or args[&#039;date&#039;] or &#039;&#039;<br /> local date2 = args[&#039;date2&#039;] or args[&#039;3&#039;] or &#039;&#039;<br /> local conj = args[&#039;conj&#039;] or args[&#039;1&#039;] or &#039;&#039;<br /> local adj1 = args[&#039;adj1&#039;] or args[&#039;adj&#039;] or &#039;&#039;<br /> local adj2 = args[&#039;adj2&#039;] or &#039;&#039;<br /> local units1 = args[&#039;precision1&#039;] or args[&#039;precision&#039;] or &#039;&#039;<br /> local units2 = args[&#039;precision2&#039;] or args[&#039;precision&#039;] or &#039;&#039;<br /> local era1 = args[&#039;era1&#039;] or args[&#039;era&#039;] or &#039;&#039;<br /> local era2 = args[&#039;era2&#039;] or args[&#039;era&#039;] or &#039;&#039;<br /> local lang = args[&#039;lang&#039;]<br /> <br /> dateStr = p._complex_date(conj, adj1, date1, units1, era1, adj2, date2, units2, era2, lang, 1)<br /> if p.Error~=nil then<br /> dateStr = p.Error .. &#039;[[Category:Pages using Complex date template with incorrect parameter]]&#039;<br /> end<br /> return dateStr<br /> end<br /> <br /> return p</div> Ederporto