Modul:Chronik: Unterschied zwischen den Versionen
Aus FürthWiki
Keine Bearbeitungszusammenfassung |
(Namenskonvention für Modul-Importe) |
||
| Zeile 1: | Zeile 1: | ||
local p = {} | local p = {} | ||
local str = require("Modul:String") | local str = require("Modul:String") | ||
local | local srf = require("Modul:Subrefs") | ||
local | local com = require("Modul:Common") | ||
local lfd = require("Modul:LinkFormDatum") | local lfd = require("Modul:LinkFormDatum") | ||
local lsd = require("Modul:LinkSubformDatum") | local lsd = require("Modul:LinkSubformDatum") | ||
| Zeile 13: | Zeile 13: | ||
local thema = frame.args["Thema"] or "Ereignis" | local thema = frame.args["Thema"] or "Ereignis" | ||
local year = nil | local year = nil | ||
if | if com.istJahreszahl(title) then | ||
year = title | year = title | ||
end | end | ||
local data = p.dateParser(daterange, year) | local data = p.dateParser(daterange, year) | ||
local ds = '' | local ds = '' | ||
if not | if not com.isEmpty(data['Starttag']) then | ||
ds = '[[' .. data['Starttag'] .. ']]' | ds = '[[' .. data['Starttag'] .. ']]' | ||
end | end | ||
| Zeile 37: | Zeile 37: | ||
local t | local t | ||
if option == "nodate" then | if option == "nodate" then | ||
t = | t = srf.subrefs(text) | ||
else | else | ||
t = ds .. ': ' .. | t = ds .. ': ' .. srf.subrefs(text) | ||
end | end | ||
return frame:preprocess(t) | return frame:preprocess(t) | ||
| Zeile 72: | Zeile 72: | ||
local sd = str.split(start_date, ' ') | local sd = str.split(start_date, ' ') | ||
if not | if not com.isEmpty(end_date) then | ||
-- Wenn ein Enddatum gegeben ist | -- Wenn ein Enddatum gegeben ist | ||
local ed = str.split(end_date, ' ') | local ed = str.split(end_date, ' ') | ||
mw.logObject(ed) | mw.logObject(ed) | ||
if | if com.len(ed) == 2 then | ||
-- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu | -- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu | ||
ed[3] = year | ed[3] = year | ||
end_date = end_date .. " " .. ed[3] | end_date = end_date .. " " .. ed[3] | ||
end | end | ||
if | if com.len(sd) == 2 then | ||
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum | -- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum | ||
start_date = start_date .. " " .. ed[3] | start_date = start_date .. " " .. ed[3] | ||
elseif | elseif com.len(sd) == 1 then | ||
-- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum | -- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum | ||
start_date = start_date .. " " .. ed[2] .. " " .. ed[3] | start_date = start_date .. " " .. ed[2] .. " " .. ed[3] | ||
| Zeile 93: | Zeile 93: | ||
return start_date, end_date | return start_date, end_date | ||
end | end | ||
if | if com.len(sd) == 2 then | ||
-- Wenn das Startdatum kein Jahr enthält, hole es aus year | -- Wenn das Startdatum kein Jahr enthält, hole es aus year | ||
sd[3] = year | sd[3] = year | ||
start_date = start_date .. " " .. sd[3] | start_date = start_date .. " " .. sd[3] | ||
elseif | elseif com.len(sd) == 1 then | ||
sd[3] = year | sd[3] = year | ||
start_date = start_date .. " " .. sd[3] | start_date = start_date .. " " .. sd[3] | ||
| Zeile 109: | Zeile 109: | ||
local dates = str.split(s, "-") | local dates = str.split(s, "-") | ||
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis" | -- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis" | ||
if | if com.len(dates) == 1 then | ||
dates = str.split(s, "bis") | dates = str.split(s, "bis") | ||
end | end | ||
Version vom 26. Oktober 2025, 14:46 Uhr
local p = {}
local str = require("Modul:String")
local srf = require("Modul:Subrefs")
local com = require("Modul:Common")
local lfd = require("Modul:LinkFormDatum")
local lsd = require("Modul:LinkSubformDatum")
function p.Eintrag(frame)
local title = mw.title.getCurrentTitle().text
local daterange = frame.args[1]
local text = frame.args[2] or ""
local option = frame.args[3]
local thema = frame.args["Thema"] or "Ereignis"
local year = nil
if com.istJahreszahl(title) then
year = title
end
local data = p.dateParser(daterange, year)
local ds = ''
if not com.isEmpty(data['Starttag']) then
ds = '[[' .. data['Starttag'] .. ']]'
end
if not year then
ds = ds .. ' [[' .. data['Startjahr'] .. ']]'
end
if data['Enddatum'] then
ds = ds .. " - [[" .. data['Endtag'] .. "]]"
if not year then
ds = ds .. " [[" .. data['Endjahr'] .. "]]"
end
end
data['Beschreibung'] = text
data['Option'] = option
data['Thema'] = thema
mw.smw.subobject(data)
local t
if option == "nodate" then
t = srf.subrefs(text)
else
t = ds .. ': ' .. srf.subrefs(text)
end
return frame:preprocess(t)
end
function p.dateParser(s, year)
local start_date, end_date = p.splitDateString(s, year)
start_date, end_date = p.completeDates(start_date, end_date, year)
local sdf = lfd.humanToFormDate(start_date)
local data = {
['Startdatum'] = sdf,
['Startjahr'] = lsd.getYear(sdf),
['Starttag'] = lsd.getMonthday(sdf)
}
if end_date then
local edf = lfd.humanToFormDate(end_date)
data['Enddatum'] = edf
data['Endjahr'] = lsd.getYear(edf)
data['Endtag'] = lsd.getMonthday(edf)
end
mw.logObject(data)
return data
end
function p.completeDates(start_date, end_date, year)
--[[Jetzt müssen die gesplitteten Datum vervollständigt werden. Kann ja
sein, daß etwas wie 6. - 10. Januar angegeben ist. Und das Jahr, wenn nicht
gegeben, muß auch aus dem year entnommen werden können.]]
--start_date = str.strip(start_date)
--end_date = str.strip(end_date)
local sd = str.split(start_date, ' ')
if not com.isEmpty(end_date) then
-- Wenn ein Enddatum gegeben ist
local ed = str.split(end_date, ' ')
mw.logObject(ed)
if com.len(ed) == 2 then
-- Wenn das Enddatum kein Jahr enthält, füge es aus year hinzu
ed[3] = year
end_date = end_date .. " " .. ed[3]
end
if com.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
start_date = start_date .. " " .. ed[3]
elseif com.len(sd) == 1 then
-- Startdatum enthält weder Monat noch Jahr, hole sie von Enddatum
start_date = start_date .. " " .. ed[2] .. " " .. ed[3]
end
else
-- Wenn nur ein Startdatum gegeben ist
if year == nil then
return start_date, end_date
end
if com.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es aus year
sd[3] = year
start_date = start_date .. " " .. sd[3]
elseif com.len(sd) == 1 then
sd[3] = year
start_date = start_date .. " " .. sd[3]
end
end
return start_date, end_date
end
function p.splitDateString(s)
-- Teilt ein von/bis Datum in Start- und End-Datum auf.
local dates = str.split(s, "-")
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis"
if com.len(dates) == 1 then
dates = str.split(s, "bis")
end
-- Alle Leerzeichen links und rechts in den Ergebnissen entfernen
for i, v in ipairs(dates) do
dates[i] = str.strip(dates[i])
end
return dates[1], dates[2]
end
return p