Modul:Vorlage:FormatDate: Unterschied zwischen den Versionen
te>Antonsusi K |
te>Antonsusi K |
||
Zeile 70: | Zeile 70: | ||
if mw.ustring.upper(Args[2] or "") == "S" or mw.ustring.upper(Args[3] or "") == "S" or mw.ustring.upper(Args[4] or "") == "S" then STIL = 'S'; end | if mw.ustring.upper(Args[2] or "") == "S" or mw.ustring.upper(Args[3] or "") == "S" or mw.ustring.upper(Args[4] or "") == "S" then STIL = 'S'; end | ||
if mw.ustring.lower(Args['AT'] or "") == "ja" then AT = true; end | if mw.ustring.lower(Args['AT'] or "") == "ja" then AT = true; end | ||
+ | if mw.ustring.lower(Args['sort'] or "") ~= "" then SortIt = true; end | ||
IsOk, Tbl = Split(Args[1]) | IsOk, Tbl = Split(Args[1]) | ||
+ | |||
if Tbl.y == 'x' then | if Tbl.y == 'x' then | ||
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Jahr!</span>' | Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Jahr!</span>' | ||
Zeile 80: | Zeile 82: | ||
return Text | return Text | ||
end | end | ||
− | |||
if Tbl.y <= 0 then | if Tbl.y <= 0 then | ||
Tbl.y = 1 - Tbl.y | Tbl.y = 1 - Tbl.y | ||
VCHR = " v. Chr."; | VCHR = " v. Chr."; | ||
end | end | ||
− | |||
if Tbl.d > 0 then | if Tbl.d > 0 then | ||
if CheckDate(Tbl) then | if CheckDate(Tbl) then | ||
Zeile 94: | Zeile 94: | ||
end | end | ||
end | end | ||
− | |||
if Tbl.m > 0 then | if Tbl.m > 0 then | ||
− | |||
if LINK then | if LINK then | ||
if Tbl.d == 0 then | if Tbl.d == 0 then | ||
Zeile 104: | Zeile 102: | ||
end | end | ||
end | end | ||
− | |||
if AT and Tbl.m == 1 then | if AT and Tbl.m == 1 then | ||
Tbl.m = 13 | Tbl.m = 13 | ||
Zeile 124: | Zeile 121: | ||
end | end | ||
end | end | ||
− | |||
if LINK then | if LINK then | ||
Text = Text .. "[[" .. tostring(Tbl.y) .. VCHR .. "]]" | Text = Text .. "[[" .. tostring(Tbl.y) .. VCHR .. "]]" | ||
Zeile 130: | Zeile 126: | ||
Text = Text .. tostring(Tbl.y) .. VCHR | Text = Text .. tostring(Tbl.y) .. VCHR | ||
end | end | ||
+ | if SortIt then | ||
+ | if Tbl.m == 13 then Tbl.m = 1 end | ||
+ | if tonumber(Tbl.y) and tonumber(Tbl.m) and tonumber(Tbl.d) then | ||
+ | local Numstr = string.format('%5d%2.2d%2.2d',5000+Tbl.y,Tbl.m,Tbl.d) | ||
+ | local SortTag='<span style="display:none" class="sortkey">' .. Numstr .. '</span>' | ||
+ | Text = SortTag .. Text | ||
+ | end | ||
+ | end | ||
+ | |||
return Text | return Text | ||
end | end | ||
-- | -- | ||
− | |||
− | |||
− | |||
− | |||
+ | function p.Execute(frame) | ||
+ | local FR = frame:getParent() | ||
+ | return Run(FR.args) | ||
+ | end | ||
+ | |||
+ | -- function p.Go(frame) | ||
+ | -- return Run(frame.args) | ||
+ | -- end | ||
return p | return p |
Version vom 2. Juni 2013, 18:42 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 Datum = {}
local Teil=""
local pos = 0
Datum.y = 0
Datum.m = 0
Datum.d = 0
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
Datum.y = tonumber(str) or 'x'
return false, Datum -- Kein Wert erkennbar
end
Teil = mw.ustring.sub(str,1,pos-1)
Datum.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 true, Datum -- Nur Jahr
end
Teil = mw.ustring.sub(str,1,pos-1)
Datum.m = tonumber(Teil) or 0
Teil = mw.ustring.sub(str,pos+1, -1)
if #Teil == 0 then
return true, Datum -- Nur Jahr und Monat
end
if Datum.m == 0 then
Datum.d = 0
else
Datum.d = tonumber(Teil) or 0
end
return true, Datum
end
--
local function CheckDate(Date)
if ( Date.m == 4 or Date.m == 6 or Date.m == 9 or Date.m == 11) and Date.d > 30 then
return false;
end
if Date.m == 2 then -- Die greg. Sonderregeln werden ignoriert.
if Date.y % 4 ~= 0 and Date.d > 28 then return false; end
if Date.y % 4 == 0 and Date.d > 29 then return false; end
end
-- Hier nur noch 31-Tage-Monate übrig.
if Date.d > 31 then return false; end
return true;
end
--
local function Run(Args)
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 IsOk = true
local Tbl = {}
if mw.ustring.lower(Args[2] or "") == "nbsp" or mw.ustring.lower(Args[3] or "") == "nbsp" or mw.ustring.lower(Args[4] or "") == "nbsp" then NBSP = true; end
if mw.ustring.lower(Args[2] or "") == "link" or mw.ustring.lower(Args[3] or "") == "link" or mw.ustring.lower(Args[4] or "") == "link" then LINK = true; end
if mw.ustring.upper(Args[2] or "") == "M" or mw.ustring.upper(Args[3] or "") == "M" or mw.ustring.upper(Args[4] or "") == "M" then STIL = 'M'; end
if mw.ustring.upper(Args[2] or "") == "S" or mw.ustring.upper(Args[3] or "") == "S" or mw.ustring.upper(Args[4] or "") == "S" then STIL = 'S'; end
if mw.ustring.lower(Args['AT'] or "") == "ja" then AT = true; end
if mw.ustring.lower(Args['sort'] or "") ~= "" then SortIt = true; end
IsOk, Tbl = Split(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!'.. table.concat(Tbl,'.')..'</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
if SortIt then
if Tbl.m == 13 then Tbl.m = 1 end
if tonumber(Tbl.y) and tonumber(Tbl.m) and tonumber(Tbl.d) then
local Numstr = string.format('%5d%2.2d%2.2d',5000+Tbl.y,Tbl.m,Tbl.d)
local SortTag='<span style="display:none" class="sortkey">' .. Numstr .. '</span>'
Text = SortTag .. Text
end
end
return Text
end
--
function p.Execute(frame)
local FR = frame:getParent()
return Run(FR.args)
end
-- function p.Go(frame)
-- return Run(frame.args)
-- end
return p