Modul:LinkFormDatum: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
local p = {} | local p = {} | ||
local c = require( "Module:Common" ) | local c = require( "Module:Common" ) | ||
local str = require("Modul:String") | |||
function p.LinkFormDate(frame) | function p.LinkFormDate(frame) | ||
| Zeile 15: | Zeile 16: | ||
months=getMonthList() | months=getMonthList() | ||
date_array=split(date, "/") | date_array=str.split(date, "/") | ||
mw.smw.set({[attr_date] = date}) | mw.smw.set({[attr_date] = date}) | ||
if isEmpty(date_array[1]) then | if isEmpty(date_array[1]) then | ||
| Zeile 24: | Zeile 25: | ||
else | else | ||
-- Dateformat is <monthname> YYYY | -- Dateformat is <monthname> YYYY | ||
mda = split(date_array[0]) | mda = str.split(date_array[0]) | ||
return mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]" | return mda[0] .. " [[" .. attr_year .. "::" .. mda[1] .. "]]" | ||
end | end | ||
| Zeile 48: | Zeile 49: | ||
function format_date(date) | function format_date(date) | ||
date_array=split(date, " ") | date_array=str.split(date, " ") | ||
if isEmpty(date_array[1]) then | if isEmpty(date_array[1]) then | ||
-- When datestring contained no " ", thus is year | -- When datestring contained no " ", thus is year | ||
| Zeile 72: | Zeile 73: | ||
function human_to_form_date(date) | function human_to_form_date(date) | ||
date_array=split(date, " ") | date_array=str.split(date, " ") | ||
if isEmpty(date_array[1]) then | if isEmpty(date_array[1]) then | ||
-- When datestring contained no " ", thus is year | -- When datestring contained no " ", thus is year | ||
Version vom 24. August 2025, 08:24 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 (z. B. 20 Januar 2008) in die Übliche Darstellung (20. Januar 2008), so dass Jahr und Jahrestag klickbar sind und in die entsprechenden Artikel verlinken. Es funktioniert auch, wenn der Tag mit Punkt übergeben wird (also 20. Januar 2008).
HumanToFormDate
Bringt ein Menschenlesbares Datum wie "23. Februar 1985" in die semantische Form "1985/02/23". Die Konvertierung gelingt auch, wenn der Tag oder Tag und Monat fehlen. Das nun maschinenlesbare Format kann mit der Funktion LinkFormDate wieder semantisiert und in die Datenbank eingetragen werden (unter Nennung der Attribute, siehe dort).
Unterseiten
local p = {}
local c = require( "Module:Common" )
local str = require("Modul:String")
function p.LinkFormDate(frame)
args = frame.args
date = args[1]
attr_date = args[2]
attr_day = args[3]
attr_year = args[4]
return link_form_date(date, attr_date, attr_day, attr_year)
end
function link_form_date(date, attr_date, attr_day, attr_year)
months=getMonthList()
date_array=str.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 = str.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)
args = frame.args
date = args[1]
return format_date(date)
end
function format_date(date)
date_array=str.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
day=string.gsub(date_array[0], "%.", "")
return "[[" .. day .. ". " .. date_array[1] .. "]] " ..
"[[" .. date_array[2] .. "]]"
end
end
function p.HumanToFormDate(frame)
-- Converts a human date (3. Februar 1955) to 1955/02/03, like SMW needs
args = frame.args
date = args[1]
return human_to_form_date(date)
end
function human_to_form_date(date)
date_array=str.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
day = string.gsub(date_array[0], "%.", "")
day = string.format("%02d", day)
mnr = getMonthnr(date_array[1])
mnr = string.format("%02d", mnr)
return date_array[2].."/"..mnr.."/"..day
end
end
return p