Zum Inhalt springen

Modul:Vorlage:FormatDate: Unterschied zwischen den Versionen

K
keine Bearbeitungszusammenfassung
K (1 Version)
dewiki>Antonsusi
KKeine Bearbeitungszusammenfassung
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 = {}
Zeile 24: Zeile 24:
str = mw.ustring.sub(str,pos+1,  -1);
str = mw.ustring.sub(str,pos+1,  -1);
pos = mw.ustring.find(str,'-',1,true);
pos = mw.ustring.find(str,'-',1,true);
if not pos or pos == 0 then
if not pos or pos == 0 then
return true, Datum; -- Nur Jahr
Datum.m = tonumber(str) or 0
Datum.d = 0;
return true, Datum;
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.m = tonumber(Teil) or 0
Teil  = mw.ustring.sub(str,pos+1,  -1)
Teil  = mw.ustring.sub(str,pos+1,  -1)
if #Teil == 0 then
Datum.d = tonumber(Teil) or 0;
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;
return true, Datum;
end
end
Zeile 63: Zeile 61:
if Date.d > 31  then return false; end
if Date.d > 31  then return false; end
return true;
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
end
--
--
Zeile 80: Zeile 164:
local VCHR = "";
local VCHR = "";
local STIL = 'L';
local STIL = 'L';
local IsOk = true
local IsOk = true;
local Tbl = {}
local Tbl = {}
local SortIt = false;
local SortIt = false;
Zeile 104: Zeile 188:
return Text
return Text
end
end
--Tag ohne Monat nicht erlaubt: Auch Tag auf Null setzen (= nur Jahr)
--Tage ohne Monat: Tage in Monat und Tag umrechnen
if Tbl.m == 0 then
if Tbl.m == 0 and Tbl.d ~= 0  then
Tbl.d = 0;
IsOk, Tbl = TageInMonate(Tbl)
end
if not  IsOk then
Text = '<span class="error">[[Vorlage:FormatDate]]: Kein gültiges ISO-Datum!</span>'
return Text
end
end
Tbl.y = tonumber(Tbl.y) or 0;
Tbl.y = tonumber(Tbl.y) or 0;
Zeile 187: Zeile 275:
end
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)
function p.Execute(frame)
Zeile 198: Zeile 334:
return Run(FR.args)
return Run(FR.args)
end
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
return p
return p
Anonymer Benutzer
Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.