Modul:LinkFormDatum: Unterschied zwischen den Versionen

Aus FürthWiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 26: Zeile 26:
      
      
     date_array=split(date, "/")
     date_array=split(date, "/")
    t = "{{#set:" .. attr_date .. "=" .. date .. "}}"
     if isEmpty(date_array[1]) then
     if isEmpty(date_array[1]) then
     -- When datestring contained no "/"
     -- When datestring contained no "/"
     if isInteger(date_array[0]) then
     if isInteger(date_array[0]) then
     -- When dateformat is just YYYY
     -- When dateformat is just YYYY
     return "[[" .. attr_year .. "::" .. date_array[0] .. "]]"
     return t .. "[[" .. attr_year .. "::" .. date_array[0] .. "]]"
     else
     else
     -- Dateformat is <monthname> YYYY
     -- Dateformat is <monthname> YYYY
     mda = split(date_array[0])
     mda = split(date_array[0])
     return mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]"
     return t .. mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]"
     end
     end
     elseif isEmpty(date_array[2]) then
     elseif isEmpty(date_array[2]) then
     -- Datestring contained one "/"
     -- Datestring contained one "/"
     mn = months[tonumber(date_array[1])]
     mn = months[tonumber(date_array[1])]
     return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     return t .. mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     else
     else
     -- Dateformat should be YYYY/MM/DD
     -- Dateformat should be YYYY/MM/DD
     mn = months[tonumber(date_array[1])]
     mn = months[tonumber(date_array[1])]
     date_array[2] = string.gsub(date_array[2], '0*', '', 1)
     date_array[2] = string.gsub(date_array[2], '0*', '', 1)
     return "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" ..  
     return t .. "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" ..  
     " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     end
     end
     return "t"
     return t
end
end


return p
return p

Version vom 9. September 2024, 15:26 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.ParseFormDate( 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, "/")
    t = "{{#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 t .. "[[" .. attr_year .. "::" .. date_array[0] .. "]]"
    	else
    		-- Dateformat is <monthname> YYYY
    		mda = split(date_array[0])
    		return t .. mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]"
    	end
    elseif isEmpty(date_array[2]) then
    	-- Datestring contained one "/"
    	mn = months[tonumber(date_array[1])]
    	return t .. mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
    else
    	-- Dateformat should be YYYY/MM/DD
    	mn = months[tonumber(date_array[1])]
    	date_array[2] = string.gsub(date_array[2], '0*', '', 1)
    	return t .. "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" .. 
    		" [[" .. attr_year .. "::" .. date_array[0] .. "]]"
    end
    return t
end

return p