Modul:DateTime: Unterschied zwischen den Versionen

6.953 Bytes hinzugefügt ,  3. Juli 2020
K
32 Versionen importiert: Doku-Vorlage
K (Änderte den Schutzstatus für „Modul:DateTime“: Häufig eingebundenes Modul: https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=170687742&oldid=170687631 ([Bearbeiten=Nur Administratoren] (unbe…)
K (32 Versionen importiert: Doku-Vorlage)
 
(12 dazwischenliegende Versionen von 7 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local DateTime  = { serial = "2017-04-29",
local DateTime  = { serial = "2020-04-08",
                     suite  = "DateTime" }   -- Date and time objects
                     suite  = "DateTime",
                    item  = 20652535 }
-- Date and time objects
local Failsafe  = DateTime
local GlobalMod  = DateTime
local Calc      = { }
local Calc      = { }
local Meta      = { }
local Meta      = { }
Zeile 103: 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 124: Zeile 177:
     -- Returns:
     -- Returns:
     --    string, HTML span
     --    string, HTML span
     return string.format( "<span class=\"error\">%s</span>", a )
     local e = mw.html.create( "span" )
                    :addClass( "error" )
                    :wikitext( a )
    return tostring( e )
end -- fault()
end -- fault()


Zeile 327: Zeile 383:
                         n    = min + m
                         n    = min + m
                     else    -- dom
                     else    -- dom
                         if adjust.month and adjust.year and  n > 1 and
                         if adjust.month and adjust.year  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 n > 0 then
                            if adjust.month == 2  and
                                max = Calc.final( adjust )
                              ( adjust.year % 4 ~= 0  or
                                while n > max do
                                adjust.year % 400 == 0 ) then
                                    n = n - max
                                 max = 28
                                    if adjust.month < 12 then
                             end
                                        adjust.month = adjust.month + 1
                            if n <= max then
                                    else
                                max = false
                                        adjust.month = 1
                                        adjust.year = adjust.year + 1
                                    end
                                    max = Calc.final( adjust )
                                 end    -- while n <= max
                             else
                                while n < 1 do
                                    if adjust.month == 1 then
                                        adjust.month = 12
                                        adjust.year  = adjust.year - 1
                                    else
                                        adjust.month = adjust.month - 1
                                    end
                                    max = Calc.final( adjust )
                                    n  = n + max
                                end    -- while n < 1
                             end
                             end
                        end
                        if max then
                            m    = n % 30
                            move = ( n - m )  /  30
                            n    = 1 + m
                         end
                         end
                     end
                     end
 
                end
                    end
                 adjust[ s ] = n
                 adjust[ s ] = n
             end
             end
Zeile 354: Zeile 419:
     end -- for i
     end -- for i
end -- Calc.fair()
end -- Calc.fair()
Calc.final = function ( adjust )
    -- Retrieve number of days in particular month
    -- Parameter:
    --    adjust  -- table, with date specification
    -- Returns:
    --    number, of days in month
    local r = Calc.months[ adjust.month ]
    if adjust.month == 2  and
      ( adjust.year % 4 ~= 0  or
        adjust.year % 400 == 0 ) then
        r = 28
    end
    return r
end -- Calc.final()




Zeile 444: Zeile 526:
         if amount <= 4 then
         if amount <= 4 then
             r.year = tonumber( analyse )
             r.year = tonumber( analyse )
         elseif n == 14 then
         elseif amount == 14 then
             -- timestamp
             -- timestamp
             r.year  = tonumber( analyse:sub(  1, 4 ) )
             r.year  = tonumber( analyse:sub(  1, 4 ) )
             r.month  = tonumber( analyse:sub(  5, 2 ) )
             r.month  = tonumber( analyse:sub(  5, 6 ) )
             r.dom    = tonumber( analyse:sub(  7, 2 ) )
             r.dom    = tonumber( analyse:sub(  7, 8 ) )
             r.hour  = tonumber( analyse:sub(  9, 2 ) )
             r.hour  = tonumber( analyse:sub(  9, 10 ) )
             r.min    = tonumber( analyse:sub( 11, 2 ) )
             r.min    = tonumber( analyse:sub( 11, 12 ) )
             r.sec    = tonumber( analyse:sub( 13, 2 ) )
             r.sec    = tonumber( analyse:sub( 13, 14 ) )
         else
         else
             r = false
             r = false
Zeile 746: Zeile 828:
                         n = #s2
                         n = #s2
                         if n <= 2  and  #s3 == 4 then
                         if n <= 2  and  #s3 == 4 then
                             rO.dom  = tonumber( n )
                             rO.dom  = tonumber( s2 )
                             rO.year = tonumber( s3 )
                             rO.year = tonumber( s3 )
                             rO.dom2 = ( n == 2 )
                             rO.dom2 = ( n == 2 )
Zeile 1.161: Zeile 1.243:
     --    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      -- string, with interval (PHP strtotime), or nil
     --    add      -- table, with interval, or nil
     -- Returns:
     -- Returns:
     --    table, if parsed
     --    table, if parsed
Zeile 1.168: Zeile 1.250:
     local r
     local r
     if type( analyse ) == "string" then
     if type( analyse ) == "string" then
        local strip = mw.ustring.char( 0x5B, 0x200E, 0x200F, 0x5D )
         r =  analyse:gsub( "&nbsp;", " " )
         r =  analyse:gsub( "&nbsp;", " " )
                     :gsub( "&#160;", " " )
                     :gsub( "&#160;", " " )
Zeile 1.177: Zeile 1.260:
                     :gsub( "%[%[", "" )
                     :gsub( "%[%[", "" )
                     :gsub( "%]%]", "" )
                     :gsub( "%]%]", "" )
                    :gsub( strip, "" )
         r = mw.text.trim( r )
         r = mw.text.trim( r )
         if r == "" then
         if r == "" then
             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.190: Zeile 1.279:
                 end
                 end
             end
             end
             slang = slang:lower()
             slang   = slang:lower()
             if slang == "en" or slang == "de" then
             suitable = parser[ slang ]
            if suitable then
                 local l
                 local l
                 l, r = pcall( Parser.GermanEnglish, r )
                 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.200: Zeile 1.290:
                         r = Prototypes.future( r, add )
                         r = Prototypes.future( r, add )
                     end
                     end
                else
                    r = "invalid format"
                 end
                 end
             else
             else
                 r = "unknown language"
                 r = "unknown language: " .. slang
             end
             end
         end
         end
Zeile 1.268: Zeile 1.360:
     -- Retrieve localization submodule
     -- Retrieve localization submodule
     if not Meta.localized then
     if not Meta.localized then
         local l, d = pcall( mw.loadData, "Module:DateTime/local" )
         local d = foreignModule( DateTime.suite,
         if l then
                                false,
                                "local",
                                DateTime.item )
         if type( d ) == "table" then
             local wk
             local wk
             if d.slang then
             if d.slang then
Zeile 1.281: Zeile 1.376:
                     for subk, subv in pairs( v ) do
                     for subk, subv in pairs( v ) do
                         wk[ subk ] = subv
                         wk[ subk ] = subv
                     end -- for k, v%s %s
                     end -- for k, v
                 else
                 else
                     World[ k ] = v
                     World[ k ] = v
Zeile 1.324: Zeile 1.419:
     --    add  -- string or number, to be added
     --    add  -- string or number, to be added
     -- Returns:
     -- Returns:
     --    string, with shift, or false/nil
     --    table, with shift, or false/nil
     local r
     local r
     if add then
     if add then
Zeile 1.331: Zeile 1.426:
             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.338: Zeile 1.431:
                 r = false
                 r = false
             else
             else
                 r = string.format( "%d second", r )
                 r = string.format( "%d second", r or add )
             end
             end
         elseif s ~= "string" then
         elseif s == "string" then
            r = add
        else
             r = false
             r = false
         end
         end
Zeile 1.362: Zeile 1.457:
     return r
     return r
end -- Prototypes.clone()
end -- Prototypes.clone()
Prototypes.failsafe = function ( self, atleast )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    atleast  -- string, with required version or "wikidata" or "~"
    --                or false
    -- Postcondition:
    --    Returns  string  -- with queried version, also if problem
    --              false  -- if appropriate
    local last  = ( atleast == "~" )
    local since = atleast
    local r
    if last  or  since == "wikidata" then
        local item = Meta.item
        since = false
        if type( item ) == "number"  and  item > 0 then
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
                                                                item ) )
            if type( entity ) == "table" then
                local seek = Failsafe.serialProperty or "P348"
                local vsn  = entity:formatPropertyValues( seek )
                if type( vsn ) == "table"  and
                  type( vsn.value ) == "string"  and
                  vsn.value ~= "" then
                    if last  and
                      vsn.value == ( Meta.serial or DateTime.serial ) then
                        r = false
                    else
                        r = vsn.value
                    end
                end
            end
        end
    end
    if type( r ) == "nil" then
        if not since  or  since <= Meta.serial then
            r = Meta.serial
        else
            r = false
        end
    end
    return r
end -- Prototypes.failsafe()




Zeile 1.440: Zeile 1.580:
                                 end
                                 end
                                 if d == 29  and  m == 2  and  y then
                                 if d == 29  and  m == 2  and  y then
                                     if y % 4 ~= 0 or  y % 400 == 0 then
                                     if y % 4 ~= 0   or
                                      ( y % 100 == 0 and
                                        y % 400 ~= 0 ) then
                                         ret = false
                                         ret = false
                                     end
                                     end
Zeile 1.580: Zeile 1.722:
     return r
     return r
end -- Prototypes.first()
end -- Prototypes.first()
Prototypes.fix = function ( self )
    -- Adapt this object to local time if no explicit zone given
    -- Parameter:
    --    self  -- table, with numbers etc.
    if type( self ) == "table"  and
      not self.zone then
        local seconds = Prototypes.format( self, "Z" )
        Prototypes.future( self,  - tonumber( seconds ) )
    end
end -- Prototypes.fix()




Zeile 1.657: Zeile 1.812:
     local r = false
     local r = false
     if type( self ) == "table" then
     if type( self ) == "table" then
         local opts  = { lang = self.lang }
        local slang = self.lang or "en"
         local babel, slang
         local opts  = { lang = 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.669: Zeile 1.825:
                 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:lower() )
         if babel then
         if babel then
             local shift, show, stamp, suffix, limit4, locally
             local shift, show, stamp, suffix, limit4, locally
Zeile 1.684: Zeile 1.839:
                     stamp = string.format( "%d %s", self.dom, stamp )
                     stamp = string.format( "%d %s", self.dom, stamp )
                 end
                 end
                 if ask and ask:find( "Mon4" ) then
                 if ask and ask:find( "Mon4", 1, true ) then
                     local mon4 = World.months4[ opts.lang ]
                     local mon4 = World.months4[ opts.lang:lower() ]
                     if mon4 then
                     if mon4 and  mon4[ self.month ] then
                        if mon4[ self.month ] then
                        limit4 = true
                            limit4 = true
                        end
                     end
                     end
                 end
                 end
Zeile 1.696: Zeile 1.849:
             end
             end
             if self.hour then
             if self.hour then
                 stamp = string.format( "%s %02d:", stamp, self.hour )
                if stamp then
                    stamp = stamp .. " "
                else
                    stamp = ""
                end
                 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.736: Zeile 1.894:
             if self.month then
             if self.month then
                 local bucket, m, suite, x
                 local bucket, m, suite, x
                 if show:find( "F" ) then
                 if show:find( "F", 1, true ) then
                     suite = "monthsLong"
                     suite = "monthsLong"
                 elseif show:find( "M" ) then
                 elseif show:find( "M", 1, true ) 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:lower() ]
                     if slang then
                     if slang then
                         x = bucket[ slang ]
                         x = bucket[ slang:lower() ]
                     end
                     end
                     if m then
                     if m then
