82.367
Bearbeitungen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 4: | Zeile 4: | ||
function p.LinkFormDate(frame) | function p.LinkFormDate(frame) | ||
args = frame.args | local args = frame.args | ||
local date = args[1] | |||
date = args[1] | local attr_date = args[2] | ||
attr_date = args[2] | local attr_day = args[3] | ||
attr_day = args[3] | local attr_year = args[4] | ||
attr_year = args[4] | return p.link_form_date(date, attr_date, attr_day, attr_year) | ||
return link_form_date(date, attr_date, attr_day, attr_year) | |||
end | end | ||
function link_form_date(date, attr_date, attr_day, attr_year) | function p.link_form_date(date, attr_date, attr_day, attr_year) | ||
months=getMonthList() | local months=getMonthList() | ||
local 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 25: | Zeile 24: | ||
else | else | ||
-- Dateformat is <monthname> YYYY | -- Dateformat is <monthname> YYYY | ||
mda = str.split(date_array[0]) | local mda = str.split(date_array[0]) | ||
return mda[0] .. " [[" .. attr_year .. "::" .. 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])] | local mn = months[tonumber(date_array[1])] | ||
return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]" | return mn .. " [[" .. attr_year .. "::" .. date_array[0] .. "]]" | ||
else | else | ||
| Zeile 42: | Zeile 41: | ||
function p.FormatDate(frame) | function p.FormatDate(frame) | ||
args = frame.args | local args = frame.args | ||
return p.format_date(args[1]) | |||
end | end | ||
function format_date(date) | function p.format_date(date) | ||
date_array=str.split(date, " ") | local 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 58: | Zeile 55: | ||
else | else | ||
-- When datestring contains day, monthname and year | -- When datestring contains day, monthname and year | ||
day=string.gsub(date_array[0], "%.", "") | local day=string.gsub(date_array[0], "%.", "") | ||
return "[[" .. day .. ". " .. date_array[1] .. "]] " .. | return "[[" .. day .. ". " .. date_array[1] .. "]] " .. | ||
"[[" .. date_array[2] .. "]]" | "[[" .. date_array[2] .. "]]" | ||
| Zeile 66: | Zeile 63: | ||
function p.HumanToFormDate(frame) | function p.HumanToFormDate(frame) | ||
-- Converts a human date (3. Februar 1955) to 1955/02/03, like SMW needs | -- Converts a human date (3. Februar 1955) to 1955/02/03, like SMW needs | ||
args = frame.args | local args = frame.args | ||
return p.human_to_form_date(args[1]) | |||
end | end | ||
function human_to_form_date(date) | function p.human_to_form_date(date) | ||
date_array=str.split(date, " ") | local 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 81: | Zeile 76: | ||
return date_array[0].." "..date_array[1] | return date_array[0].." "..date_array[1] | ||
else | else | ||
day = string.gsub(date_array[0], "%.", "") | local day = string.gsub(date_array[0], "%.", "") | ||
day = string.format("%02d", day) | day = string.format("%02d", day) | ||
mnr = getMonthnr(date_array[1]) | local mnr = getMonthnr(date_array[1]) | ||
mnr = string.format("%02d", mnr) | mnr = string.format("%02d", mnr) | ||
return date_array[2].."/"..mnr.."/"..day | return date_array[2].."/"..mnr.."/"..day | ||