26.722
Bearbeitungen
(- getMonthList() obsolete, -getMonthnr() obsolete, +/fix dateLastDayCompleter() von Modul:SMW) |
(fix local p = {}) |
||
| (3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
p = {} | local p = {} | ||
p.month_names = { "Januar", "Februar", "März", "April", "Mai", "Juni", | p.month_names = { "Januar", "Februar", "März", "April", "Mai", "Juni", | ||
| Zeile 45: | Zeile 45: | ||
-- Prüfe auf Formate wie: 2024, -44, 44 v. Chr., 800 n. Chr. | -- Prüfe auf Formate wie: 2024, -44, 44 v. Chr., 800 n. Chr. | ||
return s:match("^%-?%d+$") or s:match("^%d+%s+[vn]%.%s+Chr%.$") | return s:match("^%-?%d+$") or s:match("^%d+%s+[vn]%.%s+Chr%.$") | ||
end | |||
function p.DateLastDayCompleter(frame) | |||
-- mw.log("DateLastDayCompleter(frame)") | |||
-- mw.logObject(frame, "frame") | |||
local date = frame.args[1] or "" | |||
local last_date = p.dateLastDayCompleter(date) | |||
-- mw.logObject(last_date, "last_date") | |||
return last_date | |||
end | end | ||
| Zeile 61: | Zeile 70: | ||
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 82: | ||
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 | |||
-- Februar 2000 => 2000-02 | |||
-- 2020/04/02 => 2020-04-02 | |||
local date_iso = "" | |||
if #date == 4 then -- nur "Jahr" vorhanden | |||
date_iso = date | |||
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] | |||
date_iso = string.sub(date, string.find(date, " ") + 1) | |||
if month ~= nil then | |||
date_iso = date_iso .. "-" .. string.format("%02d", month) | |||
end | |||
else | |||
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 | |||
end | |||
return date_iso | |||
end | end | ||
return p | return p | ||