Zeile 1.825: Zeile 1.983:
     end
     end
     if r then
     if r then
         raw = r[ Meta.signature ]
         if r[ Meta.signature ] then
         rel = Private.future( shift )
            raw = r[ Meta.signature ]
         else
            raw = r
        end
        if type( shift ) == "table" then
            rel = shift
        else
            rel = Private.future( shift )
        end
     end
     end
     if raw and rel then
     if raw and rel then
Zeile 1.850: Zeile 2.016:
     -- Returns:
     -- Returns:
     --    string
     --    string
     local dels = { false, "", "-", "-", "", ":", ":", ".", "", "" }
     local dels = { false, "", "-", "-", "", "", ":", ":", ".", "" }
     local wids = { false, 4,  2,  2,  2,  2,   2,  2,  3,  3  }
     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 1.862: Zeile 2.028:
                   end
                   end
               end -- f()
               end -- f()
     for i = 2, 4 do
     for i = 2, 5 do
         f( i )
         f( i )
     end -- for i
     end -- for i
     r = s
     r = s
     s = ""
     s = ""
     for i = 5, 10 do
     for i = 6, 10 do
         f( i )
         f( i )
     end -- for i
     end -- for i
Zeile 1.879: Zeile 2.045:
         end
         end
     end
     end
    r = r:gsub( "%.$", "" )
     return r
     return r
