Modul:Adresse: Unterschied zwischen den Versionen

fix formDate2CompareIndex()
(- Kategorie:Fehlerhafte Adresse)
(fix formDate2CompareIndex())
Zeile 67: Zeile 67:
-- subobject setzen
-- subobject setzen
mw.smw.subobject(attr, subobject)
mw.smw.subobject(attr, subobject)
 
-- Plausibilitätsprüfung von/bis
-- Plausibilitätsprüfung von/bis
if attr["AdresseVon"] ~= nil and attr["AdresseBis"] ~= nil and
if attr["AdresseVon"] ~= nil and attr["AdresseBis"] ~= nil and
  p.smwDate2CompareIndex(attr["AdresseVon"], "von") > p.smwDate2CompareIndex(attr["AdresseBis"], "bis") then
  p.formDate2CompareIndex(attr["AdresseVon"], "von") > p.formDate2CompareIndex(attr["AdresseBis"], "bis") then
  fail = true
  fail = true
end
end
Zeile 86: Zeile 86:
end
end


function p.smwDate2CompareIndex(date, vonbis)
function p.formDate2CompareIndex(date, vonbis)
-- mw.log("smwDate2CompareIndex(" .. date .. ")")
-- mw.log("formDate2CompareIndex(" .. date .. ")")
-- Datum in Index wandeln
-- Datum in Index wandeln
-- Bsp.: 23 April 1989 => 19890423
-- Bsp.: 23 April 1989 => 19890423
-- Konsolenzeile zum Debuggen:
-- Konsolenzeile zum Debuggen:
-- =p.smwDate2CompareIndex("2000","von")
-- =p.formDate2CompareIndex("2000","von")
-- =p.smwDate2CompareIndex("2000","bis")
-- =p.formDate2CompareIndex("2000","bis")
-- =p.smwDate2CompareIndex("Februar 2000","von")
-- =p.formDate2CompareIndex("Februar 2000","von")
-- =p.smwDate2CompareIndex("Februar 2000","bis")
-- =p.formDate2CompareIndex("Februar 2000","bis")
-- =p.smwDate2CompareIndex("3. Februar 2000","von")
-- =p.formDate2CompareIndex("2000/02/03","von")
-- =p.smwDate2CompareIndex("3. Februar 2000","bis")
-- =p.formDate2CompareIndex("2000/02/03","bis")
local index = ""
local index = ""
local date=str.split2(date, " ")
local date = str.split2(date, "/")
if #date == 1 then -- nur Jahr vorhanden
if #date == 3 then -- komplettes Datum vorhanden
index = tostring(date[1])
index = tostring(date[1]) .. tostring(date[2]) .. tostring(date[3])
if vonbis == "von" then
else
index = index .. "0101"
date = str.split2(date[1], " ")
else
if #date == 1 then -- nur Jahr vorhanden
index = index .. "1231"
index = tostring(date[1])
end
if vonbis == "von" then
elseif #date == 2 then -- nur Monat + Jahr vorhanden
index = index .. "0101"
index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]])
else
if vonbis == "von" then
index = index .. "1231"
index = index .. "01"
end
else
elseif #date == 2 then -- nur Monat + Jahr vorhanden
index = index .. "31"
index = tostring(date[2]) .. string.format("%02d", kal.month_numbers[date[1]])
if vonbis == "von" then
index = index .. "01"
else
index = index .. "31"
end
end
end
elseif #date == 3 then -- komplettes Datum vorhanden
index = tostring(date[3]) .. string.format("%02d",kal.month_numbers[date[2]]) .. string.format("%02d", tonumber(string.match(date[1], "%d*")))
end
end
index = tonumber(index) or 0
index = tonumber(index) or 0