|
|
| (19 mellomliggende versjoner av 4 brukere er ikke vist) |
| Linje 1: |
Linje 1: |
| local p = {} | | local p = {} |
| local lang = mw.getContentLanguage() | | local lang = mw.getContentLanguage() |
| -- HtmlError = require('Modul:Error')
| | |
|
| | function p.formatIsoDate(date) |
| function p.isodato(frame) | | if date:match("^%d%d%p%s%a%a%a%p%s%d%d%d%d$") then |
| local dato = mw.text.trim(frame.args[1])
| | if string.sub(date,-9,-7) == "okt" then |
| if dato:match("^%d%d%d%d%-%d%d%-%d%d$") or dato:match("^%d%d%d%d%-%d%d%-%d$") or dato:match("^%d%d%d%d%-%d%-%d%d$") or dato:match("^%d%d%d%d%-%d%-%d$") then | | return string.sub(date,-13,-12) .. ". oktober " .. string.sub(date,-4,-1) |
| if dato:match("^%d%d%d%d%-%d%d%-%d%d$") then | | elseif string.sub(date,-9,-7) == "des" then |
| local month_number = string.sub(dato, 6, 7)
| | return string.sub(date,-13,-12) .. ". desember " .. string.sub(date,-4,-1) |
| local day_number = string.sub(dato, 9, 10) | | else |
| if tonumber(month_number) > 12 then
| | local daymonth = lang:formatDate('j. F', date) |
| result = dato .. "<sup><small>'''Feil datoformat''': månedstallet er høyere enn 12</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| | local year = lang:formatDate('Y', date) |
| elseif tonumber(day_number) > 31 then
| | assert(tonumber(year), date) |
| result = dato .. "<sup><small>'''Feil datoformat''': dagstallet er høyere enn 31</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| | return daymonth .. " " .. year |
| else
| | end |
| local day = lang:formatDate('j. F', dato)
| | elseif date:match("^%d%p%s%a%a%a%p%s%d%d%d%d$") then |
| local year = lang:formatDate('Y', dato)
| | if string.sub(date,-9,-7) == "okt" then |
| assert(tonumber(year), frame.args[1])
| | return string.sub(date,-12,-12) .. ". oktober " .. string.sub(date,-4,-1) |
| local args = mw.text.trim(frame.args[2])
| | elseif string.sub(date,-9,-7) == "des" then |
| if args == 'n' then
| | return string.sub(date,-12,-12) .. ". desember " .. string.sub(date,-4,-1) |
| result = day.. " "..year
| |
| else
| |
| result = "[["..day.."]] [["..year.."]]"
| |
| end
| |
| end
| |
| elseif dato:match("^%d%d%d%d%-%d%d%-%d$") then
| |
| local month_number = string.sub(dato, 6, 7)
| |
| if tonumber(month_number) > 12 then
| |
| result = dato .. '<sup><small>Feil datoformat: månedstallet er høyere enn 12</small></sup>[[Kategori:Sider som inneholder feil datoformat]]'
| |
| else
| |
| local day = lang:formatDate('j. F', dato) | |
| local year = lang:formatDate('Y', dato) | |
| assert(tonumber(year), frame.args[1]) | |
| local args = mw.text.trim(frame.args[2]) | |
| if args == 'n' then
| |
| result = day.. " "..year
| |
| else
| |
| result = "[["..day.."]] [["..year.."]]"
| |
| end
| |
| end
| |
| elseif dato:match("^%d%d%d%d%-%d%-%d%d$") then
| |
| local day_number = string.sub(dato, 8, 9)
| |
| if tonumber(day_number) > 31 then | |
| result = dato .. "<sup><small>'''Feil datoformat''': dagstallet er høyere enn 31</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| |
| else
| |
| local day = lang:formatDate('j. F', dato)
| |
| local year = lang:formatDate('Y', dato)
| |
| assert(tonumber(year), frame.args[1])
| |
| local args = mw.text.trim(frame.args[2])
| |
| if args == 'n' then
| |
| result = day.. " "..year
| |
| else
| |
| result = "[["..day.."]] [["..year.."]]"
| |
| end
| |
| end
| |
| else | | else |
| local day = lang:formatDate('j. F', dato) | | local daymonth = lang:formatDate('j. F', date) |
| local year = lang:formatDate('Y', dato) | | local year = lang:formatDate('Y', date) |
| assert(tonumber(year), frame.args[1]) | | assert(tonumber(year), date) |
| local args = mw.text.trim(frame.args[2]) | | return daymonth .. " " .. year |
| if args == 'n' then
| |
| result = day.. " "..year
| |
| else
| |
| result = "[["..day.."]] [["..year.."]]"
| |
| end
| |
| end | | end |
| elseif dato:match("^%d%d%s%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%d%s%a%a%a%a%a%a%a%a%a%s%d%d%d%d$") then | | elseif date:match("^%d%d%d%d%-%d%d%-%d%d$") or date:match("^%d%d%d%d%-%d%d%-%d$") or date:match("^%d%d%d%d%-%d%-%d%d$") |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| | or date:match("^%d%d%p%s%oktp%s%d%d%d%d$") or date:match("^%d%d%p%s\d\e\sp%s%d%d%d%d$") |
| elseif dato:match("^%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%d%s%d%d%d%d$") then | | or date:match("^%d%d%d%d%-%d%-%d$") then |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| | local daymonth = lang:formatDate('j. F', date) |
| elseif dato:match("^%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%d%a%a%p%s%d%d%d%d$") then | | local year = lang:formatDate('Y', date) |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]" | | assert(tonumber(year), date) |
| elseif dato:match("^%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%d%a%a%s%d%d%d%d$") then
| | return daymonth .. " " .. year |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]" | |
| elseif dato:match("^%d%s%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%a%a%a%a%s%d%d%d%d$") or dato:match("^%d%s%a%a%a%a%a%a%a%a%a%s%d%d%d%d$") then
| |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| |
| elseif dato:match("^%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%s%d%d%d%d$") then
| |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| |
| elseif dato:match("^%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%a%a%p%s%d%d%d%d$") then
| |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| |
| elseif dato:match("^%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%s%d%a%a%s%d%d%d%d$") or dato:match("^%a%a%a%a%a%a%a%a%a%s%d%a%a%s%d%d%d%d$") then
| |
| result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
| |
| else
| |
| result = dato
| |
| end | | end |
|
| | return date |
| return result | | end |
| | |
| | function p.isodato(frame) |
| | local date = mw.text.trim(frame.args[1]) |
| | return p.formatIsoDate(date) |
| end | | end |
| | | |
| return p | | return p |
 | Denne modulen brukes på over 137 000 sider.
