15.075
Bearbeitungen
K (Entfernte den Schutz von „Modul:LinkFormDatum“) |
(linkFormDate() zusätzlich ISO-P case YYYY-MM-DD) |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 11: | Zeile 11: | ||
function p.linkFormDate(date, attr_date, attr_day, attr_year) | function p.linkFormDate(date, attr_date, attr_day, attr_year) | ||
local months = c.getMonthList() | local months = c.getMonthList() | ||
local date_array | local date_array | ||
local mda | local mda | ||
local mn -- monthname | local mn -- monthname | ||
if string.find(date, "/") ~= nil then -- regular case YYYY/MM/DD | |||
date_array = str.split(date, "/") | |||
else -- ISO-P case YYYY-MM-DD | |||
date_array = str.split(date, "-") | |||
end | |||
mw.smw.set({[attr_date] = date}) | -- wenn keine Attribute übergeben, werden keine gesetzt, sondern nur Links eingebaut | ||
if attr_day ~= nil then | |||
attr_day = attr_day .. "::" | |||
else | |||
attr_day = "" | |||
end | |||
if attr_year ~= nil then | |||
attr_year = attr_year .. "::" | |||
else | |||
attr_year = "" | |||
end | |||
if attr_date ~= nil then | |||
mw.smw.set({[attr_date] = date}) | |||
end | |||
if c.isEmpty(date_array[2]) then | if c.isEmpty(date_array[2]) then | ||
-- When datestring contained no "/" | -- When datestring contained no "/" | ||
if c.isInteger(date_array[1]) then | if c.isInteger(date_array[1]) then | ||
-- When dateformat is just YYYY | -- When dateformat is just YYYY | ||
return "[[" .. attr_year | return "[[" .. attr_year .. date_array[1] .. "]]" | ||
else | else | ||
-- Dateformat is <monthname> YYYY | -- Dateformat is <monthname> YYYY | ||
mda = str.split(date_array[1]) | mda = str.split(date_array[1]) | ||
return mda[1] .. " [[" .. attr_year | return mda[1] .. " [[" .. attr_year .. mda[2] .. "]]" | ||
end | end | ||
elseif c.isEmpty(date_array[3]) then | elseif c.isEmpty(date_array[3]) then | ||
-- Datestring contained one "/" | -- Datestring contained one "/" | ||
mn = months[tonumber(date_array[2])] | mn = months[tonumber(date_array[2])] | ||
return mn .. " [[" .. attr_year | return mn .. " [[" .. attr_year .. date_array[1] .. "]]" | ||
else | else | ||
-- Dateformat should be YYYY/MM/DD | -- Dateformat should be YYYY/MM/DD or YYYY-MM-DD | ||
mn = months[tonumber(date_array[2])] | mn = months[tonumber(date_array[2])] | ||
date_array[3] = date_array[3]:gsub('0*', '', 1) | date_array[3] = date_array[3]:gsub('0*', '', 1) | ||
return "[[" .. attr_day | return "[[" .. attr_day .. date_array[3] .. ". " .. mn .. "]]" .. | ||
" [[" .. attr_year | " [[" .. attr_year .. date_array[1] .. "]]" | ||
end | end | ||
end | end | ||