Modul:Vorlage:FormatDate: Unterschied zwischen den Versionen
te>Antonsusi K |
te>Antonsusi K |
||
Zeile 134: | Zeile 134: | ||
-- | -- | ||
function p.Execute(frame) | function p.Execute(frame) | ||
− | return | + | return Run(frame:getParent()) |
end | end | ||
return p | return p |
Version vom 2. Juni 2013, 00:04 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Vorlage:FormatDate/Doku erstellt werden
local p = {}
-- Trennen der Parameter
local function Split(str)
local Tbl = {}
local Teil=""
local pos = 0
Tbl.y = 0
Tbl.m = 0
Tbl.d = 0
-- str = mw.ustring.gsub(str,'/','-'); -- Evtl. Erweiterung auf Slashstring.
pos = mw.ustring.find(str,'-',1,true);
if pos == 1 then -- Minuszeichen am Anfang - nochmal suchen
pos = mw.ustring.find(str,'-',2,true);
end
if not pos then
return Tbl
end
Teil = mw.ustring.sub(str,1,pos-1)
Tbl.y = tonumber(Teil) or 'x'
str = mw.ustring.sub(str,pos+1, -1)
pos = mw.ustring.find(str,'-',1,true);
if not pos or pos == 0 then
return Tbl
end
Teil = mw.ustring.sub(str,1,pos-1)
Tbl.m = tonumber(Teil) or 0
Teil = mw.ustring.sub(str,pos+1, -1)
if #Teil == 0 then
return Tbl
end
Tbl.d = tonumber(Teil) or 0
return Tbl
end
--
local function CheckDate(Tbl)
if ( Tbl.m == 1 or Tbl.m == 3 or Tbl.m == 5 or Tbl.m == 7 or Tbl.m == 8 or Tbl.m == 10 or Tbl.m == 12 ) and Tbl.d > 31 then
return false;
end
if Tbl.m == 2 then -- Die greg. Sonderregeln werden ignoriert.
if Tbl.y % 4 ~= 0 and Tbl.d > 28 then return false; end
if Tbl.y % 4 == 0 and Tbl.d > 29 then return false; end
end
-- Hier nur noch 30-Tage-Monate übrig.
if Tbl.d > 30 then return false; end
return true;
end
--
function Run(frame)
local T_F = {"Januar","Februar", "März", "April", "Mai","Juni", "Juli", "August","September","Oktober","November","Dezember","Jänner"}
local T_M = {"Jan.","Feb.", "Mrz", "Apr.", "Mai","Jun.", "Jul.", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
local T_S = {"Jan.","Feb.", "März", "Apr.", "Mai","Juni", "Juli", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
local Text = "";
local AT = false;
local NBSP = false;
local LINK = false;
local VCHR = "";
local STIL = 'F';
local Tbl = {}
local Pars = {}
for i, v in pairs(frame.args) do
Pars[i] = v or ""
end
if mw.ustring.lower(Pars[2]) == "nbsp" or mw.ustring.lower(Pars[3]) == "nbsp" or mw.ustring.lower(Pars[4]) == "nbsp" then NBSP = true; end
if mw.ustring.lower(Pars[2]) == "link" or mw.ustring.lower(Pars[3]) == "link" or mw.ustring.lower(Pars[4]) == "link" then LINK = true; end
if mw.ustring.upper(Pars[2]) == "M" or mw.ustring.upper(Pars[3]) == "M" or mw.ustring.upper(Pars[4]) == "M" then STIL = 'M'; end
if mw.ustring.upper(Pars[2]) == "S" or mw.ustring.upper(Pars[3]) == "S" or mw.ustring.upper(Pars[4]) == "S" then STIL = 'S'; end
if mw.ustring.lower(Pars['AT']) == "ja" then AT = true; end
Tbl = Split(frame.args[1])
if Tbl.y == 'x' then
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Jahr!</span>'
return Text
end
if Tbl.m > 12 or Tbl.m < 0 then
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Monat!</span>'
return Text
end
if Tbl.y <= 0 then
Tbl.y = 1 - Tbl.y
VCHR = " v. Chr.";
end
if Tbl.d > 0 then
if CheckDate(Tbl) then
Text = tostring(Tbl.d) .. '. '
else
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiges Datum!</span>'
return Text
end
end
if Tbl.m > 0 then
if LINK then
if Tbl.d == 0 then
Linkziel =T_F[Tbl.m]
else
Linkziel = tostring(Tbl.d) .. ". " .. T_F[Tbl.m]
end
end
if AT and Tbl.m == 1 then
Tbl.m = 13
end
if STIL == 'M' then
Text = Text .. T_M[Tbl.m]
elseif STIL == 'S' then
Text = Text .. T_S[Tbl.m]
else
Text = Text .. T_F[Tbl.m]
end
if LINK then
Text = "[[" .. Linkziel .. "|" .. Text .. "]]"
end
if NBSP then
Text = Text .. " "
else
Text = Text .. " "
end
end
if LINK then
Text = Text .. "[[" .. tostring(Tbl.y) .. VCHR .. "]]"
else
Text = Text .. tostring(Tbl.y) .. VCHR
end
return Text
end
--
function p.Execute(frame)
return Run(frame:getParent())
end
return p