Modul:DateTime: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
gemäß Wunsch von WP:AAF aktuaisiert.
(Muss nochmal nachfragen.) |
(gemäß Wunsch von WP:AAF aktuaisiert.) |
||
| Zeile 1: | Zeile 1: | ||
local DateTime = { serial = "2019- | local DateTime = { serial = "2019-10-21", | ||
suite = "DateTime", | suite = "DateTime", | ||
item = 20652535 } | item = 20652535 } | ||
-- Date and time objects | -- Date and time objects | ||
local Failsafe = DateTime | local Failsafe = DateTime | ||
local GlobalMod = DateTime | |||
local Calc = { } | local Calc = { } | ||
local Meta = { } | local Meta = { } | ||
| Zeile 106: | Zeile 107: | ||
HST = -1000 -- Hawaiian Standard Time | HST = -1000 -- Hawaiian Standard Time | ||
} | } | ||
local foreignModule = function ( access, advanced, append, alt, alert ) | |||
-- Fetch global module | |||
-- Precondition: | |||
-- access -- string, with name of base module | |||
-- advanced -- true, for require(); else mw.loadData() | |||
-- append -- string, with subpage part, if any; or false | |||
-- alt -- number, of wikidata item of root; or false | |||
-- alert -- true, for throwing error on data problem | |||
-- Postcondition: | |||
-- Returns whatever, probably table | |||
-- 2019-10-20 | |||
local storage = access | |||
local fun, lucky, r | |||
if advanced then | |||
fun = require | |||
else | |||
fun = mw.loadData | |||
end | |||
if append then | |||
storage = string.format( "%s/%s", storage, append ) | |||
end | |||
lucky, r = pcall( fun, "Module:" .. storage ) | |||
if not lucky then | |||
local suited | |||
GlobalMod.globalModules = GlobalMod.globalModules or { } | |||
suited = GlobalMod.globalModules[ access ] | |||
if not suited and | |||
type( alt ) == "number" and | |||
alt > 0 then | |||
suited = string.format( "Q%d", alt ) | |||
suited = mw.wikibase.getSitelink( suited ) | |||
GlobalMod.globalModules[ access ] = suited or true | |||
end | |||
if type( suited ) == "string" then | |||
storage = suited | |||
if append then | |||
storage = string.format( "%s/%s", storage, append ) | |||
end | |||
lucky, r = pcall( fun, storage ) | |||
end | |||
if not lucky and alert then | |||
error( "Missing or invalid page: " .. storage, 0 ) | |||
end | |||
end | |||
return r | |||
end -- foreignModule() | |||
| Zeile 1.215: | Zeile 1.265: | ||
r = { } | r = { } | ||
else | else | ||
local slang = ( alien or "" ) | local slang = ( alien or "" ) | ||
local parser = { en = "GermanEnglish", | |||
de = "GermanEnglish", | |||
frr = "GermanEnglish", | |||
nds = "GermanEnglish" } | |||
local suitable | |||
if slang == "" then | if slang == "" then | ||
slang = "en" | slang = "en" | ||
| Zeile 1.224: | Zeile 1.279: | ||
end | end | ||
end | end | ||
slang = slang:lower() | slang = slang:lower() | ||
suitable = parser[ slang ] | |||
if suitable then | |||
local l | local l | ||
l, r = pcall( Parser | l, r = pcall( Parser[ suitable ], r ) | ||
if l and r then | if l and r then | ||
if not Prototypes.fair( r ) then | if not Prototypes.fair( r ) then | ||
| Zeile 1.238: | Zeile 1.294: | ||
end | end | ||
else | else | ||
r = "unknown language" | r = "unknown language: " .. slang | ||
end | end | ||
end | end | ||
| Zeile 1.304: | Zeile 1.360: | ||
-- Retrieve localization submodule | -- Retrieve localization submodule | ||
if not Meta.localized then | if not Meta.localized then | ||
local | local d = foreignModule( DateTime.suite, | ||
if | false, | ||
"local", | |||
DateTime.item ) | |||
if d then | |||
local wk | local wk | ||
if d.slang then | if d.slang then | ||
| Zeile 1.419: | Zeile 1.478: | ||
item ) ) | item ) ) | ||
if type( entity ) == "table" then | if type( entity ) == "table" then | ||
local vsn = entity:formatPropertyValues( | local seek = Failsafe.serialProperty or "P348" | ||
local vsn = entity:formatPropertyValues( seek ) | |||
if type( vsn ) == "table" and | if type( vsn ) == "table" and | ||
type( vsn.value ) == "string" and | type( vsn.value ) == "string" and | ||
vsn.value ~= "" then | vsn.value ~= "" then | ||
if last | if last and | ||
vsn.value == ( Meta.serial or DateTime.serial ) then | |||
r = false | r = false | ||
else | else | ||
| Zeile 2.235: | Zeile 2.296: | ||
function p.test( args, alien ) | function p.test( args, alien ) | ||
local slang = args.lang | local slang = args.lang or alien | ||
local obj = Meta.fiat( args[ 1 ], false, args.shift ) | local obj = Meta.fiat( args[ 1 ], false, args.shift ) | ||
local r | local r | ||