15.081
Bearbeitungen
Keine Bearbeitungszusammenfassung |
(linkFormDate() zusätzlich ISO-P case YYYY-MM-DD) |
||
| (10 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 4: | Zeile 4: | ||
function p.LinkFormDate(frame) | function p.LinkFormDate(frame) | ||
-- #invoke wrapper | |||
local args = frame.args | local args = frame.args | ||
return p.linkFormDate(args[1], args[2], args[3], args[4]) | |||
end | end | ||
function p. | function p.linkFormDate(date, attr_date, attr_day, attr_year) | ||
local months=c.getMonthList() | local months = c.getMonthList() | ||
local date_array=str.split(date, "/") | local date_array | ||
local mda | |||
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]) | |||
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])] | |||
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])] | |||
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 | ||
function p.FormatDate(frame) | function p.FormatDate(frame) | ||
-- #invoke wrapper | |||
return p. | return p.formatDate(frame.args[1]) | ||
end | end | ||
function p. | function p.formatDate(date) | ||
local date_array = str.split(date, " ") | local date_array = str.split(date, " ") | ||
local day | |||
if c.isEmpty(date_array[2]) then | if c.isEmpty(date_array[2]) then | ||
-- When datestring contained no " ", thus is year | -- When datestring contained no " ", thus is year | ||
| Zeile 55: | Zeile 75: | ||
else | else | ||
-- When datestring contains day, monthname and year | -- When datestring contains day, monthname and year | ||
day = string.gsub(date_array[1], "%.", "") | |||
return "[[" .. day .. ". " .. date_array[2] .. "]] " .. | return "[[" .. day .. ". " .. date_array[2] .. "]] " .. | ||
"[[" .. date_array[3] .. "]]" | "[[" .. date_array[3] .. "]]" | ||
| Zeile 62: | Zeile 82: | ||
function p.HumanToFormDate(frame) | function p.HumanToFormDate(frame) | ||
-- | -- #invoke wrapper | ||
return p.humanToFormDate(frame.args[1]) | |||
return p. | |||
end | end | ||
function p. | function p.humanToFormDate(date) | ||
mw.log("p.humanToFormDate(date)") | |||
mw.logObject(date) | |||
-- Converts a human date (3. Februar 1955) to 1955/02/03, like SMW needs | |||
local date_array=str.split(date, " ") | local date_array=str.split(date, " ") | ||
local day | |||
local mnr -- monthnr | |||
if c.isEmpty(date_array[2]) then | if c.isEmpty(date_array[2]) then | ||
-- When datestring contained no " ", thus is year | -- When datestring contained no " ", thus is year | ||
| Zeile 74: | Zeile 99: | ||
elseif c.isEmpty(date_array[3]) then | elseif c.isEmpty(date_array[3]) then | ||
-- When datestring contains monthname and year | -- When datestring contains monthname and year | ||
return date_array[1].." "..date_array[ | return date_array[1].." "..date_array[2] | ||
else | else | ||
day = string.gsub(date_array[1], "%.", "") | |||
day = string.format("%02d", day) | day = string.format("%02d", day) | ||
mnr = c.getMonthnr(date_array[2]) | |||
mnr = string.format("%02d", mnr) | mnr = string.format("%02d", mnr) | ||
return date_array[ | return date_array[3] .. "/" .. mnr .. "/" .. day | ||
end | end | ||
end | end | ||
return p | return p | ||