Module:TimeGreeting: Difference between revisions

From Empire of Dragons
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:


function p.getGreeting()
function p.getGreeting()
     local now = mw.getCurrentFrame():callParserFunction("#time", "U", "1")
     -- Use local time (server's time zone)
    local now = mw.getCurrentFrame():callParserFunction("#time", "Y-m-d H:i:s")
 
    -- Alternatively, use UTC+1
    -- local now = mw.getCurrentFrame():callParserFunction("#time", "Y-m-d H:i:s", "1")
 
     local hours = tonumber(now:match("(%d%d)"))
     local hours = tonumber(now:match("(%d%d)"))


     if hours >= 6 and hours < 12 then
     if hours then
        return "Good morning"
        if hours >= 6 and hours < 12 then
    elseif hours >= 12 and hours < 18 then
            return "Good morning"
         return "Good afternoon"
        elseif hours >= 12 and hours < 18 then
            return "Good afternoon"
         else
            return "Good evening"
        end
     else
     else
         return "Good evening"
         return "Error: Unable to determine the time"
     end
     end
end
end

Revision as of 09:11, 19 January 2024

Good evening


-- Module:TimeGreeting

local p = {}

function p.getGreeting()
    -- Use local time (server's time zone)
    local now = mw.getCurrentFrame():callParserFunction("#time", "Y-m-d H:i:s")

    -- Alternatively, use UTC+1
    -- local now = mw.getCurrentFrame():callParserFunction("#time", "Y-m-d H:i:s", "1")

    local hours = tonumber(now:match("(%d%d)"))

    if hours then
        if hours >= 6 and hours < 12 then
            return "Good morning"
        elseif hours >= 12 and hours < 18 then
            return "Good afternoon"
        else
            return "Good evening"
        end
    else
        return "Error: Unable to determine the time"
    end
end

function p.displayGreeting(frame)
    return p.getGreeting()
end

return p