end -- Prototypes.tostring()
end -- Prototypes.tostring()
Zeile 1.948: Zeile 2.115:
     if not ask  or  ask == "" then
     if not ask  or  ask == "" then
         r1 = "c"
         r1 = "c"
    elseif ask == "*" then
        if World.present then
            if assigned.hour then
                if assigned.dom or assigned.month or assigned.year then
                    if World.present.both and
                      World.present.date and
                      World.present.time then
                        r1 = World.present.both
                                    :gsub( "$date", World.present.date )
                                    :gsub( "$time", World.present.time )
                    else
                        r1 = World.present.date
                    end
                end
                r1 = r1 or World.present.time
            else
                r1 = World.present.date
            end
        end
        r1 = r1 or "c"
     else
     else
         local template = World.templates[ ask ]
         local template = World.templates[ ask ]
Zeile 1.956: Zeile 2.143:
             if tmp then
             if tmp then
                 template = tmp[ ask ]
                 template = tmp[ ask ]
            end
            if not template then
                local i = slang:find( "-", 3, true )
                if i then
                    slang = slang:sub( 1,  i - 1 ):lower()
                    tmp  = World.templates[ slang ]
                    if tmp then
                        template = tmp[ ask ]
                    end
                end
             end
             end
         end
         end
Zeile 1.977: Zeile 2.174:
             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)
                not ( assigned.month or assigned.year or assigned.bc )
               ) then
               ) then
                 local stamp = false
                 local stamp = false
