Jump to content

Module:Date period

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chlod (talk | contribs) at 14:44, 19 February 2021 (Create module). 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 Date = require('Module:Date')._Date
local yesno = require('Module:Yesno')

local p = {}

function p.main(frame)
	return p._main(frame.args)
end

function p._main(args)
	local dateA = Date(args[1])
	local dateB = Date(args[2])
	
	local disableYear = args['no-year'] and yesno(args['no-year']) or dateA.year == dateB.year
	
	if dateA.year == dateB.year then
		if dateA.month == dateB.month and dateA.day == dateB.day then
			return dateA:text("%B %-d")
		elseif dateA.month == dateB.month then
			return dateA:text("%B %-d") .. " – " .. dateB.day .. (disableYear and "" or ", " .. dateA.year)
		else
			return dateA:text("%B %-d") .. " – " .. dateB:text("%B %-d") .. (disableYear and "" or ", " .. dateA.year)
		end
	else
		return dateA:text("%B %-d, %-Y") .. " – " .. dateB:text("%B %-d, %-Y")
	end
	
end

return p