On Friday, April 19, 2024 at 10:00 PM New York time, all OpenWiki Project sites will be undergoing scheduled maintenance for about 2 hours. Expect read-only access and brief periods of downtime.

Module:GhbRotation

From Fire Emblem Wiki, your source on Fire Emblem information. By fans, for fans.

For use on Grand Hero Battle and possibly other locations later on. This module can be used to output Grand Hero Battle data, including the first rerun date, the next rerun date, total number of reruns, and the current active Grand Hero Battle.

The only function, main, takes three parameters, each of them corresponding to a year, a month number, and a day of a month, where the full date represents the first rerun date of a Grand Hero Battle.

{{#invoke:GhbRotation|main|2018|02|10}}

This outputs:

In rotation since February 10, 2018
Rerun in rotation 323 times to date
Next rerun: April 20, 2024


local p = {}

function p.main(frame)
	args = frame.args
	date_begin = os.time({year=args[1], month=args[2], day=args[3], hour=7})
    next_rerun_days_away = 7 - math.floor(os.difftime( os.time(), date_begin ) / (24*60*60)) % 7

	-- Subtracting seven hours to calibrate daily reset time (07:00 UTC)
    next_rerun = os.date("%B %e, %Y", math.max(os.time()-7*60*60+(24*60*60*next_rerun_days_away), date_begin))
    
    rotation_since = os.date("%B %e, %Y", date_begin)

	-- Using ceiling function to account currently running GHB
    total_reruns = math.max(0, math.ceil(os.difftime( os.time(), date_begin ) / (24*60*60)/7))

    if ( next_rerun_days_away == 7 and os.time() >= date_begin ) then
        is_active = "<b>Currently available</b><br/>"
    else
        is_active = ""
    end

    return string.format("In rotation since %s<br/>Rerun in rotation %s times to date<br/>%sNext rerun: %s",
    	rotation_since, total_reruns, is_active, next_rerun)
end

return p