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: | ||
local DateTime = { serial = " | local DateTime = { serial = "2017-04-29", | ||
suite = "DateTime" | suite = "DateTime" } -- Date and time objects | ||
-- Date and time objects | |||
local Calc = { } | local Calc = { } | ||
local Meta = { } | local Meta = { } | ||
Zeile 107: | Zeile 103: | ||
HST = -1000 -- Hawaiian Standard Time | HST = -1000 -- Hawaiian Standard Time | ||
} | } | ||
Zeile 177: | Zeile 124: | ||
-- Returns: | -- Returns: | ||
-- string, HTML span | -- string, HTML span | ||
return string.format( "<span class=\"error\">%s</span>", a ) | |||
end -- fault() | end -- fault() | ||
Zeile 383: | Zeile 327: | ||
n = min + m | n = min + m | ||
else -- dom | else -- dom | ||
if adjust.month and adjust.year and | if adjust.month and adjust.year and n > 1 and | ||
adjust.month >= 1 and | adjust.month >= 1 and | ||
adjust.month <= 12 and | adjust.month <= 12 and | ||
adjust.year > 1900 then | adjust.year > 1900 then | ||
max = Calc.months[ adjust.month ] | |||
if adjust.month == 2 and | |||
( adjust.year % 4 ~= 0 or | |||
adjust.year % 400 == 0 ) then | |||
max = 28 | |||
end | |||
if n <= max then | |||
max = false | |||
end | end | ||
end | end | ||
if max then | |||
m = n % 30 | |||
move = ( n - m ) / 30 | |||
n = 1 + m | |||
end | |||
end | |||
end | end | ||
adjust[ s ] = n | adjust[ s ] = n | ||
end | end | ||
Zeile 419: | Zeile 354: | ||
end -- for i | end -- for i | ||
end -- Calc.fair() | end -- Calc.fair() | ||
Zeile 526: | Zeile 444: | ||
if amount <= 4 then | if amount <= 4 then | ||
r.year = tonumber( analyse ) | r.year = tonumber( analyse ) | ||
elseif | elseif n == 14 then | ||
-- timestamp | -- timestamp | ||
r.year = tonumber( analyse:sub( 1, | r.year = tonumber( analyse:sub( 1, 4 ) ) | ||
r.month = tonumber( analyse:sub( 5, | r.month = tonumber( analyse:sub( 5, 2 ) ) | ||
r.dom = tonumber( analyse:sub( 7, | r.dom = tonumber( analyse:sub( 7, 2 ) ) | ||
r.hour = tonumber( analyse:sub( 9, | r.hour = tonumber( analyse:sub( 9, 2 ) ) | ||
r.min = tonumber( analyse:sub( 11, | r.min = tonumber( analyse:sub( 11, 2 ) ) | ||
r.sec = tonumber( analyse:sub( 13, | r.sec = tonumber( analyse:sub( 13, 2 ) ) | ||
else | else | ||
r = false | r = false | ||
Zeile 828: | Zeile 746: | ||
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 1.243: | Zeile 1.161: | ||
-- analyse -- string to be interpreted | -- analyse -- string to be interpreted | ||
-- alien -- string with language code, or nil | -- alien -- string with language code, or nil | ||
-- add -- | -- add -- string, with interval (PHP strtotime), or nil | ||
-- Returns: | -- Returns: | ||
-- table, if parsed | -- table, if parsed | ||
Zeile 1.250: | Zeile 1.168: | ||
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 1.177: | ||
: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 1.190: | ||
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 | ||
Zeile 1.290: | Zeile 1.200: | ||
r = Prototypes.future( r, add ) | r = Prototypes.future( r, add ) | ||
end | end | ||
end | end | ||
else | else | ||
r = "unknown language | r = "unknown language" | ||
end | end | ||
end | end | ||
Zeile 1.360: | Zeile 1.268: | ||
-- Retrieve localization submodule | -- Retrieve localization submodule | ||
if not Meta.localized then | if not Meta.localized 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 | ||
Zeile 1.376: | Zeile 1.281: | ||
for subk, subv in pairs( v ) do | for subk, subv in pairs( v ) do | ||
wk[ subk ] = subv | wk[ subk ] = subv | ||
end -- for k, v | end -- for k, v%s %s | ||
else | else | ||
World[ k ] = v | World[ k ] = v | ||
Zeile 1.419: | Zeile 1.324: | ||
-- add -- string or number, to be added | -- add -- string or number, to be added | ||
-- Returns: | -- Returns: | ||
-- | -- string, with shift, or false/nil | ||
local r | local r | ||
if add then | if add then | ||
Zeile 1.426: | Zeile 1.331: | ||
r = tonumber( add ) | r = tonumber( add ) | ||
s = "number" | s = "number" | ||
else | |||
r = add | |||
end | end | ||
if s == "number" then | if s == "number" then | ||
Zeile 1.431: | Zeile 1.338: | ||
r = false | r = false | ||
else | else | ||
r = string.format( "%d second", | r = string.format( "%d second", r ) | ||
end | end | ||
elseif s | elseif s ~= "string" then | ||
r = false | |||
r = false | |||
end | end | ||
if r then | if r then | ||
Zeile 1.457: | Zeile 1.362: | ||
return r | return r | ||
end -- Prototypes.clone() | end -- Prototypes.clone() | ||
Zeile 1.580: | Zeile 1.440: | ||
end | end | ||
if d == 29 and m == 2 and y then | if d == 29 and m == 2 and y then | ||
if y % 4 ~= 0 | if y % 4 ~= 0 or y % 400 == 0 then | ||
ret = false | ret = false | ||
end | end | ||
Zeile 1.722: | Zeile 1.580: | ||
return r | return r | ||
end -- Prototypes.first() | end -- Prototypes.first() | ||
Zeile 1.812: | Zeile 1.657: | ||
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 | ||
Zeile 1.825: | Zeile 1.669: | ||
end | end | ||
end | end | ||
opts.lang = opts.lang | |||
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.684: | ||
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.696: | ||
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.894: | Zeile 1.736: | ||
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.983: | Zeile 1.825: | ||
end | end | ||
if r then | if r then | ||
raw = r[ Meta.signature ] | |||
rel = Private.future( shift ) | |||
end | end | ||
if raw and rel then | if raw and rel then | ||
Zeile 2.016: | Zeile 1.850: | ||
-- Returns: | -- Returns: | ||
-- string | -- string | ||
local dels = { false, "", "-", "-", "", "", ":", " | local dels = { false, "", "-", "-", "", ":", ":", ".", "", "" } | ||
local wids = { false, 4, 2, 2, 2, 2, | local wids = { false, 4, 2, 2, 2, 2, 2, 2, 3, 3 } | ||
local s = "" | local s = "" | ||
local n, r, spec | local n, r, spec | ||
Zeile 2.028: | Zeile 1.862: | ||
end | end | ||
end -- f() | end -- f() | ||
for i = 2, | for i = 2, 4 do | ||
f( i ) | f( i ) | ||
end -- for i | end -- for i | ||
r = s | r = s | ||
s = "" | s = "" | ||
for i = | for i = 5, 10 do | ||
f( i ) | f( i ) | ||
end -- for i | end -- for i | ||
Zeile 2.045: | Zeile 1.879: | ||
end | end | ||
end | end | ||
return r | return r | ||
end -- Prototypes.tostring() | end -- Prototypes.tostring() | ||
Zeile 2.115: | Zeile 1.948: | ||
if not ask or ask == "" then | if not ask or ask == "" then | ||
r1 = "c" | r1 = "c" | ||
else | else | ||
local template = World.templates[ ask ] | local template = World.templates[ ask ] | ||
Zeile 2.143: | Zeile 1.956: | ||
if tmp then | if tmp then | ||
template = tmp[ ask ] | template = tmp[ ask ] | ||
end | end | ||
end | end | ||
Zeile 2.174: | Zeile 1.977: | ||
end | end | ||
if template.lift and | if template.lift and | ||
( assigned.dom or | (assigned.dom or | ||
not (assigned.month or assigned.year or assigned.bc) | |||
) then | ) then | ||
local stamp = false | local stamp = false | ||
Zeile 2.198: | Zeile 2.001: | ||
end | end | ||
end | end | ||
if low or ask:find( "hh:mm:ss" | if low or ask:find( "hh:mm:ss" ) then | ||
if stamp then | if stamp then | ||
r1 = string.format( "%s %s", r1, stamp ) | r1 = string.format( "%s %s", r1, stamp ) | ||
Zeile 2.254: | Zeile 2.057: | ||
if #s == 1 then | if #s == 1 then | ||
-- "YXWVUTSRQPONZABCDEFGHIKLM" | -- "YXWVUTSRQPONZABCDEFGHIKLM" | ||
move = World.zones[ "!" ]:find( s | move = World.zones[ "!" ]:find( s ) | ||
if move then | if move then | ||
move = ( move - 13 ) * 100 | move = ( move - 13 ) * 100 | ||
Zeile 2.269: | Zeile 2.072: | ||
if tmp then | if tmp then | ||
code = tmp[ s ] | code = tmp[ s ] | ||
end | end | ||
end | end | ||
Zeile 2.331: | Zeile 2.129: | ||
function p.test( args, alien ) | function p.test( args, alien ) | ||
local slang = args.lang | local slang = args.lang | ||
local obj = Meta.fiat( args[ 1 ], false, args.shift ) | local obj = Meta.fiat( args[ 1 ], false, args.shift ) | ||
local r | local r | ||
Zeile 2.347: | Zeile 2.145: | ||
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.363: | Zeile 2.161: | ||
since = frame.args[ 1 ] | since = frame.args[ 1 ] | ||
elseif s == "string" then | elseif s == "string" then | ||
since = frame | |||
end | |||
if since then | |||
since = mw.text.trim( since ) | since = mw.text.trim( since ) | ||
if since == "" then | if since == "" then | ||
Zeile 2.368: | Zeile 2.169: | ||
end | end | ||
end | end | ||
if since then | |||
if since > Meta.serial then | |||
r = "" | |||
else | |||
r = Meta.serial | |||
end | |||
else | |||
r = Meta.serial | |||
end | |||
return r | |||
end -- p.failsafe | end -- p.failsafe | ||