Modul:LinkFormDatum: Unterschied zwischen den Versionen

Aus FürthWiki

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(19 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
Zeile 26: Zeile 26:
      
      
     date_array=split(date, "/")
     date_array=split(date, "/")
    mw.smw.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 "[[" .. date_array[0] .. "]]"
     return "[[" .. 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] .. " [[" .. mda[1] .. "]]"
     return 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 .. " [[" .. date_array[0] .. "]]"
     return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     else
     else
    -- Dateformat should be YYYY/MM/DD
     mn = months[tonumber(date_array[1])]
     mn = months[tonumber(date_array[1])]
     return "[[" .. date_array[2] .. " " .. mn .. "]]" .. " [[" .. date_array[0] .. "]]"
    date_array[2] = date_array[2]:gsub('0*', '', 1)
     return "[[" .. attr_day .. "::" .. date_array[2] .. ". " .. mn .. "]]" ..  
    " [[" .. attr_year .. "::" .. date_array[0] .. "]]"
     end
     end
    --l=string.len(date_array[0])
end
--t="[["..date_array[0].."]] " .. l .. " ".. tostring(date_array[1])--tostring(isInteger(date_array[0]))
 
return "t"
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
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