Modul:ISOtilNorskdato: Forskjell mellom sideversjoner
Hopp til navigering
Hopp til søk
rv |
nå da |
||
| Linje 5: | Linje 5: | ||
if date:match("^%d%d%p%s%a%a%a%p%s%d%d%d%d$") then | 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 | if string.sub(date,-9,-7) == "okt" then | ||
result = string.sub(date,-13,-12) .. ". oktober " .. string.sub(date,-4,-1) | |||
elseif string.sub(date,-9,-7) == "des" then | elseif string.sub(date,-9,-7) == "des" then | ||
result = string.sub(date,-13,-12) .. ". desember " .. string.sub(date,-4,-1) | |||
else | else | ||
local daymonth = lang:formatDate('j. F', date) | local daymonth = lang:formatDate('j. F', date) | ||
local year = lang:formatDate('Y', date) | local year = lang:formatDate('Y', date) | ||
assert(tonumber(year), date) | assert(tonumber(year), date) | ||
result = daymonth .. " " .. year | |||
end | end | ||
elseif date:match("^%d%p%s%a%a%a%p%s%d%d%d%d$") then | elseif date:match("^%d%p%s%a%a%a%p%s%d%d%d%d$") then | ||
if string.sub(date,-9,-7) == "okt" then | if string.sub(date,-9,-7) == "okt" then | ||
result = string.sub(date,-12,-12) .. ". oktober " .. string.sub(date,-4,-1) | |||
elseif string.sub(date,-9,-7) == "des" then | elseif string.sub(date,-9,-7) == "des" then | ||
result = string.sub(date,-12,-12) .. ". desember " .. string.sub(date,-4,-1) | |||
else | else | ||
local daymonth = lang:formatDate('j. F', date) | local daymonth = lang:formatDate('j. F', date) | ||
local year = lang:formatDate('Y', date) | local year = lang:formatDate('Y', date) | ||
assert(tonumber(year), date) | assert(tonumber(year), date) | ||
result = daymonth .. " " .. year | |||
end | end | ||
elseif date:match("^%d%d%d%d%-%d%d%-%d%d | elseif date:match("^%d%d%d%d$") or date:match("^%d%d%d%d–%d%d%d%d") then | ||
or date:match("^%d%d%p%s%oktp%s%d%d%d%d | result = date | ||
or date:match("^%d%d%d%d%-%d%-%d | 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 daymonth = lang:formatDate('j. F', date) | ||
local year = lang:formatDate('Y', date) | local year = lang:formatDate('Y', date) | ||
assert(tonumber(year), date) | assert(tonumber(year), date) | ||
result = daymonth .. " " .. year | |||
elseif date:match("^%d%d%d%d-%d%d") or date:match("^%d%d%d%d-%d") then | |||
local month = lang:formatDate('F', date) | |||
local year = lang:formatDate('Y', date) | |||
assert(tonumber(year), date) | |||
result = month .. " " .. year | |||
end | |||
if result == nil then | |||
return date | |||
else | |||
return result | |||
end | end | ||
end | end | ||
Sideversjonen fra 26. okt. 2015 kl. 13:09
| 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.
- Modul:ISOtilNorskdato • Modul:ISOtilNorskdato/sandkasse • forskjellig (diff)
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
result = string.sub(date,-13,-12) .. ". oktober " .. string.sub(date,-4,-1)
elseif string.sub(date,-9,-7) == "des" then
result = 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)
result = 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
result = string.sub(date,-12,-12) .. ". oktober " .. string.sub(date,-4,-1)
elseif string.sub(date,-9,-7) == "des" then
result = 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)
result = daymonth .. " " .. year
end
elseif date:match("^%d%d%d%d$") or date:match("^%d%d%d%d–%d%d%d%d") then
result = date
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)
result = daymonth .. " " .. year
elseif date:match("^%d%d%d%d-%d%d") or date:match("^%d%d%d%d-%d") then
local month = lang:formatDate('F', date)
local year = lang:formatDate('Y', date)
assert(tonumber(year), date)
result = month .. " " .. year
end
if result == nil then
return date
else
return result
end
end
function p.isodato(frame)
local date = mw.text.trim(frame.args[1])
return p.formatIsoDate(date)
end
return p