Modul:Zeit: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
(Paar Standards kopiert als Basis)
 
K (59 Versionen von wikivoyage:Modul:Zeit importiert)
 
(58 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local check = require('Modul:Check2')
local params = mw.loadData('Modul:Zeit/Params')
local lang = mw.language.new ( 'de' );


function p._error( error_str )
local zeit = {}
local frame = mw.getCurrentFrame()
 
local localArgs = frame.args
function zeit.inhalt_monat ( frame )
local templateArgs = frame:getParent().args
funcParams = params['inhalt_monat']
args = frame:getParent().args
local januar = args['jan'] or args['januar'] or args['std'] or args['standard'] or funcParams['jan']
local februar = args['feb'] or args['februar'] or args['std'] or args['standard'] or funcParams['feb']
local maerz = args['mar'] or args['maerz'] or args['std'] or args['standard'] or funcParams['mar']
local april = args['apr'] or args['april'] or args['std'] or args['standard'] or funcParams['apr']
local mai = args['mai'] or args['std'] or args['standard'] or funcParams['mai']
local juni = args['jun'] or args['juni'] or args['std'] or args['standard'] or funcParams['jun']
local juli = args['jul'] or args['juli'] or args['std'] or args['standard'] or funcParams['jul']
local august = args['aug'] or args['august'] or args['std'] or args['standard'] or funcParams['aug']
local september = args['sep'] or args['september'] or args['std'] or args['standard'] or funcParams['sep']
local oktober = args['okt'] or args['oktober'] or args['std'] or args['standard'] or funcParams['okt']
local november = args['nov'] or args['november'] or args['std'] or args['standard'] or funcParams['nov']
local dezember = args['dez'] or args['dezember'] or args['std'] or args['standard'] or funcParams['dez']
local ausgabe = funcParams['st']
local monat = lang:formatDate ( 'm' )
-- Allgemeine Parameter auswerten
if monat == '01' then ausgabe = januar end
if templateArgs['ignore_errors'] == nil
if monat == '02' then ausgabe = februar end
then  
if monat == '03' then ausgabe = maerz end
if localArgs['ignore_errors'] == nil then templateArgs['ignore_errors'] = '0' else templateArgs['ignore_errors'] = localArgs['ignore_errors'] end
if monat == '04' then ausgabe = april end
end
if monat == '05' then ausgabe = mai end
if templateArgs['ignore_errors'] == '1' or templateArgs['ignore_errors'] == 'true' then return '' end
if monat == '06' then ausgabe = juni end
if monat == '07' then ausgabe = juli end
if monat == '08' then ausgabe = august end
if monat == '09' then ausgabe = september end
if monat == '10' then ausgabe = oktober end
if monat == '11' then ausgabe = november end
if monat == '12' then ausgabe = dezember end
 
return check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end


if templateArgs['no_category'] == nil
function zeit.inhalt_jahreszeit ( frame )
then
if localArgs['no_category'] == nil then templateArgs['no_category'] = '0' else templateArgs['no_category'] = localArgs['no_category'] end
funcParams = params['inhalt_jahreszeit']
args = frame:getParent().args
local paramsTypen = { astronomisch = 'astronomisch', meteorologisch = 'meteorologisch' }
local errorStr = '';
local fruehling = args['fr'] or args['fruehling'] or args['std'] or args['standard'] or funcParams['fr']
local sommer = args['so'] or args['sommer'] or args['std'] or args['standard'] or funcParams['so']
local herbst = args['he'] or args['herbst'] or args['std'] or args['standard'] or funcParams['he']
local winter = args['wi'] or args['winter'] or args['std'] or args['standard'] or funcParams['wi']
local typ = args['typ'] or funcParams['typ']
local ausgabe = funcParams['std']
if paramsTypen[typ] == nil then errorStr = check._error ('Falscher Wert für Parameter <em>typ</em>: <em>' .. typ .. '</em>', 'Zeit' ) end
if typ == 'meteorologisch' then
local monat = lang:formatDate ( 'm' )
if monat == '01' then ausgabe = winter end
if monat == '02' then ausgabe = winter end
if monat == '03' then ausgabe = fruehling end
if monat == '04' then ausgabe = fruehling end
if monat == '05' then ausgabe = fruehling end
if monat == '06' then ausgabe = sommer end
if monat == '07' then ausgabe = sommer end
if monat == '08' then ausgabe = sommer end
if monat == '09' then ausgabe = herbst end
if monat == '10' then ausgabe = herbst end
if monat == '11' then ausgabe = herbst end
if monat == '12' then ausgabe = winter end
end
end
 
if typ == 'astronomisch' then
if templateArgs['error_category'] == nil
local jahr = lang:formatDate ( 'Y' )
then  
local differenz = os.difftime ( os.time(), os.time ( { year = jahr, month = '01', day = '01' } ) )
if localArgs['error_category'] == nil
tage = math.floor ( differenz / 86400 +0.5 )
then templateArgs['error_category'] = '[[Kategorie:Fehlerberichte des Moduls Formatierung]]'
if tage < 78 then ausgabe = winter
else templateArgs['error_category'] = '[[Kategorie:' .. localArgs['error_category'] .. ']]' end
else
else templateArgs['error_category'] = '[[Kategorie:' .. templateArgs['error_category'] .. ']]'
if tage < 178 then ausgabe = fruehling
else
if tage < 265 then ausgabe = sommer
else
if tage < 355 then ausgabe = herbst
else
ausgabe = winter
end
end
end
end
end
end
return errorStr .. check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end


-- Fehler generieren
function zeit.inhalt_saison ( frame )
local error_str = '<strong class="error">Fehler im Modul [[Modul:Formatierung|Formatierung]]: ' .. error_str .. '</strong>';
if templateArgs['ignore_errors'] == '1' or templateArgs['ignore_errors'] == 'true' then error_str = '' end
funcParams = params['inhalt_saison']
args = frame:getParent().args
-- Kategorie generieren
local sommer = args['so'] or args['sommer'] or args['std'] or args['standard'] or funcParams['so']
if templateArgs['no_category'] == '0' or templateArgs['ignore_errors'] == 'false' then error_str = templateArgs['error_category'] .. error_str end
local winter = args['wi'] or args['winter'] or args['std'] or args['standard'] or funcParams['wi']
return error_str;
local ausgabe = funcParams['std']
-- local datum = os.date( '*t' )
-- if datum['isdst'] then ausgabe = sommer else ausgabe = winter end
local saison = lang:formatDate ( 'I', nil , true )
if ( saison == '1' ) then ausgabe = sommer else ausgabe = winter end
return check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end
end


function p._testParams ( templateArgs, params )
function zeit.inhalt_zeitraum ( frame )
-- Argumente des invoke-Aufrufs holen
local jahr = lang:formatDate ( 'Y' )
local frame = mw.getCurrentFrame()
funcParams = params['inhalt_zeitraum']
local localArgs = frame.args
args = frame:getParent().args
 
-- Variablen für Parameterauswertung
local errorStr = '';
local errorMsg = 'Unbekannte(r) Parameter: '
local errorCat = '[[Kategorie:Vorlagen mit unbekannten Parametern]]'
local errorOccured = false
-- generell erlaubte Parameter
local von_tag = args['von_tag'] or funcParams['von_tag']
local paramsWhitelist = { ignore_errors = 'ignore_errors', no_category = 'no_category', error_category = 'error_category' }
local von_monat = args['von_monat'] or funcParams['von_monat']
local bis_monat = args['bis_monat'] or funcParams['bis_monat']
-- Test ob unbekannte Parameter übergeben wurden (Tippfehler)
local bis_tag = args['bis_tag']
-- 0-9 werden auch stillschweigend akzeptiert
if bis_tag == nil then
-- allgemeine Parameter werden auch akzeptiert
bis_tag = funcParams['bis_tag']  
for k, v in pairs(templateArgs) do
if bis_monat == '02' then  
if  ( not ( ( params[k] ~= nil ) or ( paramsWhitelist[k] ~= nil ) ) ) and ( string.gsub( k, "%d", ".") ~= '.' )
bis_tag = 28
then  
if jahr / 4 == math.floor ( jahr / 4 ) then bis_tag = 29 end
errorMsg = errorMsg .. k .. ', '
errorOccured = true
end
end
if bis_monat == '04' then bis_tag = 30 end
if bis_monat == '06' then bis_tag = 30 end
if bis_monat == '09' then bis_tag = 30 end
if bis_monat == '11' then bis_tag = 30 end
end
end
local inhalt = args['inhalt']
if inhalt == nil then
inhalt = funcParams['inhalt']
errorStr = check._error ('Kein Textinhalt für den Zeitraum angegeben.', 'Zeit' )
end
local standard = args['std'] or args['standard'] or funcParams['std']
local ausgabe = standard


-- Parameter für Fehlerbehandlung auswerten
local differenz = os.difftime ( os.time(), os.time ( { year = jahr, month = '01', day = '01' } ) )
if templateArgs['ignore_errors'] == nil
local heute = math.floor ( differenz / 86400 +0.5 )
then  
differenz = os.difftime ( os.time( { year = jahr, month = von_monat, day = von_tag } ), os.time ( { year = jahr, month = '01', day = '01' } ) )
if localArgs['ignore_errors'] == nil then templateArgs['ignore_errors'] = '0' else templateArgs['ignore_errors'] = localArgs['ignore_errors'] end
local von = math.floor ( differenz / 86400 +0.5 )
differenz = os.difftime ( os.time( { year = jahr, month = bis_monat, day = bis_tag } ), os.time ( { year = jahr, month = '01', day = '01' } ) )
local bis = math.floor ( differenz / 86400 +0.5 )
if von > bis then
if jahr / 4 == math.floor ( jahr / 4 ) then von = von - 357 else von = von - 356 end
end
end
if templateArgs['no_category'] == nil
then  
local inside = false;
if localArgs['no_category'] == nil then templateArgs['no_category'] = '0' else templateArgs['no_category'] = localArgs['no_category'] end
if heute >= von and heute <= bis then inside = true end
if jahr / 4 == math.floor ( jahr / 4 ) then  
von = von + 357
bis = bis + 357
else  
von = von + 356
bis = bis + 356
end
end
if heute >= von and heute <= bis then inside = true end
if inside then ausgabe = inhalt end
return errorStr .. check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end
function zeit.addMonth ( frame )
if errorOccured and ( templateArgs['ignore_errors'] == '0' or templateArgs['ignore_errors'] == 'false' )
local funcParams = params['addMonth']
then
local vArgs = frame.args
errorMsg = p._error ( string.sub ( errorMsg, 1 , string.len ( errorMsg ) - 2 ) )
local args = frame:getParent().args
else
 
errorMsg = ''
local anzahl = tonumber( vArgs['anzahlMonate'] or args['anzahlMonate'] or funcParams['anzahlMonate'] )
end
local ausgabeFormat = vArgs['format'] or args['format'] or funcParams['format']
if templateArgs['no_category'] == '0' or templateArgs['no_category'] == 'false' then errorMsg = errorMsg .. '[[Kategorie:Vorlagen mit unbekannten Parametern]]' end
local jahr = tonumber( vArgs['jahr'] or args['jahr'] or lang:formatDate ( 'Y' ) )
local monat = tonumber( vArgs['monat'] or args['monat'] or lang:formatDate ( 'm' ) )
local tag = vArgs['tag'] or args['tag'] or lang:formatDate ( 'd' )
local monatStr = tostring ( monat + anzahl - ( math.floor ( ( anzahl + monat - 1 ) / 12 ) * 12 ) )
if ( string.len(monatStr) == 1 ) then monatStr = '0'..monatStr end
 
return lang:formatDate ( ausgabeFormat, tostring ( jahr + math.floor ( ( anzahl + monat - 1 ) / 12 ) )..monatStr..tag )
end
 
function zeit.addYear ( frame )
return errorMsg
local funcParams = params['addYear']
local vArgs = frame.args
local args = frame:getParent().args
 
local anzahl = tonumber( vArgs['anzahlJahre'] or args['anzahlJahre'] or funcParams['anzahlJahre'] )
local ausgabeFormat = vArgs['format'] or args['format'] or funcParams['format']
local jahr = tonumber( vArgs['jahr'] or args['jahr'] or lang:formatDate ( 'Y' ) )
local monat = vArgs['monat'] or args['monat'] or lang:formatDate ( 'm' )
local tag = vArgs['tag'] or args['tag'] or lang:formatDate ( 'd' )
 
return lang:formatDate ( ausgabeFormat, tostring ( jahr + anzahl )..monat..tag )
end
end
return zeit

Aktuelle Version vom 22. Februar 2023, 22:31 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Zeit/doc erstellt werden

local check = require('Modul:Check2')
local params = mw.loadData('Modul:Zeit/Params')
local lang = mw.language.new ( 'de' );

local zeit = {}

function zeit.inhalt_monat ( frame )
	
	funcParams = params['inhalt_monat']
	args = frame:getParent().args
	
	local januar = args['jan'] or args['januar'] or args['std'] or args['standard'] or funcParams['jan']	
	local februar = args['feb'] or args['februar'] or args['std'] or args['standard'] or funcParams['feb']
	local maerz = args['mar'] or args['maerz'] or args['std'] or args['standard'] or funcParams['mar']	
	local april = args['apr'] or args['april'] or args['std'] or args['standard'] or funcParams['apr']	
	local mai = args['mai'] or args['std'] or args['standard'] or funcParams['mai']	
	local juni = args['jun'] or args['juni'] or args['std'] or args['standard'] or funcParams['jun']	
	local juli = args['jul'] or args['juli'] or args['std'] or args['standard'] or funcParams['jul']
	local august = args['aug'] or args['august'] or args['std'] or args['standard'] or funcParams['aug']
	local september = args['sep'] or args['september'] or args['std'] or args['standard'] or funcParams['sep']	
	local oktober = args['okt'] or args['oktober'] or args['std'] or args['standard'] or funcParams['okt']	
	local november = args['nov'] or args['november'] or args['std'] or args['standard'] or funcParams['nov']
	local dezember = args['dez'] or args['dezember'] or args['std'] or args['standard'] or funcParams['dez']
	
	local ausgabe = funcParams['st']
	local monat = lang:formatDate ( 'm' )
	
	if monat == '01' then ausgabe = januar end
	if monat == '02' then ausgabe = februar end
	if monat == '03' then ausgabe = maerz end
	if monat == '04' then ausgabe = april end
	if monat == '05' then ausgabe = mai end
	if monat == '06' then ausgabe = juni end
	if monat == '07' then ausgabe = juli end
	if monat == '08' then ausgabe = august end
	if monat == '09' then ausgabe = september end
	if monat == '10' then ausgabe = oktober end
	if monat == '11' then ausgabe = november end
	if monat == '12' then ausgabe = dezember end

	return check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end

function zeit.inhalt_jahreszeit ( frame )
	
	funcParams = params['inhalt_jahreszeit']
	args = frame:getParent().args
	
	local paramsTypen = { astronomisch = 'astronomisch', meteorologisch = 'meteorologisch' }
	local errorStr = '';
	
	local fruehling = args['fr'] or args['fruehling'] or args['std'] or args['standard'] or funcParams['fr']	
	local sommer = args['so'] or args['sommer'] or args['std'] or args['standard'] or funcParams['so']	
	local herbst = args['he'] or args['herbst'] or args['std'] or args['standard'] or funcParams['he']
	local winter = args['wi'] or args['winter'] or args['std'] or args['standard'] or funcParams['wi']
	
	local typ = args['typ'] or funcParams['typ']
	
	local ausgabe = funcParams['std']
	
	if paramsTypen[typ] == nil then errorStr = check._error ('Falscher Wert für Parameter <em>typ</em>: <em>' .. typ .. '</em>', 'Zeit' ) end
	if typ == 'meteorologisch' then
		local monat = lang:formatDate ( 'm' )
		if monat == '01' then ausgabe = winter end
		if monat == '02' then ausgabe = winter end
		if monat == '03' then ausgabe = fruehling end
		if monat == '04' then ausgabe = fruehling end
		if monat == '05' then ausgabe = fruehling end
		if monat == '06' then ausgabe = sommer end
		if monat == '07' then ausgabe = sommer end
		if monat == '08' then ausgabe = sommer end
		if monat == '09' then ausgabe = herbst end
		if monat == '10' then ausgabe = herbst end
		if monat == '11' then ausgabe = herbst end
		if monat == '12' then ausgabe = winter end		
	end
	if typ == 'astronomisch' then
		local jahr = lang:formatDate ( 'Y' )
		local differenz = os.difftime ( os.time(), os.time ( { year = jahr, month = '01', day = '01' } ) )
		tage = math.floor ( differenz / 86400 +0.5 )
		if tage < 78 then ausgabe = winter
		else
			if tage < 178 then ausgabe = fruehling
			else
				if tage < 265 then ausgabe = sommer
				else
					if tage < 355 then ausgabe = herbst
					else
						ausgabe = winter
					end
				end
			end
		end
		
	end
	return errorStr .. check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end

function zeit.inhalt_saison ( frame )
	
	funcParams = params['inhalt_saison']
	args = frame:getParent().args
	
	local sommer = args['so'] or args['sommer'] or args['std'] or args['standard'] or funcParams['so']
	local winter = args['wi'] or args['winter'] or args['std'] or args['standard'] or funcParams['wi']
	
	local ausgabe = funcParams['std']
	
	-- local datum = os.date( '*t' )
	-- if datum['isdst'] then ausgabe = sommer else ausgabe = winter end
	local saison = lang:formatDate ( 'I', nil , true )
	if ( saison == '1' ) then ausgabe = sommer else ausgabe = winter end
	
	return check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end

function zeit.inhalt_zeitraum ( frame )
	
	local jahr = lang:formatDate ( 'Y' )
	funcParams = params['inhalt_zeitraum']
	args = frame:getParent().args
	
	local errorStr = '';
	
	local von_tag = args['von_tag'] or funcParams['von_tag']	
	local von_monat = args['von_monat'] or funcParams['von_monat']	
	local bis_monat = args['bis_monat'] or funcParams['bis_monat']
	
	local bis_tag = args['bis_tag']
	if bis_tag == nil then 
		bis_tag = funcParams['bis_tag'] 
		if bis_monat == '02' then 
			bis_tag = 28
			if jahr / 4 == math.floor ( jahr / 4 ) then bis_tag = 29 end
		end
		if bis_monat == '04' then bis_tag = 30 end
		if bis_monat == '06' then bis_tag = 30 end
		if bis_monat == '09' then bis_tag = 30 end
		if bis_monat == '11' then bis_tag = 30 end
	end
	
	local inhalt = args['inhalt']
	if inhalt == nil then
		inhalt = funcParams['inhalt']
		errorStr = check._error ('Kein Textinhalt für den Zeitraum angegeben.', 'Zeit' )
	end

	local standard = args['std'] or args['standard'] or funcParams['std']

	local ausgabe = standard

	local differenz = os.difftime ( os.time(), os.time ( { year = jahr, month = '01', day = '01' } ) )
	local heute = math.floor ( differenz / 86400 +0.5 )
	differenz = os.difftime ( os.time( { year = jahr, month = von_monat, day = von_tag } ), os.time ( { year = jahr, month = '01', day = '01' } ) )
	local von = math.floor ( differenz / 86400 +0.5 )
	differenz = os.difftime ( os.time( { year = jahr, month = bis_monat, day = bis_tag } ), os.time ( { year = jahr, month = '01', day = '01' } ) )
	local bis = math.floor ( differenz / 86400 +0.5 )
	if von > bis then
		if jahr / 4 == math.floor ( jahr / 4 ) then von = von - 357 else von = von - 356 end
	end
	
	local inside = false;
	
	if heute >= von and heute <= bis then inside = true end
	if jahr / 4 == math.floor ( jahr / 4 ) then 
		von = von + 357
		bis = bis + 357
	else 
		von = von + 356
		bis = bis + 356
	end
	if heute >= von and heute <= bis then inside = true end
	
	if inside then ausgabe = inhalt end
	
	return errorStr .. check._testParams ( args, funcParams, 'Zeit' ) .. ausgabe
end

function zeit.addMonth ( frame )
	
	local funcParams = params['addMonth']
	local vArgs = frame.args
	local args = frame:getParent().args

	local anzahl = tonumber( vArgs['anzahlMonate'] or args['anzahlMonate'] or funcParams['anzahlMonate'] )
	local ausgabeFormat = vArgs['format'] or args['format'] or funcParams['format']
	local jahr = tonumber( vArgs['jahr'] or args['jahr'] or lang:formatDate ( 'Y' ) )
	local monat = tonumber( vArgs['monat'] or args['monat'] or lang:formatDate ( 'm' ) )
	local tag = vArgs['tag'] or args['tag'] or lang:formatDate ( 'd' )
	
	local monatStr = tostring ( monat + anzahl - ( math.floor ( ( anzahl + monat - 1 ) / 12 ) * 12 ) )
	if ( string.len(monatStr) == 1 ) then monatStr = '0'..monatStr end

	return lang:formatDate ( ausgabeFormat, tostring ( jahr + math.floor ( ( anzahl + monat - 1 ) / 12 ) )..monatStr..tag )
end

function zeit.addYear ( frame )
	
	local funcParams = params['addYear']
	local vArgs = frame.args
	local args = frame:getParent().args

	local anzahl = tonumber( vArgs['anzahlJahre'] or args['anzahlJahre'] or funcParams['anzahlJahre'] )
	local ausgabeFormat = vArgs['format'] or args['format'] or funcParams['format']
	local jahr = tonumber( vArgs['jahr'] or args['jahr'] or lang:formatDate ( 'Y' ) )
	local monat = vArgs['monat'] or args['monat'] or lang:formatDate ( 'm' )
	local tag = vArgs['tag'] or args['tag'] or lang:formatDate ( 'd' )

	return lang:formatDate ( ausgabeFormat, tostring ( jahr + anzahl )..monat..tag )
end

return zeit