Jump to content

Module:TFA title

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Legoktm (talk | contribs) at 07:48, 28 December 2022 (new module, for Template:TFA title eventually). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local data = mw.loadJsonData("Template:TFA title/data.json")

-- Get the TFA title for the specified "YYYY-MM-DD" date. May be
-- a single title, an array of multiple titles, or nil, if no title is known
function p.title(date)
	return data.titles[date] or nil
end

-- Today's TFA, see title() for possible return values
function p.today_title()
	return p.title(today())
end

-- Is the specified title today's TFA
function p.is_todays_tfa(title)
	local today = p.today_title()
	if today == nil then
		-- no clue
		return false
	end
	if type(today) == "string" then
		return title == today
	end
	
	-- table case, multiple titles
	for _, check in pairs( today ) do
		if check == title then
			return true
		end
	end
	return false
end

-- Internal, today's date as YYYY-MM-DD
function today()
	return os.date("%Y-%m-%d")
end


return p