Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Änderungen

Zur Navigation springen Zur Suche springen
K
53 Versionen importiert: Import aus der deutschen Wikipedia, Vorlage:Lang
Zeile 1: Zeile 1: −
local p = {}  
+
local p = {}
        -- Trennen der Parameter
+
-- Trennen der Parameter
        local function Split(str)
+
local function Split(str)
            local Datum = {}
+
local Datum = {}
            local Teil=""
+
local Teil=""
            local pos = 0
+
local pos = 0
            Datum.y = 0
+
Datum.y = 0
            Datum.m = 0
+
Datum.m = 0
            Datum.d = 0
+
Datum.d = 0
            pos = mw.ustring.find(str,'-',1,true);
+
pos = mw.ustring.find(str,'-',1,true);
            if pos == 1 then -- Minuszeichen am Anfang - nochmal suchen
+
if pos == 1 then -- Minuszeichen am Anfang - nochmal suchen
                pos = mw.ustring.find(str,'-',2,true);
+
pos = mw.ustring.find(str,'-',2,true);
            end
+
end
            if not pos then
+
if not pos then -- Bereits am Stringende
                Datum.y = tonumber(str) or 'x'
+
Datum.y = tonumber(str);
                return false, Datum  -- Kein Wert erkennbar
+
if Datum.y then
            end
+
if math.floor(Datum.y) ~= Datum.y then
            Teil  = mw.ustring.sub(str,1,pos-1)
+
return false, Datum -- Eine Dezimalzahl ist Unsinn
            Datum.y = tonumber(Teil) or 'x'
+
end
            str = mw.ustring.sub(str,pos+1,  -1)
+
return true, Datum -- Nur eine Jahreszahl
            pos = mw.ustring.find(str,'-',1,true);
+
else
            if not pos or pos == 0 then
+
return false, Datum  -- Kein Wert erkennbar
                return true, Datum  -- Nur Jahr
+
end
            end
+
end
            Teil  = mw.ustring.sub(str,1,pos-1)
+
Teil  = mw.ustring.sub(str,1,pos-1);
            Datum.m = tonumber(Teil) or 0
+
Datum.y = tonumber(Teil) or 0;
            Teil  = mw.ustring.sub(str,pos+1,  -1)
+
            if #Teil == 0 then
+
str = mw.ustring.sub(str,pos+1,  -1);
                return true, Datum  -- Nur Jahr und Monat
+
pos = mw.ustring.find(str,'-',1,true);
            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 not pos or pos == 0 then
            if ( Date.m == 4 or Date.m == 6  or Date.m == 9  or Date.m == 11) and Date.d > 30 then
+
Datum.m = tonumber(str) or 0
                return false;
+
Datum.d = 0;
            end
+
if math.floor(Datum.m) ~= Datum.m then
            if Date.m == 2 then -- Die greg. Sonderregeln werden ignoriert.
+
return false, Datum -- Eine Dezimalzahl ist Unsinn
                if Date.y % 4 ~= 0 and Date.d > 28 then return false; end
+
end
                if Date.y % 4 == 0 and Date.d > 29 then return false; end
+
return true, Datum;
            end
+
end
            -- Hier nur noch 31-Tage-Monate übrig.
  −
            if Date.d > 31  then return false; end
  −
            return true;
  −
        end
  −
        --
     −
        local function Run(Args)
+
Teil = mw.ustring.sub(str,1,pos-1)
            local T_F = {"Januar","Februar", "März", "April", "Mai","Juni", "Juli", "August","September","Oktober","November","Dezember","Jänner"}
+
Datum.m = tonumber(Teil) or 0
            local T_M  = {"Jan.","Feb.", "Mrz", "Apr.", "Mai","Jun.", "Jul.", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
+
Teil = mw.ustring.sub(str,pos+1,  -1)
            local T_S  = {"Jan.","Feb.", "März", "Apr.", "Mai","Juni", "Juli", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
+
Datum.d = tonumber(Teil) or 0;
            local Text = "";
+
if math.floor(Datum.m) ~= Datum.m then
            local  AT = false;
+
return false, Datum -- Eine Dezimalzahl ist Unsinn
            local NBSP = false;
+
end
            local LINK = false;
+
if math.floor(Datum.d) ~= Datum.d then
            local VCHR = "";
+
return false, Datum -- Eine Dezimalzahl ist Unsinn
            local STIL = 'F';
+
end
            local IsOk = true
+
return true, Datum;
            local Tbl = {}
+
end
            local SortIt = false;
+
--
            local Numstr = "";
  −
            local SortTag= "";
  −
            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])
+
local function CheckDate(Date)
 +
