FANDOM


-- <pre>
local p = {}
 
function div(x,y) return math.floor(x/y) end
 
function p.main(frame)
    local args = frame:getParent().args
    local paramday = args[1]
    local parammonth = args[2]
    local paramyear = args[3]
 
    local ret = ""
    local now
 
    if (paramday ~= nil and parammonth ~= nil and paramyear ~= nil) then
        paramtime = os.time({year=paramyear, month=parammonth, day=paramday})
        now = os.date("*t",paramtime)
    else
        now = os.date("*t")
    end
 
    --wow, easter is a bitch
    local eastermonth, easterday = easter(now.year)
    local eastertime = os.time({year=now.year, month=eastermonth, day=easterday})
    local easterdate = os.date("*t", eastertime)
    local easteryday = easterdate.yday
 
    --seasons
    if (between(now,80,172)) then ret = "spring"
    elseif (between(now,172,264)) then ret = "summer"
    elseif (between(now,264,355)) then ret = "autumn"
    else ret = "winter"
    end
 
    --holidays and the likes
    if (on(now,4)) then ret = "rsbirth" end
    if (on(now,easteryday) or on(now,easteryday+1)) then ret = "easter" end
    if (on(now,185)) then ret = "fourjuly" end
    if (on(now,211)) then ret = "birth" end
    if (on(now,284)) then ret = "halloween" end
    if (on(now,285) or on(now,286)) then ret = "muertos" end
    if (on(now,nth_weekday("Thursday",11,now.year,4))) then ret = "thxgibe" end
    if (on(now,358) or on(now,359)) then ret = "christmas" end
    if (on(now,360)) then ret = "boxing" end
    if (on(now,365) or on(now,1)) then ret = "newyear" end
 
    return frame:preprocess("{{Signatures/ThePsionic/" .. ret .. "}}")
end
 
function leap(year)
    if (year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)) then return 1 else return 0 end
end
 
function between(now, one, two)
    if (now.yday < 60) then return now.yday >= one and now.yday < two
    else return now.yday >= one + leap(now.year) and now.yday < two + leap(now.year)
    end
end
 
function on(now, target)
    if (now.yday < 60) then return now.yday == target
    else return now.yday == target + leap(now.year)
    end
end
 
function nth_weekday(weekday, month, year, n)
    local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
    if (leap(year) == 1) then days_in_month[2] = 29 end
 
    local daycount = 0
    local day = 0
    while (daycount < n and day < days_in_month[month]) do
        day = day + 1
        local t = os.time({year=year,month=month,day=day})
        if (os.date("%A", t) == weekday) then daycount = daycount + 1 end
    end
    local leapnr
    if os.date("*t", os.time({year=year,month=month,day=day})).yday < 60 then leapnr = 0 else leapnr = leap(year) end
    return os.date("*t", os.time({year=year,month=month,day=day})).yday - leapnr
end
 
function easter (year)
    local G = year % 19
    local C = div(year, 100)
    local H = (C - div(C, 4) - div((8 * C + 13), 25) + 19 * G + 15) % 30
    local I = H - div(H, 28) * (1 - div(29, H + 1)) * (div(21 - G, 11))
    local J = (year + div(year, 4) + I + 2 - C + div(C, 4)) % 7
    local L = I - J
    local month = 3 + div(L + 40, 44)
    return month, L + 28 - 31 * div(month, 4)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.