Module:Complex date: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
No edit summary |
||
| Line 119: | Line 119: | ||
return p._otherCalend(datetype, first, frame:callParserFunction('#time', 'xmY', first), lang, era) | return p._otherCalend(datetype, first, frame:callParserFunction('#time', 'xmY', first), lang, era) | ||
end | end | ||
elseif second ~= '' then | elseif second ~= '' then | ||
mw.log('meow') | |||
if datetype == '~' or datetype == 'ca' or datetype == 'circa' then | if datetype == '~' or datetype == 'ca' or datetype == 'circa' then | ||
datetype = 'circa2' | datetype = 'circa2' | ||
| Line 152: | Line 154: | ||
end | end | ||
return p._oneDate(datetype, first, lang) | return p._oneDate(datetype, first, lang) | ||
end | end | ||
end | end | ||
return p | return p | ||
Revision as of 02:52, 20 December 2014
This documentation is transcluded from Module:Complex date/doc.
local p = {}
local era = require('Module:Era')
local i18n = require('Module:i18n/other date')
local langSwitch = require('Module:Fallback')._langSwitch
local maintenancecat = 'Pages with incorrect usage of Module:Other date'
local datemod = require('Module:Date')
local makeera = require('Module:Era')._era
local linguistic = require('Module:Linguistic')
function yearunknown(lang)
return langSwitch(i18n['yeark unknown'], lang)
end
function p._otherCalend(datetype, first, second, lang, era)
-- hack to make use of ISOdate
local frame = {}
frame.args = {lang=lang}
frame.args[1] = first
first = datemod.ISOdate(frame)
frame.args[1] = second
second = datemod.ISOdate(frame)
----
if datetype == 'islamic' then
if era == nil then era = 'AD' end
return makeera(first, era, lang) .. ' (' .. makeera(second, 'AH', lang) .. ')'
elseif datetype == 'julian' then
first = makeera(first, era, lang);
second = makeera(second, era, lang);
local pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function
local outputstr
if pattern then
outputstr = mw.ustring.gsub(pattern, '$date1', first)
outputstr = mw.ustring.gsub(outputstr, '$date2', second)
else
outputstr = linguistic.conj({first, second}, lang)
end
return outputstr
end
end
function p._oneDate(datetype, first, lang, era)
-- hack to make use of ISOdate
local frame = {}
frame.args = {lang=lang}
frame.args[1] = first
first = datemod.ISOdate(frame)
----
if datetype ~= 'era' then
local pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function
local outputstr
if pattern then
outputstr = mw.ustring.gsub(pattern, '$date1', first)
else
outputstr = linguistic.conj({first}, lang)
end
else
outputstr = first
end
return makeera(outputstr, era, lang)
end
function p._twoDate(datetype, first, second, lang, era)
if datetype ~= 'century' then
-- hack to make use of ISOdate
local frame = {}
frame.args = {lang=lang}
frame.args[1] = first
first = datemod.ISOdate(frame)
frame.args[1] = second
second = datemod.ISOdate(frame)
----
end
local pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function
local outputstr
if pattern then
outputstr = mw.ustring.gsub(pattern, '$date1', first)
outputstr = mw.ustring.gsub(outputstr, '$date2', second)
else
outputstr = linguistic.conj({first, second}, lang)
end
return makeera(outputstr, era, lang)
end
function p.otherdate(frame)
local args = frame.args
local lang = frame.args.lang
if not lang or lang == '' then
lang = frame:preprocess('{{int:lang}}')
end
local datetype = string.lower(args[1])
local first = args[2]
local second
local era
if args[1] == 'BCE' or args[1] == 'BC' or args[1] == 'CE' or args[1] == 'AD' then
era = args[1]
datetype = 'era'
elseif args[3] == 'BEFORE PRESENT' or args[3] == 'BP' or args[3] == 'BCE' or args[3] == 'BC' or args[3] == 'CE' or args[3] == 'AD' then
era = args[3]
elseif args[3] ~= '' then
second = args[3]
end
if args['era'] ~= '' then
era = args['era']
else
era = nil
end
if datetype == 'islamic' or datetype == 'julian' then
if second then
return p._otherCalend(datetype, first, second, lang, era)
else
return p._otherCalend(datetype, first, frame:callParserFunction('#time', 'xmY', first), lang, era)
end
elseif second ~= '' then
mw.log('meow')
if datetype == '~' or datetype == 'ca' or datetype == 'circa' then
datetype = 'circa2'
elseif datetype == '&' then
datetype = 'and'
end
return p._twoDate(datetype, first, second, lang, era)
else
if datatype == '<' or datatype == 'b' then
datatype = 'before'
elseif datatype == '>' or datatype == 'a' then
datatype = 'after'
elseif datatype == '~' or datatype == 'ca' then
datatype = 'circa'
elseif datatype == 's' then
datatype = 'decade'
elseif datatype == 'fall' then
datatype = 'autumn'
elseif datatype == 'beginning' then
datatype = 'early'
elseif datatype == 'middle' then
datatype = 'mid'
elseif datatype == 'end' then
datatype = 'late'
elseif datatype == '1half' or datatype == '1sthalf' then
datatype = 'firsthalf'
elseif datatype == '2half' or datatype == '2ndhalf' then
datatype = 'secondhalf'
elseif datatype == '?' then
datatype = 'unknown'
end
return p._oneDate(datetype, first, lang)
end
end
return p