26.714
Bearbeitungen
(- getMonthList() obsolete, -getMonthnr() obsolete, +/fix dateLastDayCompleter() von Modul:SMW) |
(+ dateFirstDayCompleter(), date2ISO()) |
||
| Zeile 61: | Zeile 61: | ||
month = p.month_numbers[month] | month = p.month_numbers[month] | ||
local year = string.sub(date, string.find(date, " ") + 1) | local year = string.sub(date, string.find(date, " ") + 1) | ||
last_date = year .. "/" .. month .. "/" | last_date = year .. "/" .. string.format("%02d", month) .. "/" | ||
if month == 2 and year % 4 == 0 then -- Sonderfall Feb. Schaltjahr | if month == 2 and year % 4 == 0 then -- Sonderfall Feb. Schaltjahr | ||
last_date = last_date .. "29" | last_date = last_date .. "29" | ||
| Zeile 73: | Zeile 73: | ||
end | end | ||
function p.date2ISO( | function p.dateFirstDayCompleter(date) | ||
-- ergänzt ersten Tag | |||
-- 2000 => 2000/01/01 | |||
-- Februar 2000 => 2000/2/01 | |||
-- 2020/04/02 => 2020/04/02 | |||
local first_date | |||
if #date == 4 then -- nur "Jahr" vorhanden | |||
first_date = date .. "/01/01" | |||
elseif string.find(date, " ") ~= nil then -- "Monat Jahr" vorhanden (hat Leerzeichen) | |||
local month = string.sub(date, 1, string.find(date, " ") - 1) | |||
month = p.month_numbers[month] | |||
local year = string.sub(date, string.find(date, " ") + 1) | |||
first_date = year .. "/" .. string.format("%02d", month) .. "/01" | |||
else | |||
first_date = date | |||
end | |||
return first_date | |||
end | |||
function p.date2ISO(date) | |||
-- 2000 => 2000-01-01 | |||
-- Februar 2000 => 2000-02-01 | |||
-- 2020/04/02 => 2020-04-02 | |||
local date_iso = "" | |||
date = p.dateFirstDayCompleter(date) | |||
for i = 1, #date do | |||
local char = string.sub(date, i, i) | |||
if char == "/" then | |||
date_iso = date_iso .. "-" | |||
else | |||
date_iso = date_iso .. char | |||
end | |||
end | |||
return date_iso | |||
end | end | ||
return p | return p | ||