Marvel Wiki
Advertisement

La documentación para este módulo puede ser creada en Módulo:Semana/doc

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	
	if args.week and args.year then
		args.referenceDate = p.getDateFromWeek(args.week, args.year)
	end
	
	return p.getDayOfWeekDate( args.dayIndex, args.weeksDifference, args.referenceDate )
end

function p.getDateFromWeek(week, year)
	local frame = mw.getCurrentFrame()
	local week = tostring(week - 1)
	local year = tostring(year)
	return frame:callParserFunction{ name = '#time', args = { 'Y-m-d', year .. '-01-01 + ' .. week .. ' weeks' } }
end

function p.getDayOfWeekDate(dayIndex, weeksDifference, referenceDate)
	local frame = mw.getCurrentFrame()
	local dayIndex = dayIndex or 3 -- default to wednesday
	local weeksDifference = weeksDifference or '+0'
	local referenceDate = referenceDate or frame:callParserFunction{ name = '#time', args = { 'Y-m-d' } }
	
	local dayNumber = frame:callParserFunction{ name = '#time', args = { 'w', referenceDate } } -- Sunday = 0, Monday = 1, ..., Saturday = 6
	local daysDifference = dayIndex - dayNumber
	
	local sign = daysDifference < 0 and '-' or '+'
	local days = tostring( math.abs( daysDifference ) ) .. ' days'
	local weeks = weeksDifference .. ' weeks'
	local dayDate = frame:callParserFunction{ name = '#time', args = { 'F j, Y', referenceDate .. ' ' .. sign .. days .. ', ' .. weeks } }
	
	return dayDate
end

return p
Advertisement