Modul:ISOtilNorskdato: Forskjell mellom sideversjoner

Fra wikisida.no
Hopp til navigering Hopp til søk
rv
prøver igjen
Linje 1: Linje 1:
local p = {}
local p = {}
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
-- HtmlError = require('Modul:Error')
   
   
function p.isodato(frame)
function p.isodato(frame)
local dato = mw.text.trim(frame.args[1])
local dato = mw.text.trim(frame.args[1])
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
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
if dato:match("^%d%d%d%d%-%d%d%-%d%d$") then
local day = lang:formatDate('j. F', dato)
local month_number = string.sub(dato, 6, 7)
local year = lang:formatDate('Y', dato)
local day_number = string.sub(dato, 9, 10)
assert(tonumber(year), frame.args[1])
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]]"
elseif 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
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
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])
local args = mw.text.trim(frame.args[2])
if args == 'n' then
if args == 'n' then
Linje 64: Linje 14:
result = "[["..day.."]] [["..year.."]]"
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
result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
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
result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
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
result = dato .. "<sup><small>'''Feil datoformat'''</small></sup>[[Kategori:Sider som inneholder feil datoformat]]"
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
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
else
result = dato
result = dato
end
end
return result
return result
end
end
 
return p
return p

Sideversjonen fra 14. aug. 2014 kl. 19:29

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.isodato(frame)
	local dato = mw.text.trim(frame.args[1])
	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
		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
	else
		result = dato
	end
	return result
end

return p