-- this module implements local p =
p.ShowTemplate = function(frame) local showtemp = frame.args[1]:upper local namespace = frame.args[2]:upper local forcedips = frame.args[3]:upper if showtemp
"YES" then return true elseif forcedisp
"YES" then return true elseif namespace
p.ShowDate = function(frame) local Year = "" local Month = "" local Day = "" local Hour = "" local Minute = "" if frame.args[3]
"" then return "in " .. Year else Month = p.MonthName(frame.args[2]) end if frame.args[1]
if frame.args[4]
"" then lTime = "" else Hour = p.pad(frame.args[4]) Minute = p.pad(frame.args[5])
LTime = Hour .. ":" .. Minute .. " UTC on " ConvTime = p.ConvertTime(frame) end local dateformat = frame.args[6]:lower --Display the date in the specified format local dString = "" local atLine = "" if LTime
"mdy" then dString = atLine .. " " .. LTime .. Month .. " " .. Day .. ", " .. Year .. ConvTime else dString = atLine .. " " .. LTime .. Day .. " " .. Month .. " " .. Year .. ConvTime end
return dString --test end p.GetOffset = function(frame) local DateNow = os.time local DateThen = p.GetDate(frame) return os.difftime(DateNow, DateThen) end p.IsPassed = function(frame) local Offset = p.GetOffset(frame) if Offset > 0 then return true else return false end end
p.TimeToLaunch = function(frame) if frame.args[1]
"" then return "in the near future" else local Offset = p.GetOffset(frame) local Min = -60 local Hour = Min * 60 local Day = Hour * 24 local Week = Day * 7 local FN = Day * 14 --Fortnight local oMins = tostring(math.ceil(Offset/Min)) local oHours = tostring(math.ceil(Offset/Hour)) local oDays = tostring(math.ceil(Offset/Day)) local oWeeks = tostring(math.ceil(Offset/Week)) if Offset > 0 then return "imminently or may already be in progress" elseif Offset > Min then return "in the next minute" elseif Offset > Hour then return "in the next " .. oMins .. " minutes" elseif Offset > Day then return "in the next " .. oHours .. " hours" elseif Offset > FN then return "in the next " .. oDays .. " days" else return "in the next " .. oWeeks .. " weeks" end end end p.GetDate = function(frame) local Year = 0 local Month = 0 local Day = 0 local Hour = 0 local Minute = 0 if frame.args[3]
"" then Month = 1 Year = Year+1 --assume start of next year else Month = tonumber(frame.args[2]) end local mLen = p.MonthLength(Month, Year) if frame.args[3]
"" then Hour = 0 Minute = 0 Day = Day + 1 --use end of day, 23:59:59.99... ~ 00:00 else Hour = tonumber(frame.args[4]) Minute = tonumber(frame.args[5]) end if Day > mLen then Month = Month+1 Day = 1 end if Month > 12 then Year = Year+1 Month = 1 end local d = os.time return d end p.MonthName = function(IMonth) --Strip leading zeros local I = p.trim(IMonth) --For some reason lua has not switch/select case statement if I
"2" then return "February" elseif I
"4" then return "April" elseif I
"6" then return "June" elseif I
"8" then return "August" elseif I
"10" then return "October" elseif I
"12" then return "December" else return IMonth end end p.MonthLength = function(I, IYear) --Returns number of days in a month local FebLen = 28 if p.IsLeap(IYear) then FebLen = 29 end --For some reason lua has not switch/select case statement if I
2 then return FebLen elseif I
4 then return 30 elseif I
6 then return 30 elseif I
8 then return 31 elseif I
10 then return 31 elseif I
12 then return 31 else return 31 end end
p.IsLeap = function(iYear) --Determines whether a year is a leap year or not if math.fmod(iYear,400)
0 then return false elseif math.fmod(iYear, 4)
p.trim = function(s) --Removes leading zeroes from value if s:sub(1,1)
p.pad = function(s) local sLen = string.len(s) if sLen
"UTC" then return "UTC" elseif t
"YAKT" then return "Yakutsk Time" --Vostochny elseif t
"KST" then return "KST" --Tonghae, Sohae, Naro elseif t
"AAST" then return "Almaty Time" --Baikonur elseif t
"YEKT" then return "Yekaterinburg Time" --Dombarovsky elseif t
"IRST" then return "IRST" --Semnan (Standard) elseif t
"ISDT" then return "IDT" --Palmachim (DST) elseif t
"GFT" then return "GFT" --Kourou elseif t
"EDT" then return "EDT" --Canaveral, Wallops/MARS (DST) elseif t
"PDT" then return "PDT" --Vandenberg (DST) elseif t
"AKDT" then return "AKDT" --Kodiak (DST) elseif t
"HADT" then return "AKDT" --Barking Sands (DST) elseif t
"SL" then return "UTC-10" --Sea Launch else return TimeZone end end
p.bigoffset = function(TimeZone) local t = TimeZone:upper if t
"MHT" then return 12 --Kwajelein elseif t
"JST" then return 9 --Uchinoura, Tanegashima elseif t
"CST" then return 8 --Jiuquan, Taiyuan, Xichang elseif t
"IST" then return 5 --India elseif t
"IRDT" then return 4 --Semnan (DST) elseif t
"MSK" then return 3 --Plesetsk elseif t
"ISST" then return 2 --Palmachim (Standard) elseif t
"BRT" then return -3 --Alcantara elseif t
"EST" then return -5 --Canaveral, Wallops/MARS (Standard) elseif t
"PST" then return -8 --Vandenberg (Standard) elseif t
"AKST" then return -9 --Kodiak (Standard) elseif t
"HAST" then return -10 --Barking Sands (Standard) elseif t
p.littleoffset = function(TimeZone) local t = TimeZone:upper if t
"IST" then return 30 elseif t
"IRDT" then return 30 else return 0 end end
p.use12hc = function(TimeZone) --12 hour clock local t = TimeZone:upper if t
"MHT" then return true --Kwajalein elseif t
"EDT" then return true --Canaveral, Wallops/MARS (DST) elseif t
"PDT" then return true --Vandenberg elseif t
"AKDT" then return true --Kodiak elseif t
"HADT" then return true --Barking Sands elseif t
p.ConvertTime = function(frame) local TimeZone = frame.args[7] local oLa = p.bigoffset(TimeZone) local oSm = p.littleoffset(TimeZone) local TName = p.zonename(TimeZone) local Use12HC = p.use12hc(TimeZone) if oLa
0 then return "" else local Year = tonumber(frame.args[3]) --Get value of year local Month = tonumber(frame.args[2]) --Get value of month local Day = tonumber(frame.args[1]) --Get value of day local Hour = tonumber(frame.args[4]) --Get value of hour local Minute = tonumber(frame.args[5]) --Get value of minute local lMin = Minute + oSm local lHour = Hour + oLa local lDay = Day local lMonth = Month if lMin < 0 then lMin = lMin + 60 lHour = lHour - 1 elseif lMin > 59 then lMin = lMin - 60 lHour = lHour + 1 end if lHour < 0 then lHour = lHour + 24 lDay = lDay - 1 elseif lHour > 23 then lHour = lHour - 24 lDay = lDay + 1 end local ThisMonthLength = p.MonthLength(lMonth, Year) local LastMonthLength = 0 if lMonth
if lDay < 1 then lDay = LastMonthLength lMonth = lMonth - 1 elseif lDay > ThisMonthLength then lDay = 1 lMonth = lMonth + 1 end if lMonth < 1 then lMonth = 12 elseif lMonth > 12 then lMonth = 1 end local DayOffset = "" if lDay ~= Day then MyMonth = p.MonthName(tostring(lMonth))
local dateformat = frame.args[6]:lower if dateformat
12 then ap = " p.m." elseif lHour
return p