Module:TimeGreeting: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
local hours = tonumber(now:match("(%d%d)")) | local hours = tonumber(now:match("(%d%d)")) | ||
local greeting | |||
if hours then | if hours then | ||
-- Adjust for local time zone | -- Adjust for local time zone | ||
hours = hours + offsetHours | hours = hours + offsetHours | ||
greeting = "It is " .. hours | |||
if hours >= 6 and hours < 12 then | if hours >= 6 and hours < 12 then | ||
greeting = "It is " .. hours .. "Good morning" | |||
elseif hours >= 12 and hours < 18 then | elseif hours >= 12 and hours < 18 then | ||
greeting = "It is " .. hours .. "Good afternoon" | |||
else | else | ||
greeting = "It is " .. hours .. "Good evening" | |||
end | end | ||
return greeting | |||
else | else | ||
return "Error: Unable to determine the time" | return "Error: Unable to determine the time" |
Revision as of 09:44, 19 January 2024
It is 8Good morning
-- 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") local offsetHours = -12 local hours = tonumber(now:match("(%d%d)")) local greeting if hours then -- Adjust for local time zone hours = hours + offsetHours greeting = "It is " .. hours if hours >= 6 and hours < 12 then greeting = "It is " .. hours .. "Good morning" elseif hours >= 12 and hours < 18 then greeting = "It is " .. hours .. "Good afternoon" else greeting = "It is " .. hours .. "Good evening" end return greeting else return "Error: Unable to determine the time" end end function p.displayGreeting(frame) return p.getGreeting() end return p