Modul:FormatDateTest
Die Dokumentation für dieses Modul kann unter Modul:FormatDateTest/Doku erstellt werden
Die Dokumentation für dieses Modul kann unter Modul:FormatDateTest/Doku erstellt werden
local p = {}
-- ACHTUNG! Das Modul dient der Erprobung und ist nicht für den dauerhaften Einsatz vorgesehen!
-- 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 -- Bereits am Stringende
Datum.y = tonumber(str);
if Datum.y then
return true, Datum -- Nur eine Jahreszahl
else
return false, Datum -- Kein Wert erkennbar
end
end
Teil = mw.ustring.sub(str,1,pos-1);
Datum.y = tonumber(Teil) or 0;
str = mw.ustring.sub(str,pos+1, -1);
pos = mw.ustring.find(str,'-',1,true);
if not pos or pos == 0 then
Datum.m = tonumber(str) or 0
Datum.d = 0;
return true, Datum;
end
Teil = mw.ustring.sub(str,1,pos-1)
Datum.m = tonumber(Teil) or 0
Teil = mw.ustring.sub(str,pos+1, -1)
Datum.d = tonumber(Teil) or 0;
return true, Datum;
end
--
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
--
local function Run(Args)
local T_L = {"Januar","Februar", "März", "April", "Mai","Juni", "Juli", "August","September","Oktober","November","Dezember","Jänner"}
local T_M = {"Jan.","Feb.", "März", "Apr.", "Mai","Juni", "Juli", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
local T_S = {"Jan.","Feb.", "Mrz.", "Apr.", "Mai","Jun.", "Jul.", "Aug.","Sep.","Okt.","Nov.","Dez.","Jän."}
local Text = "";
local TextYear = "";
local TextMonth = "";
local TextDay = "";
local idxm = 0 ; -- Wegen der AT-Regel ein Extraindex fuer den Monat.
local AT = false;
local NBSP = false;
local LINK = false;
local VCHR = "";
local STIL = 'L';
local IsOk = true;
local Tbl = {}
local SortIt = false;
local Zero = false;
local Numstr = "";
local SortTag= "";
local Arg2 = mw.ustring.lower(mw.text.trim(Args[2] or ""));
local Arg3 = mw.ustring.lower(mw.text.trim(Args[3] or ""));
local Arg4 = mw.ustring.lower(mw.text.trim(Args[4] or ""));
local davor = mw.text.trim(Args['davor'] or "");
if Arg2 == "nbsp" or Arg3 == "nbsp" or Arg4 == "nbsp" then NBSP = true; end
if Arg2 == "link" or Arg3 == "link" or Arg4 == "link" then LINK = true; end
if Arg2 == "l" or Arg3 == "l" or Arg4 == "l" then STIL = 'L'; end
if Arg2 == "m" or Arg3 == "m" or Arg4 == "m" then STIL = 'M'; end
if Arg2 == "s" or Arg3 == "s" or Arg4 == "s" then STIL = 'S'; end
if mw.ustring.lower(mw.text.trim(Args['AT'] or "")) == "ja" then AT = true; end
if mw.ustring.lower(mw.text.trim(Args['Zero'] or "")) ~= "" then Zero = true; end
if mw.ustring.lower(mw.text.trim(Args['Sort'] or "")) ~= "" then SortIt = true; Zero = true; end
if davor ~="" then davor = davor .. " "; end
IsOk, Tbl = Split(Args[1])
if not IsOk then
Text = '<span class="error">[[Vorlage:FormatDate]]: Kein gültiges ISO-Datum!</span>'
return Text
end
--Tage ohne Monat: Tage in Monat und Tag umrechnen
if Tbl.m == 0 and Tbl.d ~= 0 then
IsOk, Tbl = TageInMonate(Tbl)
end
if not IsOk then
Text = '<span class="error">[[Vorlage:FormatDate]]: Kein gültiges ISO-Datum!</span>'
return Text
end
Tbl.y = tonumber(Tbl.y) or 0;
if Tbl.y == 0 and Tbl.m == 0 and Tbl.d == 0 then
Text = '<span class="error">[[Vorlage:FormatDate]]: Ungültiger Wert ("0-0-0") für das Datum! </span>'
return Text
end
if Tbl.y < 0 then -- Jahr Null reserviert fuer "Nur Tag und Monat"
Tbl.y = 0 - Tbl.y
VCHR = ' v. Chr.';
end
IsOk = CheckDate(Tbl);
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) .. '. '
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 = ' ' .. TextYear;
else
TextYear = ' ' .. TextYear;
end
end
end
Text = Text .. TextYear;
if SortIt then
if VCHR ~= "" then
Tbl.y = 0 - 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 .. davor .. Text;
end
return Text
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
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.