-- Monatspruefung
 +
if Date.m ==  0 then -- keine Pruefung
 +
return true;
 +
end
 +
if Date.m > 12 or Date.m < 1 then
 +
return false;
 +
end
 +
if Date.d ==  0 then -- nur Monat angegeben, keine Tagespruefung
 +
return true;
 +
end
 +
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 TageInMonate(Datum)
 +
Datum.m = 1;
 +
if Datum.d > 31 then -- nach Januar
 +
Datum.m = 2;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.y % 4 == 0 then -- Die greg. Sonderregeln werden ignoriert.
 +
if Datum.d > 29 then  -- nach Februar (Schaltjahr)
 +
Datum.m = 3;
 +
Datum.d = Datum.d - 29;
 +
else
 +
return true, Datum;
 +
end
 +
else
 +
if Datum.d > 28 then  -- nach Februar (Normaljahr)
 +
Datum.m = 3;
 +
Datum.d = Datum.d - 28;
 +
else
 +
return true, Datum;
 +
end
 +
end
 +
if Datum.d > 31 then -- nach Maerz
 +
Datum.m = 4;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 30 then -- nach April
 +
Datum.m = 5;
 +
Datum.d = Datum.d - 30;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 31 then -- nach Mai
 +
Datum.m = 6;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 30 then -- nach Juni
 +
Datum.m = 7;
 +
Datum.d = Datum.d - 30;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 31 then -- nach Juli
 +
Datum.m = 8;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 31 then -- nach August
 +
Datum.m = 9;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 30 then -- nach September
 +
Datum.m = 10;
 +
Datum.d = Datum.d - 30;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 31 then -- nach Oktober
 +
Datum.m = 11;
 +
Datum.d = Datum.d - 31;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 30 then -- nach November
 +
Datum.m = 12;
 +
Datum.d = Datum.d - 30;
 +
else
 +
return true, Datum;
 +
end
 +
if Datum.d > 31 then -- nach Dezember = Fehler
 +
Datum.m = 0;
 +
Datum.d = 0;
 +
return false, Datum;
 +
else
 +
return true, Datum;
 +
end
 +
end
 +
--
   −
            if Tbl.y == 'x' then
+
local function Run(Args)
                Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Jahr!</span>'
+
local T_L  = {"Januar","Februar", "März", "April", "Mai","Juni", "Juli", "August","September","Oktober","November","Dezember","Jänner"}
                return Text
