Modul:Chronik/Work: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(16 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:
local str = require("Modul:String")
local str = require("Modul:String")
local c = require("Modul:Common")
local c = 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 c.istJahreszahl(title) then
year = title
end
local data = p.dateParser(daterange, year)
local ds = '[[' .. data['Starttag'] .. ']]'
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['Thema'] = thema
mw.smw.subobject(data)
if option == "nodate" then
return text
end
return ds .. ': ' .. text
end


function p.dateParser(s, year)
function p.dateParser(s, year)
local start_date, end_date = p.splitDateString(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  
--[[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
sein, daß etwas wie 6. - 10. Januar angegeben ist. Und das Jahr, wenn nicht
Zeile 11: Zeile 61:
local sd = str.split(start_date, ' ')
local sd = str.split(start_date, ' ')
if end_date then
if end_date then
-- Wenn ein Enddatum gegeben ist
local ed = str.split(end_date, ' ')
local ed = str.split(end_date, ' ')
-- Wenn das End-Datum kein Jahr enthält, füge es aus year hinzu
if c.len(ed) == 2 then
if c.len(ed) == 2 then
-- 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 c.len(sd) == 2 then
if c.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
start_date = start_date .. " " .. ed[3]
start_date = start_date .. " " .. ed[3]
elseif c.len(sd) == 1 then
elseif c.len(sd) == 1 then
-- 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]
end
end
else
else
-- Wenn nur ein Startdatum gegeben ist
if c.len(sd) == 2 then
if c.len(sd) == 2 then
-- 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]
82.367

Bearbeitungen