Zeile 2.001: Zeile 2.198:
                     end
                     end
                 end
                 end
                 if low or ask:find( "hh:mm:ss" ) then
                 if low or ask:find( "hh:mm:ss", 1, true ) then
                     if stamp then
                     if stamp then
                         r1 = string.format( "%s %s", r1, stamp )
                         r1 = string.format( "%s %s", r1, stamp )
Zeile 2.057: Zeile 2.254:
             if #s == 1 then
             if #s == 1 then
                 -- "YXWVUTSRQPONZABCDEFGHIKLM"
                 -- "YXWVUTSRQPONZABCDEFGHIKLM"
                 move = World.zones[ "!" ]:find( s )
                 move = World.zones[ "!" ]:find( s, 1, true )
                 if move then
                 if move then
                     move          = ( move - 13 ) * 100
                     move          = ( move - 13 ) * 100
Zeile 2.072: Zeile 2.269:
                   if tmp then
                   if tmp then
                       code = tmp[ s ]
                       code = tmp[ s ]
                  end
                  if not code  and
                      slang ~= "en"  and
                      World.zones.en then
                      code = World.zones.en[ s ]
                   end
                   end
                 end
                 end
Zeile 2.129: Zeile 2.331:


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
Zeile 2.145: Zeile 2.347:
         r = ( args.noerror or "0" )
         r = ( args.noerror or "0" )
         if r == "0" then
         if r == "0" then
             r = fault( "Format nicht erkannt" )
             r = fault( "Format invalid" )
         else
         else
             r = ""
             r = ""
Zeile 2.161: Zeile 2.363:
         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.169: Zeile 2.368:
         end
         end
     end
     end
     if since then
     return Prototypes.failsafe( false, since )  or  ""
        if since > Meta.serial then
            r = ""
        else
            r = Meta.serial
        end
    else
        r = Meta.serial
    end
    return r
end -- p.failsafe
end -- p.failsafe