Bearbeiten von „Modul:DateTime“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
--[=[ 2015-03-16 | |||
Date and time utilities | |||
]=] | |||
-- Date and time | |||
local | -- local globals | ||
local | local DateTime | ||
local Parser = { } | local Parser = { } | ||
local Private = { } | local Private = { } | ||
local Prototypes = { } | local Prototypes = { } | ||
local World = { slang = "en", | local World = { slang = "en", | ||
monthsLong = { }, | monthsLong = { }, | ||
Zeile 18: | Zeile 17: | ||
local Nbsp = mw.ustring.char( 160 ) | local Nbsp = mw.ustring.char( 160 ) | ||
local Tab = mw.ustring.char( 9 ) | local Tab = mw.ustring.char( 9 ) | ||
World.era = { en = { "BC", "AD" } } | World.era = { en = { "BC", "AD" } } | ||
World.monthsAbbr = { en = { n = 3 } } | World.monthsAbbr = { en = { n = 3 } } | ||
Zeile 107: | Zeile 105: | ||
HST = -1000 -- Hawaiian Standard Time | HST = -1000 -- Hawaiian Standard Time | ||
} | } | ||
Zeile 167: | Zeile 116: | ||
return mw.ustring.upper( mw.ustring.sub( a, 1, 1 ) ) | return mw.ustring.upper( mw.ustring.sub( a, 1, 1 ) ) | ||
.. mw.ustring.lower( mw.ustring.sub( a, 2 ) ) | .. mw.ustring.lower( mw.ustring.sub( a, 2 ) ) | ||
end -- | end -- fault() | ||
Zeile 177: | Zeile 126: | ||
-- Returns: | -- Returns: | ||
-- string, HTML span | -- string, HTML span | ||
return string.format( "<span class=\"error\">%s</span>", a ) | |||
end -- fault() | end -- fault() | ||
DateTime = function ( assign, alien ) | |||
-- Create metatable (constructor) | |||
-- Create | |||
-- Parameter: | -- Parameter: | ||
-- assign -- string, with initial timestamp, or nil | -- assign -- string, with initial timestamp, or nil | ||
-- nil -- now | -- nil -- now | ||
-- false -- empty object | -- false -- empty object | ||
-- alien -- string, with language code, or nil | -- alien -- string, with language code, or nil | ||
-- Returns: | -- Returns: | ||
-- table, as DateTime object | -- table, as DateTime object | ||
Zeile 299: | Zeile 143: | ||
local r | local r | ||
Private.foreign() | Private.foreign() | ||
r = Private.factory( assign, alien ) | |||
if type( r ) == "table" then | if type( r ) == "table" then | ||
r = { [ | local meta = { } | ||
setmetatable( r, | local s = "__datetime" | ||
meta.__index = function( self, access ) | |||
return self[ s ][ access ] | |||
end | |||
meta.__newindex = function( self, access, assign ) | |||
if type( access ) == "string" then | |||
local data = self[ s ] | |||
if assign == nil then | |||
local val = data[ access ] | |||
data[ access ] = nil | |||
if not Prototypes.fair( data ) then | |||
data[ access ] = val | |||
end | |||
elseif Prototypes.fair( data, | |||
access, | |||
assign ) then | |||
data[ access ] = assign | |||
end | |||
end | |||
return | |||
end | |||
r = { [ s ] = r } | |||
r.fair = function ( ... ) | |||
return Prototypes.fair( ... ) | |||
end | |||
r.figure = function ( ... ) | |||
return Prototypes.figure( ... ) | |||
end | |||
r.first = function ( ... ) | |||
return Prototypes.first( ... ) | |||
end | |||
r.format = function ( ... ) | |||
return Prototypes.format( ... ) | |||
end | |||
r.full = function ( ... ) | |||
return Prototypes.full( ... ) | |||
end | |||
setmetatable( r, meta ) | |||
end | end | ||
return r | return r | ||
end -- | end -- DateTime() | ||
Parser.digitsHeading = function ( analyse, alone, amount, add ) | |||
-- String analysis, if digits only or at least 4 digits heading | |||
-- | |||
-- Parameter: | -- Parameter: | ||
-- | -- analyse -- string to be scanned, starting with digit | ||
-- digits only, else starting with exactly 4 digits | |||
-- alone -- true, if only digits | |||
-- amount -- number of heading digits | |||
-- add -- table, to be extended | |||
-- | |||
-- | |||
-- Returns: | -- Returns: | ||
-- | -- table, extended if parsed | ||
local r = | -- false, if invalid text format | ||
if | local r = add | ||
if alone then | |||
-- digits only | |||
if amount <= 4 then | |||
r.year = tonumber( analyse ) | |||
elseif n == 14 then | |||
-- timestamp | |||
r.year = tonumber( analyse:sub( 1, 4 ) ) | |||
r.month = tonumber( analyse:sub( 5, 2 ) ) | |||
r.dom = tonumber( analyse:sub( 7, 2 ) ) | |||
r.hour = tonumber( analyse:sub( 9, 2 ) ) | |||
r.min = tonumber( analyse:sub( 11, 2 ) ) | |||
r.sec = tonumber( analyse:sub( 13, 2 ) ) | |||
else | else | ||
r = false | |||
end | end | ||
elseif amount == 4 then | |||
local s, sep, sx = analyse:match( "^(%d+)([%-%.:Ww]?)(.*)$" ) | |||
elseif amount == 4 then | |||
local s, sep, sx = analyse:match( "^(%d+)([%-%.:Ww]?)(.*)$" ) | |||
r.year = tonumber( s ) | r.year = tonumber( s ) | ||
if sep == "-" then | if sep == "-" then | ||
Zeile 583: | Zeile 263: | ||
else | else | ||
r = false | r = false | ||
end | end | ||
elseif amount == 8 then | elseif amount == 8 then | ||
Zeile 606: | Zeile 283: | ||
n = n .. "00" | n = n .. "00" | ||
r.msec = tonumber( n:sub( 1, 3 ) ) | r.msec = tonumber( n:sub( 1, 3 ) ) | ||
sz = s | |||
sz = s | |||
end | end | ||
end | end | ||
Zeile 787: | Zeile 461: | ||
rO = false | rO = false | ||
end | end | ||
if rO then | if not rO then | ||
rS = false | rS = false | ||
end | end | ||
Zeile 828: | Zeile 500: | ||
n = #s2 | n = #s2 | ||
if n <= 2 and #s3 == 4 then | if n <= 2 and #s3 == 4 then | ||
rO.dom = tonumber( | rO.dom = tonumber( n ) | ||
rO.year = tonumber( s3 ) | rO.year = tonumber( s3 ) | ||
rO.dom2 = ( n == 2 ) | rO.dom2 = ( n == 2 ) | ||
Zeile 968: | Zeile 640: | ||
s = sx:match( "^%.(%d+)$" ) | s = sx:match( "^%.(%d+)$" ) | ||
if s then | if s then | ||
r.msec = tonumber( s ) | |||
r.msec = tonumber( s | |||
else | else | ||
r = false | r = false | ||
Zeile 1.193: | Zeile 861: | ||
Private.factory = function ( assign, alien | Private.factory = function ( assign, alien ) | ||
-- Create DateTime table (constructor) | -- Create DateTime table (constructor) | ||
-- Parameter: | -- Parameter: | ||
Zeile 1.200: | Zeile 868: | ||
-- false -- empty object | -- false -- empty object | ||
-- alien -- string, with language code, or nil | -- alien -- string, with language code, or nil | ||
-- Returns: | -- Returns: | ||
-- table, for DateTime object | -- table, for DateTime object | ||
-- string or false, if failed | -- string or false, if failed | ||
local l = true | local l = true | ||
local r = false | |||
local slang = mw.text.trim( alien or World.slang or "en" ) | local slang = mw.text.trim( alien or World.slang or "en" ) | ||
if assign == false then | if assign == false then | ||
r = { } | r = { } | ||
else | else | ||
local stamp = ( assign or "now" ) | local stamp = ( assign or "now" ) | ||
if stamp == "now" then | if stamp == "now" then | ||
stamp = | stamp = mw.getCurrentFrame():callParserFunction( "#timel", | ||
"c" ) | |||
else | else | ||
local seconds = stamp:match( "^#(%d+)$" ) | local seconds = stamp:match( "^#(%d+)$" ) | ||
Zeile 1.226: | Zeile 888: | ||
end | end | ||
end | end | ||
l, r = pcall( Private.fetch, stamp, slang | l, r = pcall( Private.fetch, stamp, slang ) | ||
end | end | ||
if l and type( r ) == "table" then | if l and type( r ) == "table" then | ||
Zeile 1.238: | Zeile 900: | ||
Private.fetch = function ( analyse, alien | Private.fetch = function ( analyse, alien ) | ||
-- Retrieve object from string | -- Retrieve object from string | ||
-- Parameter: | -- Parameter: | ||
-- analyse -- string to be interpreted | -- analyse -- string to be interpreted | ||
-- alien -- string with language code, or nil | -- alien -- string with language code, or nil | ||
-- Returns: | -- Returns: | ||
-- table, if parsed | -- table, if parsed | ||
Zeile 1.250: | Zeile 911: | ||
local r | local r | ||
if type( analyse ) == "string" then | if type( analyse ) == "string" then | ||
r = analyse:gsub( " ", " " ) | r = analyse:gsub( " ", " " ) | ||
:gsub( " ", " " ) | :gsub( " ", " " ) | ||
Zeile 1.260: | Zeile 920: | ||
:gsub( "%[%[", "" ) | :gsub( "%[%[", "" ) | ||
:gsub( "%]%]", "" ) | :gsub( "%]%]", "" ) | ||
r = mw.text.trim( r ) | r = mw.text.trim( r ) | ||
if r == "" then | if r == "" then | ||
r = { } | r = { } | ||
else | else | ||
local slang | local slang = ( alien or "" ) | ||
if slang == "" then | if slang == "" then | ||
slang = "en" | slang = "en" | ||
Zeile 1.279: | Zeile 933: | ||
end | end | ||
end | end | ||
slang | slang = slang:lower() | ||
if slang == "en" or slang == "de" then | |||
local l | local l | ||
l, r = pcall( Parser | l, r = pcall( Parser.GermanEnglish, r ) | ||
if l and r then | if l and r then | ||
if not Prototypes.fair( r ) then | if not Prototypes.fair( r ) then | ||
r = false | r = false | ||
end | end | ||
end | end | ||
else | else | ||
r = "unknown language | r = "unknown language" | ||
end | end | ||
end | end | ||
Zeile 1.305: | Zeile 954: | ||
Private. | Private.foreign = function () | ||
-- Retrieve localization submodule | -- Retrieve localization submodule | ||
if not | if not World.localization then | ||
local d = | local l, d = pcall( mw.loadData, "Module:DateTime/local" ) | ||
if l then | |||
if | |||
local wk | local wk | ||
if d.slang then | if d.slang then | ||
World.slang = d.slang | World.slang = d.slang | ||
end | end | ||
Zeile 1.382: | Zeile 974: | ||
end -- for k, v | end -- for k, v | ||
end | end | ||
World.localization = true | |||
end | end | ||
end -- Private.foreign() | end -- Private.foreign() | ||
Zeile 1.388: | Zeile 980: | ||
Prototypes.fair = function ( self, access, assign ) | |||
-- | -- Check formal validity of table | ||
-- Parameter: | -- Parameter: | ||
-- | -- self -- table, to be checked | ||
-- access -- string or nil, single item to be checked | |||
-- assign -- single access value to be checked | |||
-- Returns: | -- Returns: | ||
-- | -- true, if valid; false, if not | ||
local r = ( type( self ) == "table" ) | |||
local r | if r then | ||
local defs = { year = { max = MaxYear }, | |||
month = { min = 1, | |||
max = 12 }, | |||
dom = { min = 1, | |||
max = 31 }, | |||
hour = { max = 23 }, | |||
min = { max = 59 }, | |||
sec = { max = 61 }, | |||
msec = { max = 1000 } | |||
} | |||
if | local months = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } | ||
local fNum = | |||
function ( k, v ) | |||
local ret = true | |||
local dk = defs[ k ] | |||
if dk then | |||
if type( dk.max ) == "number" then | |||
ret = ( type( v ) == "number" ) | |||
if ret then | |||
local min | |||
if dk.min then | |||
min = dk.min | |||
else | |||
min = 0 | |||
end | |||
ret = ( v >= min and v <= dk.max | |||
and math.floor( v ) == v ) | |||
if ret and dk.f then | |||
ret = dk.f( v ) | |||
end | |||
end | |||
end | end | ||
end | end | ||
end | return ret | ||
end -- fNum() | |||
defs.dom.f = | |||
function () | |||
local ret | |||
local d | |||
if access == "dom" then | |||
d = assign | |||
else | |||
d = self.dom | |||
end | |||
if d then | |||
ret = ( d <= 28 ) | |||
if not ret then | |||
local m | |||
if access == "month" then | |||
m = assign | |||
else | |||
m = self.month | |||
end | |||
if m then | |||
ret = ( d <= months[ m ] ) | |||
if ret then | |||
local y | |||
if access == "year" then | |||
y = assign | |||
else | |||
y = self.year | |||
end | |||
if d == 29 and m == 2 and y then | |||
if y % 4 ~= 0 or y % 400 == 0 then | |||
ret = false | |||
end | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
else | |||
ret = true | |||
end | end | ||
return ret | return ret | ||
end -- | end -- defs.dom.f() | ||
defs. | defs.sec.f = | ||
function () | function () | ||
local ret | local ret | ||
local | local second | ||
if access == " | if access == "sec" then | ||
second = assign | |||
else | else | ||
second = self.sec | |||
end | |||
if second then | |||
ret = ( second <= 59 ) | |||
if not ret and self.leap then | |||
ret = true | |||
end | |||
end | end | ||
return ret | |||
end -- defs.sec.f() | |||
if access or assign then | |||
r = ( type( access ) == "string" ) | |||
if r then | |||
local def = defs[ access ] | |||
if def then | |||
r = fNum( access, assign ) | |||
if r then | |||
if def == "dom" or | |||
def == "month" or | |||
def == "year" then | |||
r = defs.dom.f() | |||
end | end | ||
end | end | ||
elseif access == "lang" then | |||
r = ( type( assign ) == "string" ) | |||
if r then | |||
r = assign:match( "^%l%l%l?-?%a*$" ) | |||
if | |||
end | end | ||
elseif access == "london" then | |||
r = ( type( assign ) == "boolean" ) | |||
end | end | ||
end | |||
end | else | ||
local order = { "bc", "year", "month", "dom", | |||
"hour", "min", "sec", "msec" } | |||
local life = false | |||
local leak = false | |||
local s, v | |||
for i = 1, 8 do | |||
s = order[ i ] | |||
v = self[ s ] | |||
if v then | |||
if not life and leak then | |||
local life | |||
local leak | |||
local s, v | |||
for i = 1, | |||
s = | |||
v = self[ s ] | |||
if v then | |||
if not life and leak then | |||
-- gap detected | -- gap detected | ||
r = false | r = false | ||
Zeile 1.648: | Zeile 1.121: | ||
if not fNum( s, v ) then | if not fNum( s, v ) then | ||
r = false | r = false | ||
break | break | ||
end | end | ||
life = true | life = true | ||
leak = true | leak = true | ||
end | end | ||
else | |||
life = false | life = false | ||
end | end | ||
end -- for i | end -- for i | ||
end | |||
end | |||
end | end | ||
return r | return r | ||
Zeile 1.722: | Zeile 1.188: | ||
return r | return r | ||
end -- Prototypes.first() | end -- Prototypes.first() | ||
Zeile 1.806: | Zeile 1.198: | ||
-- adapt -- table, with options, or nil | -- adapt -- table, with options, or nil | ||
-- .lang -- string, with particular language code | -- .lang -- string, with particular language code | ||
-- .lonely -- true: permit lonely hour | -- .lonely -- true: permit lonely hour | ||
-- Returns: | -- Returns: | ||
Zeile 1.812: | Zeile 1.203: | ||
local r = false | local r = false | ||
if type( self ) == "table" then | if type( self ) == "table" then | ||
local opts = { lang = self.lang } | |||
local opts = { lang = | local babel, slang | ||
local babel | |||
if type( adapt ) == "table" then | if type( adapt ) == "table" then | ||
if type( adapt.lang ) == "string" then | if type( adapt.lang ) == "string" then | ||
local i = adapt.lang:find( "-", 3, true ) | local i = adapt.lang:find( "-", 3, true ) | ||
if i then | if i then | ||
slang = adapt.lang | slang = adapt.lang | ||
opts.lang = slang:sub( 1, i - 1 ) | opts.lang = slang:sub( 1, i - 1 ) | ||
else | else | ||
opts.lang = adapt.lang | opts.lang = adapt.lang | ||
end | end | ||
end | end | ||
opts.lang = opts.lang:lower() | |||
opts.london = adapt.london | opts.london = adapt.london | ||
opts.lonely = adapt.lonely | opts.lonely = adapt.lonely | ||
end | end | ||
babel = mw.language.new( opts.lang | babel = mw.language.new( opts.lang ) | ||
if babel then | if babel then | ||
local shift, show, stamp, suffix, limit4, locally | local shift, show, stamp, suffix, limit4, locally | ||
Zeile 1.839: | Zeile 1.230: | ||
stamp = string.format( "%d %s", self.dom, stamp ) | stamp = string.format( "%d %s", self.dom, stamp ) | ||
end | end | ||
if ask and ask:find( "Mon4" | if ask and ask:find( "Mon4" ) then | ||
local mon4 = World.months4[ opts.lang | local mon4 = World.months4[ opts.lang ] | ||
if mon4 | if mon4 then | ||
if mon4[ self.month ] then | |||
limit4 = true | |||
end | |||
end | end | ||
end | end | ||
Zeile 1.849: | Zeile 1.242: | ||
end | end | ||
if self.hour then | if self.hour then | ||
stamp = string.format( "%s %02d:", stamp, self.hour ) | |||
stamp = string.format( "%s%02d:", stamp, self.hour ) | |||
if self.min then | if self.min then | ||
stamp = string.format( "%s%02d", stamp, self.min ) | stamp = string.format( "%s%02d", stamp, self.min ) | ||
Zeile 1.861: | Zeile 1.249: | ||
stamp, self.sec ) | stamp, self.sec ) | ||
if self.msec then | if self.msec then | ||
stamp = string.format( "%s.% | stamp = string.format( "%s.%d", | ||
stamp, self.msec ) | stamp, self.msec ) | ||
end | end | ||
end | end | ||
Zeile 1.894: | Zeile 1.277: | ||
if self.month then | if self.month then | ||
local bucket, m, suite, x | local bucket, m, suite, x | ||
if show:find( "F" | if show:find( "F" ) then | ||
suite = "monthsLong" | suite = "monthsLong" | ||
elseif show:find( "M" | elseif show:find( "M" ) then | ||
suite = "monthsAbbr" | suite = "monthsAbbr" | ||
end | end | ||
bucket = World[ suite ] | bucket = World[ suite ] | ||
if bucket then | if bucket then | ||
m = bucket[ opts.lang | m = bucket[ opts.lang ] | ||
if slang then | if slang then | ||
x = bucket[ slang | x = bucket[ slang ] | ||
end | end | ||
if m then | if m then | ||
Zeile 1.966: | Zeile 1.349: | ||
World.templates.formatter = function ( assigned, ask, adapt ) | |||
-- | -- Retrieve format specification string | ||
-- Parameter: | -- Parameter: | ||
-- | -- assigned -- table, with numbers etc. | ||
-- | -- ask -- string, format spec, or nil | ||
-- | -- adapt -- table, with options | ||
-- .lang -- string, with particular language code | |||
-- .lonely -- true: permit lonely hour | |||
-- Returns: | -- Returns: | ||
-- | -- 1 -- string | ||
local | -- 2 -- string or nil; append suffix (zone) | ||
if | local r1, r2 | ||
if not ask or ask == "" then | |||
r1 = "c" | |||
else | |||
local template = World.templates[ ask ] | |||
r1 = ask | |||
if not template then | |||
local slang = ( adapt.lang or assigned.lang or World.slang ) | |||
local tmp = World.templates[ slang ] | |||
if tmp then | |||
template = tmp[ ask ] | |||
end | |||
end | end | ||
if type( | if type( template ) == "table" then | ||
local low = ( ask == "ISO" or ask == "ISO-T" ) | |||
r1 = template.spec | |||
if assigned.year then | |||
if not assigned.dom then | |||
r1 = r1:gsub( "[ .%-]?[dDjlNwz][ .,%-]*", "" ) | |||
:gsub( "^ ", "" ) | |||
if not assigned.month then | |||
r1 = r1:gsub( "[ .%-]?[FmMnt][ .%-]*", "" ) | |||
end | |||
end | |||
else | |||
r1 = r1:gsub( " ?[yY] ?", "" ) | |||
if not assigned.dom then | |||
r1 = r1:gsub( "[ .]?[dDjlNwz][ .,%-]*", "" ) | |||
:gsub( "^ ", "" ) | |||
end | |||
end | |||
if template.lift and | |||
(assigned.dom or | |||
not (assigned.month or assigned.year or assigned.bc) | |||
) then | |||
local stamp = false | |||
if assigned.hour then | |||
if assigned.min then | |||
stamp = "H:i" | |||
if assigned.sec then | |||
stamp = "H:i:s" | |||
if assigned.msec then | |||
stamp = string.format( "%s.%d", | |||
stamp, | |||
assigned.msec ) | |||
end | |||
end | |||
elseif adapt.lonely then | |||
stamp = "H" | |||
end | |||
end | |||
if low or ask:find( "hh:mm:ss" ) then | |||
if stamp then | |||
r1 = string.format( "%s %s", r1, stamp ) | |||
end | |||
end | |||
if stamp then | |||
if low or template.long then | |||
local scheme | |||
if template.long then | |||
scheme = mw.language.getContentLanguage() | |||
scheme = scheme.code | |||
end | |||
r2 = World.zones.formatter( assigned, scheme ) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
if type ( assigned.bc ) == "boolean" then | |||
local eras = World.era[ adapt.lang ] or World.era.en | |||
local i | |||
if not r2 then | |||
r2 = "" | |||
end | |||
if assigned.bc then | |||
i = 1 | |||
else | |||
i = 2 | |||
if | |||
end | end | ||
r2 = string.format( "%s %s", r2, eras[ i ] ) | |||
end | end | ||
end | end | ||
end | |||
return r1, r2 | |||
end -- World.templates.formatter() | |||
World.zones.formatter = function ( assigned, align ) | |||
-- Retrieve time zone specification string | |||
-- Parameter: | |||
-- assigned -- table, with numbers etc. | |||
-- .zone should be available | |||
-- align -- string, format spec, or nil | |||
-- nil, false, "+-" -- +/- 0000 | |||
-- "Z" -- single letter | |||
-- "UTC" -- "UTC", if appropriate | |||
-- "de" -- try localized | |||
-- Returns: | |||
-- string | |||
local r = "" | |||
local move = 0 | |||
if assigned.zone then | |||
local s = type( assigned.zone ) | |||
if s == "string" then | |||
if | s = assigned.zone:upper() | ||
if #s == 1 then | |||
-- "YXWVUTSRQPONZABCDEFGHIKLM" | |||
move = World.zones[ "!" ]:find( s ) | |||
if move then | |||
move = ( move - 13 ) * 100 | |||
assigned.zone = move | |||
else | |||
assigned.zone = false | |||
end | |||
else | |||
local code = World.zones[ s ] | |||
if not code then | |||
local slang = ( assigned.lang or | |||
World.slang ) | |||
local tmp = World.zones[ slang ] | |||
if tmp then | |||
code = tmp[ s ] | |||
end | |||
end | end | ||
if | if code then | ||
move = code | |||
assigned.zone = move | |||
end | end | ||
end | |||
elseif s == "number" then | |||
move = assigned.zone | |||
end | |||
end | |||
if move then | |||
local spec = "+-" | |||
if align then | |||
if align == "Z" then | |||
if move % 100 == 0 then | |||
r = World.zones[ "!" ]:sub( move / 100 + 13, 1 ) | |||
spec = false | |||
end | |||
elseif align ~= "+-" then | |||
if move == 0 then | |||
r = " UTC" | |||
spec = false | |||
else | |||
local part = World.zones[ align ] | |||
if part then | |||
for k, v in pairs( part ) do | |||
if v == move then | |||
r = string.format( " (%s)", k ) | |||
spec = false | |||
break | |||
end | |||
end -- for k, v | |||
end | end | ||
end | end | ||
end | end | ||
end | |||
if spec == "+-" then | |||
if move < 0 then | |||
spec = "%4.4d" | |||
else | |||
spec = "+%4.4d" | |||
end | end | ||
r = string.format( spec, move ) | |||
r = string.format( "%s:%s", | |||
r:sub( 1, 3), r:sub( 4 ) ) | |||
end | end | ||
end | end | ||
return | return r | ||
end -- World. | end -- World.zones.formatter() | ||
-- Export | |||
local p = { } | |||
function p.test( args ) | |||
local r | |||
local obj = DateTime( args[ 1 ], "de" ) | |||
if type( obj ) == "table" then | |||
local opt | |||
-- Export | |||
local p = { } | |||
function p.test( args | |||
local | |||
local obj | |||
if type( obj ) == "table" then | |||
local spec = args[ 2 ] | local spec = args[ 2 ] | ||
local | local slang = args[ 3 ] | ||
if spec then | if spec then | ||
spec = mw.text.trim( spec ) | spec = mw.text.trim( spec ) | ||
Zeile 2.347: | Zeile 1.555: | ||
r = ( args.noerror or "0" ) | r = ( args.noerror or "0" ) | ||
if r == "0" then | if r == "0" then | ||
r = fault( "Format | r = fault( "Format nicht erkannt" ) | ||
else | else | ||
r = "" | r = "" | ||
Zeile 2.354: | Zeile 1.562: | ||
return r | return r | ||
end -- p.test | end -- p.test | ||
function p.format( frame ) | function p.format( frame ) | ||
local l, r | local l, r | ||
local v = { frame.args[ 1 ], | local v = { frame.args[ 1 ], | ||
frame.args[ 2 ], | frame.args[ 2 ], | ||
frame.args[ 3 ], | |||
noerror = frame.args.noerror } | noerror = frame.args.noerror } | ||
if not v[ 1 ] or v[ 1 ] == "now" then | if not v[ 1 ] or v[ 1 ] == "now" then | ||
v[ 1 ] | v[ 1 ] = frame:callParserFunction( "#timel", "c" ) | ||
end | end | ||
l, r = pcall( p.test, v ) | |||
l, r = pcall( p.test, | |||
if not l then | if not l then | ||
r = fault( r ) | r = fault( r ) | ||
Zeile 2.398: | Zeile 1.583: | ||
p.DateTime = function ( ... ) | |||
return DateTime( ... ) | |||
function | |||
return | |||
end -- p.DateTime | end -- p.DateTime | ||
return p | return p |