Module:Complex date: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
No edit summary |
||
| Line 12: | Line 12: | ||
end | end | ||
function p._twoDate(datetype, | function p._twoDate(datetype, first, second, lang, era) | ||
-- hack to make use of ISOdate | -- hack to make use of ISOdate | ||
local frame = {} | local frame = {} | ||
frame.args = {lang=lang} | frame.args = {lang=lang} | ||
frame.args[1] = | frame.args[1] = first | ||
begin = datemod.ISOdate(frame) | begin = datemod.ISOdate(frame) | ||
frame.args[1] = | frame.args[1] = second | ||
ending = datemod.ISOdate(frame) | ending = datemod.ISOdate(frame) | ||
---- | ---- | ||
local pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function | local pattern | ||
if datetype == 'Islamic' then | |||
local islamic = makeera(second, 'AH', lang) | |||
return makeera(first, era, lang) + ' (' + islamic + ')' | |||
else | |||
pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function | |||
end | |||
local outputstr | local outputstr | ||
if pattern then | if pattern then | ||
outputstr = mw.ustring.gsub(pattern, '$date1', | outputstr = mw.ustring.gsub(pattern, '$date1', first) | ||
outputstr = mw.ustring.gsub(outputstr, '$date2', | outputstr = mw.ustring.gsub(outputstr, '$date2', second) | ||
else | else | ||
outputstr = linguistic.conj({ | outputstr = linguistic.conj({first, second}, lang) | ||
end | end | ||
return makeera(outputstr, era, lang) | return makeera(outputstr, era, lang) | ||
| Line 56: | Line 63: | ||
era = nil | era = nil | ||
end | end | ||
if second then | if second then | ||
if datetype == '~' or datetype == 'ca' or datetype == 'circa' then | if datetype == '~' or datetype == 'ca' or datetype == 'circa' then | ||
datetype = 'circa2' | datetype = 'circa2' | ||
Revision as of 01:06, 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._twoDate(datetype, first, second, lang, era)
-- hack to make use of ISOdate
local frame = {}
frame.args = {lang=lang}
frame.args[1] = first
begin = datemod.ISOdate(frame)
frame.args[1] = second
ending = datemod.ISOdate(frame)
----
local pattern
if datetype == 'Islamic' then
local islamic = makeera(second, 'AH', lang)
return makeera(first, era, lang) + ' (' + islamic + ')'
else
pattern = i18n[datetype][lang] -- checks if there is a special case for this and, else use linguistic.conj function
end
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 = args[1]
local first = args[2]
local second
local era
if 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] ~= nil then
second = args[3]
end
if args['era'] ~= '' then
era = args['era']
else
era = nil
end
if second then
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
return second, datetype
--return p._oneDate(datetype, first, lang)
end
if datetype == 'year unknown' then
return p._yearunknown(lang)
end
end
return p