Det anbefales at endringer testes i en sandkasse før de legges inn. Diskuter gjerne også endringer på diskusjonssiden først. |
Denne modulen bruker #time-funksjonen til å omdanne datoer til formen DD. MMMM ÅÅÅÅ (for eksempel 21. februar 1981) som er standard på no.wiki.
Den første, og eneste, parameteren er datoen man ønsker å omsette til norsk wikistandard.
Se mal:ISOtilNorskdato som er frontend for modulen.
local p = {}
local lang = mw.getContentLanguage()
function p.formatIsoDate(date)
if date:match("^%d%d%p%s%a%a%a%p%s%d%d%d%d$") then
if string.sub(date,-9,-7) == "okt" then
return string.sub(date,-13,-12) .. ". oktober " .. string.sub(date,-4,-1)
elseif string.sub(date,-9,-7) == "des" then
return string.sub(date,-13,-12) .. ". desember " .. string.sub(date,-4,-1)
else
local daymonth = lang:formatDate('j. F', date)
local year = lang:formatDate('Y', date)
assert(tonumber(year), date)
return daymonth .. " " .. year
end
elseif date:match("^%d%p%s%a%a%a%p%s%d%d%d%d$") then
if string.sub(date,-9,-7) == "okt" then
return string.sub(date,-12,-12) .. ". oktober " .. string.sub(date,-4,-1)
elseif string.sub(date,-9,-7) == "des" then
return string.sub(date,-12,-12) .. ". desember " .. string.sub(date,-4,-1)
else
local daymonth = lang:formatDate('j. F', date)
local year = lang:formatDate('Y', date)
assert(tonumber(year), date)
return daymonth .. " " .. year
end
elseif date:match("^%d%d%d%d%-%d%d%-%d%d$") or date:match("^%d%d%d%d%-%d%d%-%d$") or date:match("^%d%d%d%d%-%d%-%d%d$")
or date:match("^%d%d%p%s%oktp%s%d%d%d%d$") or date:match("^%d%d%p%s\d\e\sp%s%d%d%d%d$")
or date:match("^%d%d%d%d%-%d%-%d$") then
local daymonth = lang:formatDate('j. F', date)
local year = lang:formatDate('Y', date)
assert(tonumber(year), date)
return daymonth .. " " .. year
end
return date
end
function p.isodato(frame)
local date = mw.text.trim(frame.args[1])
return p.formatIsoDate(date)
end
return p