+
local T_M  = {"Jan.","Feb.", "März", "Apr.", "Mai","Juni", "Juli", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
            end
+
local T_S  = {"Jan.","Feb.",  "Mrz.", "Apr.", "Mai","Jun.", "Jul.", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
            if Tbl.m > 12 or Tbl.m < 0 then
+
local Text = "";
                Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert für Monat!</span>'
+
local TextYear  = "";
                return Text
+
local TextMonth = "";
            end
+
local TextDay  = "";
            if Tbl.y <= 0 then
+
local idxm = 0 ;  --  Wegen der AT-Regel ein Extraindex fuer den Monat.
                Tbl.y = 1 - Tbl.y
+
local  AT = false;
                VCHR = " v. Chr.";
+
local NBSP = false;
            end
+
local LINK = false;
            if Tbl.d > 0 then
+
local VCHR = "";
                if CheckDate(Tbl) then
+
local STIL = 'L';
                    Text = tostring(Tbl.d) .. '.&nbsp;'
+
local IsOk = true;
                else
+
local Tbl = {}
                    Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiges Datum!'.. table.concat(Tbl,'.')..'</span>'
+
local SortIt = false;
                    return Text
+
local Zero = false;
                end
+
local Numstr = "";
            end
+
local SortTag= "";
            if Tbl.m > 0 then
+
local Arg2 = mw.ustring.lower(mw.text.trim(Args[2] or ""));
                if LINK then
+
local Arg3 = mw.ustring.lower(mw.text.trim(Args[3] or ""));
                    if Tbl.d == 0 then
+
local Arg4 = mw.ustring.lower(mw.text.trim(Args[4] or ""));
                        Linkziel =T_F[Tbl.m]
+
local davor = mw.text.trim(Args['davor'] or "");
                    else
+
local display = mw.text.trim(Args['display'] or ""); -- Nur zusammen mit sort sinnvoll
                        Linkziel = tostring(Tbl.d) .. ". " .. T_F[Tbl.m]
+
if Arg2 == "nbsp"  or Arg3 == "nbsp"  or Arg4 == "nbsp" then NBSP = true; end
                    end
+
if Arg2 == "link"  or Arg3 == "link"  or Arg4 == "link" then LINK = true; end
                end
+
if Arg2 == "l"    or Arg3 == "l"    or Arg4 == "l"   then STIL = 'L'; end
                if AT and Tbl.m == 1 then
+
if Arg2 == "m"    or Arg3 == "m"    or Arg4 == "m"    then STIL = 'M'; end
                    Tbl.m = 13
+
if Arg2 == "s"    or Arg3 == "s"    or Arg4 == "s"    then STIL = 'S'; end
                end
+
if mw.ustring.lower(mw.text.trim(Args['AT'] or "")) == "ja" then AT = true; end
                if STIL == 'M' then
+
if mw.ustring.lower(mw.text.trim(Args['Zero'] or "")) ~= "" then Zero = true; end
                    Text = Text .. T_M[Tbl.m]
+
if mw.ustring.lower(mw.text.trim(Args['Sort'] or "")) ~= "" then SortIt = true; Zero = true; end
                elseif STIL == 'S' then
+
if davor ~="" then davor = davor .. "&nbsp;"; end
                    Text = Text .. T_S[Tbl.m]
+
IsOk, Tbl = Split(Args[1])
                else
+
if not  IsOk then
                    Text = Text .. T_F[Tbl.m]
+
Text = '<span class="error">[[Vorlage:FormatDate]]: Kein gültiges ISO-Datum!</span>'
                end
+
return Text
                if LINK then
+
end
                    Text = "[[" .. Linkziel .. "|" .. Text .. "]]"
+
--Tage ohne Monat: Tage in Monat und Tag umrechnen
                end
+
if Tbl.m == 0 and Tbl.d ~= 0  then
                if NBSP then
+
IsOk, Tbl = TageInMonate(Tbl)
                    Text = Text .. "&nbsp;"
+
end
                else
+
if not IsOk then
                    Text = Text .. " "
+
Text = '<span class="error">[[Vorlage:FormatDate]]: Kein gültiges ISO-Datum!</span>'
                end
+
return Text
            end
+
end
            if LINK then
+
Tbl.y = tonumber(Tbl.y) or 0;
                Text = Text .. "[[" .. tostring(Tbl.y) .. VCHR .. "]]"
+
if Tbl.y == 0 and Tbl.m == 0 and Tbl.d == 0 then
            else
+
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert ("0-0-0") für das Datum! </span>'
                Text = Text .. tostring(Tbl.y) .. VCHR
+
return Text
            end
+
end
            if SortIt then
+
if Tbl.y  < 0 then -- Jahr Null reserviert fuer "Nur Tag und Monat"
                if Tbl.m == 13 then Tbl.m = 1 end
+
Tbl.y = 0 - Tbl.y
                if tonumber(Tbl.y) and  tonumber(Tbl.m) and tonumber(Tbl.d) then
+
VCHR = ' v. Chr.';
                    if VCHR ~= "" then
+
end
                        Tbl.y = 1 - Tbl.y
  −
                    end
  −
                    Numstr = string.format('%d%2.2d%2.2d',5000+Tbl.y,Tbl.m,Tbl.d)
  −
                    SortTag='<span style="display:none" class="sortkey">' .. Numstr .. '</span>'
  −
                    Text = SortTag .. Text
  −
                end
  −
            end
     −
            return Text
+
IsOk = CheckDate(Tbl);
        end
+
if not IsOk then
        --
+
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiges Datum!'.. table.concat(Tbl,'.')..'</span>'
 +
return Text
 +
end
 +
 
 +
if Tbl.d > 0 then -- Tag angegeben, String erstellen
 +
TextDay =  tostring(Tbl.d) .. '.&nbsp;'
 +
if Tbl.d < 10 and Zero then
 +
TextDay = '<span style="visibility:hidden;">0</span>' .. TextDay;
 +
end
 +
else
 +
TextDay = '';
 +
end
 +
 
 +
if Tbl.m > 0 then -- Monat angegeben, String erstellen
 +
if AT and Tbl.m == 1 then
 +
idxm = 13
 +
else
 +
idxm =  Tbl.m;
 +
end
 +
 
 +
if STIL == 'S' then
 +
TextMonth = T_S[idxm] ;
 +
elseif STIL == 'M' then
 +
TextMonth = T_M[idxm] ;
 +
else
 +
TextMonth = T_L[idxm] ;
 +
end
 +
 
 +
Text = TextDay .. TextMonth
 +
if LINK then
 +
if Tbl.d == 0 then
 +
Linkziel =T_L[Tbl.m]
 +
else
 +
Linkziel = tostring(Tbl.d) .. ". " .. T_L[Tbl.m]
 +
end
 +
Text = '[[' .. Linkziel .. '|' .. Text .. ']]';
 +
end
 +
end
 +
-- hier Tag und Monat zusammen, evtl. verlinkt
 +
 
 +
if Tbl.y ~= 0 then
 +
if LINK then
 +
TextYear = '[[' .. tostring(Tbl.y) .. VCHR .. ']]';
 +
else
 +
TextYear = tostring(Tbl.y) .. VCHR;
 +
end
 +
if Tbl.m > 0 then
 +
if NBSP then
 +
TextYear = '&nbsp;' .. TextYear;
 +
else
 +
TextYear = ' ' .. TextYear;
 +
end
 +
end
 +
end
 +
Text = Text .. TextYear;
 +
 
 +
if SortIt then
 +
if VCHR ~= "" then
 +
Tbl.y = 0 - Tbl.y
 +
end
 +
-- Begrenzung auf 3000 v Chr. bis 6999 n. Chr. Vierstellige Sortierung reicht aus
 +
if Tbl.y > 6999 then
 +
Tbl.y = 6999;
 +
end
 +
-- Nur bei Sortierung sinnvoll: Überschreiben der Textausgabe mit angegebenen String
 +
if display ~= "" then
 +
Text = display;
 +
end
 +
Numstr = string.format('%d%2.2d%2.2d',3000+Tbl.y,Tbl.m,Tbl.d);
 +
SortTag='<span style="display:none" class="sortkey">' .. Numstr .. '♠</span>';
 +
Text = SortTag .. davor .. Text;
 +
end
 +
return Text
 +
end
 +
--
 +
 
 +
local function GetYear(Args)
 +
local Tbl = {}
 +
local IsOk = true;
 +
local Year = 0;
 +
IsOk, Tbl = Split(Args[1])
 +
if not IsOk or Tbl.y  == 0 then
 +
Year = 0;
 +
return Year;
 +
end
 +
return Tbl.y;
 +
end
 +
 +
local function CountDays(Args)
 +
local Tbl = {}
 +
local IsOk = true;
 +
local Days = 0;
 +
IsOk, Tbl = Split(Args[1])
 +
if not IsOk or Tbl.y  == 0 then
 +
Days = 0;
 +
return Days;
 +
end
 +
if Tbl.m == 0 or  Tbl.m == 1 then
 +
Days = Tbl.d;
 +
return Days;
 +
end
 +
if Tbl.m == 2 then
 +
Days = 31 + Tbl.d;
 +
return Days;
 +
end
 +
if Tbl.y % 4 == 0 then
 +
Days = 60
 +
else
 +
Days = 59;
 +
end
 +
if Tbl.m ==  3 then Days = Days + Tbl.d; end
 +
if Tbl.m ==  4 then Days = Days +  31 + Tbl.d; end
 +
if Tbl.m ==  5 then Days = Days +  61 + Tbl.d; end
 +
if Tbl.m ==  6 then Days = Days +  92 + Tbl.d; end
 +
if Tbl.m ==  7 then Days = Days + 122 + Tbl.d; end
 +
if Tbl.m ==  8 then Days = Days + 153 + Tbl.d; end
 +
if Tbl.m ==  9 then Days = Days + 184 + Tbl.d; end
 +
if Tbl.m == 10 then Days = Days + 214 + Tbl.d; end
 +
if Tbl.m == 11 then Days = Days + 245 + Tbl.d; end
 +
if Tbl.m == 12 then Days = Days + 275 + Tbl.d; end
 +
return Days;
 +
end
 +
 
 +
 
 +
function p.Execute(frame)
 +
local FR = frame:getParent()
 +
if frame:callParserFunction('int', 'lang' ) == 'de-at' then
 +
FR.args['AT']='ja';
 +
end
 +
return Run(FR.args)
 +
end
 +
 
 +
function p.Sort(frame)
 +
local FR = frame:getParent()
 +
FR.args.Sort='1'
 +
return Run(FR.args)
 +
end
 +
 
 +
function p.DayInYear(frame)
 +
local FR = frame:getParent()
 +
local Number = CountDays(FR.args);
 +
return tostring(Number);
 +
end
 +
 
 +
function p.YearFromISO(frame)
 +
local FR = frame:getParent()
 +
local Number = GetYear(FR.args);
 +
return tostring(Number);
 +
end
   −
        function p.Execute(frame)
  −
            local FR = frame:getParent()
  −
            return  Run(FR.args)
  −
        end
     −
        function p.Sort(frame)
  −
            local FR = frame:getParent()
  −
            FR.args.Sort='1'
  −
            return  Run(FR.args)
  −
        end
   
return p
 
return p
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü