Modul:Date

De la Wikipedia, enciclopedia liberă
Jump to navigation Jump to search

Implementează {{Dată}}.


local DateUtils = require('Modul:DateUtils')
local GregorianDate = require('Modul:GregorianDate')
local julianCutoffDate = require('Modul:GregorianDate/data').julianDateOfGregorianStart
local getArgs = require('Modul:Arguments').getArgs
local months = mw.loadData('Modul:DateUtils/data').months
local p = {}

p.formatDateFromFrame = function(frame)
	local args = getArgs(frame)
	local dateObj = {}
	if args[1] then
		dateObj = DateUtils.parseDate(args[1])
	end
	if args[2] then
		dateObj.month = tonumber(months[args[2]] or args[2])
		if args[3] then dateObj.day = tonumber(args[3]) end
	end
	dateObj.calendar = args.calendar or DateUtils.compare(dateObj, julianCutoffDate) < 0 and 'julian' or 'gregorian'
	if not dateObj.precision then
		dateObj.precision = 9
	end
	
	local link = args['link']
	if args['link'] == 'yes' or args['link'] == 'y' then
		link = 'both'
	end
	
	if args[2] ~= nil then
		dateObj.precision = 10
		if args[3] ~= nil then
			dateObj.precision = 11
		end
	end
	return GregorianDate.displayDualDateIfInInterval(dateObj, link, args['format'] or args['date_format'] or args['dateFormat'])
end

return p