Modul:Chronik: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Markierung: Zurückgesetzt
Zeile 1: Zeile 1:
local p = {}
local p = {}
local str = require("Modul:String")
local c = require("Modul:Common")
local c = require("Modul:Common")
local str = require("Modul:String")
local lfd = require("Modul:LinkFormDatum")
local lfd = require("Modul:LinkFormDatum")
local lsd = require("Modul:LinkSubformDatum")
local lsd = require("Modul:LinkSubformDatum")


function p.Eintrag(frame)
function p.Eintrag(frame)
local args = frame.args
local title = mw.title.getCurrentTitle().text
local title = mw.title.getCurrentTitle()
local daterange = frame.args[1]
local titlename = title.text
local text = frame.args[2] or ""
local fulltitle = title.fullText
local option = frame.args[3]
local year
local thema = frame.args["Thema"] or "Ereignis"
local data = {
local year = nil
["Beschreibung"] = args[2],
if c.istJahreszahl(title) then
["Thema"] = "Ereignis",
year = title
["Artikel"] = fulltitle
end
}
local data = p.dateParser(daterange, year)
-- Wenn das Lemma eine Jahreszahl ist, merken
local ds = '[[' .. data['Starttag'] .. ']]'
if c.istJahreszahl(titlename) then
if not year then
year = titlename
ds = ds .. ' [[' .. data['Startjahr'] .. ']]'
    end
end
    local data_date = p.dateParsing(args[1], year)
if data['Enddatum'] then
    local all_data = c.merge_tables(data, data_date)
ds = ds .. " - [[" .. data['Endtag'] .. "]]"
return data_date["Startdatum"] .. ": " .. args[2] --.. '<br>' ..
if not year then
--tableToString(all_data)
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
end


function p.dateParsing(s, year)
function p.dateParser(s, year)
-- Parses a date down where s is the datestring and year can be nil or string
local start_date, end_date = p.splitDateString(s, year)
start_date, end_date = p.completeDates(start_date, end_date, year)
-- Wenn s eine Zeitspanne ist, teile bei "-" oder "bis"
local sdf = lfd.humanToFormDate(start_date)
local dates = str.split(s, 'bis') -- split hatte in Modul:Commons einen bug(!)
if c.len(dates) == 1 then
dates=str.split(s, 'bis')
end
-- Ist eine Zeitspanne wie "3. bis 5. Mai" angegeben, kopiere Monat aus Enddatum
local sds = p.checkYear(dates[1], year)
local sd = lfd.humanToFormDate(dates[1])
local data = {
local data = {
-- Erstmal das Startdatum schreiben
['Startdatum'] = sdf,
["SDstring"] = dates[1],
['Startjahr'] = lsd.getYear(sdf),
["Startdatum"] = sd,
['Starttag'] = lsd.getMonthday(sdf)
["Startjahr"] = lsd.getYear(sd),
["Starttag"] = lsd.getMonthday(sd),
["length"] = c.len(dates),
["year"] = year,
}
}
if end_date then
local ed
local edf = lfd.humanToFormDate(end_date)
if c.len(dates) >= 2 then
data['Enddatum'] = edf
-- War eine Zeitspanne angegeben gibt es ein Endatum
data['Endjahr'] = lsd.getYear(edf)
ed=lfd.humanToFormDate(dates[2])
data['Endtag'] = lsd.getMonthday(edf)
data["EDstring"] = dates[2]
data["Enddatum"] = ed
data["Endjahr"] = lsd.getYear(ed)
data["Endtag"] = lsd.getMonthday(ed)
end
if c.len(dates) >= 3 then
data["3 is"] = dates[3]
end
end
mw.logObject(data)
return data
return data
end
end


function p.checkYear(s, year)
function p.completeDates(start_date, end_date, year)
-- Wenn s nicht auf eine Jahreszahl endet, dann füge diese hinzu
--[[Jetzt müssen die gesplitteten Datum vervollständigt werden. Kann ja
    return s
sein, daß etwas wie 6. - 10. Januar angegeben ist. Und das Jahr, wenn nicht
gegeben, muß auch aus dem year entnommen werden können.]]
local sd = str.split(start_date, ' ')
if end_date then
-- Wenn ein Enddatum gegeben ist
local ed = str.split(end_date, ' ')
if c.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 c.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es von Enddatum
start_date = start_date .. " " .. ed[3]
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]
end
else
-- Wenn nur ein Startdatum gegeben ist
if c.len(sd) == 2 then
-- Wenn das Startdatum kein Jahr enthält, hole es aus year
sd[3] = year
start_date = start_date .. " " .. sd[3]
end
end
return start_date, end_date
end
end


function p.checkMonth(s, month)
function p.splitDateString(s)
-- Aua
-- Teilt ein von/bis Datum in Start- und End-Datum auf.
return s
local dates = str.split(s, "-")
-- Wenn splitten mit "-" nur ein Ergebnis bringt, splitte mit "bis"
if c.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
end


return p
return p
82.367

Bearbeitungen