Modul:LinkFormDatum: Unterschied zwischen den Versionen

Aus FürthWiki

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(43 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:
local c = require( "Module:Common" )
local c = require( "Module:Common" )


function p.ParseFormDate( frame )
function p.LinkFormDate( frame )
pf = frame:getParent()
pf = frame:getParent()
args = pf.args
args = pf.args
months={
[1] = "Januar",
[2] = "Februar",
[3] = "März",
[4] = "April",
[5] = "Mai",
[6] = "Juni",
[7] = "Juli",
[8] = "August",
[9] = "September",
[10] = "Oktober",
[11] = "November",
[12] = "Dezember"}
date = args[1]
date = args[1]
Zeile 11: Zeile 25:
attr_year = args[4]
attr_year = args[4]
      
      
     t=c.AttributeTable(args)
     date_array=split(date, "/")
     t=t.."<br>"
    mw.smw.set({[attr_date] = date})
     t=t.."[["..date.."]]"
     if isEmpty(date_array[1]) then
      
    -- When datestring contained no "/"
    n=0
    if isInteger(date_array[0]) then
     for i in string.gmatch(date, "[^/]+") do
    -- When dateformat is just YYYY
n=n+1
    return "[[" .. attr_year .. "::" .. date_array[0] .. "]]"
date_array[n]=i
    else
t=t..date_array[n].."xx"
    -- Dateformat is <monthname> YYYY
    mda = split(date_array[0])
    return mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]"
    end
     elseif isEmpty(date_array[2]) then
    -- Datestring contained one "/"
    mn = months[tonumber(date_array[1])]
    return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     else
    -- Dateformat should be YYYY/MM/DD
    mn = months[tonumber(date_array[1])]
    date_array[2] = date_array[2]:gsub('0*', '', 1)
    return "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" ..
    " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     end
end
 
function p.FormatDate( frame )
pf = frame:getParent()
args = pf.args
date = args[1]
date_array=split(date, " ")
if isEmpty(date_array[1]) then
    -- When datestring contained no " ", thus is year
    return "[[" .. date_array[0] .. "]]"
elseif isEmpty(date_array[2]) then
-- When datestring contains monthname and year
return date_array[0] .. " [[" .. date_array[1] .. "]]"
else
-- When datestring contains day, monthname and year
return "[[" .. date_array[0] .. ". " .. date_array[1] .. "]] " ..
"[[" .. date_array[2] .. "]]"
end
end
return t
end
end


return p
return p

Aktuelle Version vom 16. September 2024, 13:53 Uhr

LinkFormDate

Funktion, welche die Datumsfelder der Formulare zur Visualisierung in den Faktenboxen abbildet. Hierbei werden die Datumsangaben gleichzeitig semantisiert.

Die von der Vorlage übergebenen Parameter lauten:

  • 1 = Datum, z. B. das Geburtsdatum in beliebigem Format
  • 2 = Name des Hauptattributs, z. B. "Geburtsdatum"
  • 3 = Name des Tagesattributes, z. B. "Geburtstag"
  • 4 = Name des Jahresattributes, z. B. "Geburtsjahr"

FormatDate

Bringt ein semantisches Datum in die Übliche Darstellung, so dass Jahr und Monatstag klickbar sind.


local p = {}
local c = require( "Module:Common" )

function p.LinkFormDate( frame )
	pf = frame:getParent()
	args = pf.args
	
	months={
		[1] = "Januar",
		[2] = "Februar",
		[3] = "März",
		[4] = "April",
		[5] = "Mai",
		[6] = "Juni",
		[7] = "Juli",
		[8] = "August",
		[9] = "September",
		[10] = "Oktober",
		[11] = "November",
		[12] = "Dezember"}
	
	date = args[1]
	attr_date = args[2]
	attr_day = args[3]
	attr_year = args[4]
    
    date_array=split(date, "/")
    mw.smw.set({[attr_date] = date})
    if isEmpty(date_array[1]) then
    	-- When datestring contained no "/"
    	if isInteger(date_array[0]) then
    		-- When dateformat is just YYYY
    		return "[[" .. attr_year .. "::" .. date_array[0] .. "]]"
    	else
    		-- Dateformat is <monthname> YYYY
    		mda = split(date_array[0])
    		return mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]"
    	end
    elseif isEmpty(date_array[2]) then
    	-- Datestring contained one "/"
    	mn = months[tonumber(date_array[1])]
    	return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
    else
    	-- Dateformat should be YYYY/MM/DD
    	mn = months[tonumber(date_array[1])]
    	date_array[2] = date_array[2]:gsub('0*', '', 1)
    	return "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" .. 
    		" [[" .. attr_year .. "::" .. date_array[0] .. "]]"
    end
end

function p.FormatDate( frame )
	pf = frame:getParent()
	args = pf.args
	
	date = args[1]
	date_array=split(date, " ")
	if isEmpty(date_array[1]) then
    	-- When datestring contained no " ", thus is year
    	return "[[" .. date_array[0] .. "]]"
	elseif isEmpty(date_array[2]) then
		-- When datestring contains monthname and year
		return date_array[0] .. " [[" .. date_array[1] .. "]]"
	else
		-- When datestring contains day, monthname and year
		return "[[" .. date_array[0] .. ". " .. date_array[1] .. "]] " .. 
			"[[" .. date_array[2] .. "]]"
	end
end

return p