Sari la conținut

Modul:DateUtils

De la Wikipedia, enciclopedia liberă
(dif) ← Versiunea anterioară | afișează versiunea curentă (dif) | Versiunea următoare → (dif)
local p = {}

local suffixFormatYear = function(y)
	return (y < 0 and ' î.e.n.' or (y < 1000 and ' e.n.' or ''))
end

p.formatYear = function(y, link)
	local out = ''
	if link then out = out .. '[[' end
	out = out .. tostring(math.abs(y))
	if y > 0 and link then out = out .. ']]' end
	out = out .. suffixFormatYear(y)
	if y < 0 and link then out = out .. ']]' end
	return out
end

p.formatDate = function(indate, link)
	if indate.precision == 7 then
		return 'secolul ' .. tostring(math.floor(1 + math.abs(indate.year) / 100)) .. suffixFormatYear(indate.year)
	end
	if indate.precision == 8 then
		return 'anii ' .. tostring(math.floor(math.abs(indate.year) / 10) * 10) .. suffixFormatYear(indate.year)
	end
	if indate.precision == 9 then
		return formatYear(indate.year)
	end
	if indate.precision > 9  then
		local d1 = {}
		d1.day = indate.day
		d1.month = indate.month
		d1.year = math.abs(indate.year)
		local out = ''
		out = out ..mw.language.getContentLanguage():formatDate((indate.precision >= 11) and (link and '[[j F]]' or 'j F') or 'F', os.date('%d %B %Y', os.time(d1)))
		out = out .. ' ' .. formatYear(indate.year, link)
		return out
	end
end

p.isDateGregorian = function(indate)
	return indate.calendarmodel == 'http://www.wikidata.org/entity/Q1985727' or indate.calendar == 'gregorian'
end

p.isDateJulian = function(indate)
	return indate.calendarmodel == 'http://www.wikidata.org/wiki/Q1985786' or indate.calendar == 'julian'
end

p.isLeapYearGregorian = function(year)
	if (year % 4 ~= 0) then return false
	elseif (year % 100 ~= 0) then return true
	elseif (year % 400 ~= 0) then return false
	end
	return true
end

p.isDateInLeapYear = function(indate)
	if indate.isDateJulian(indate) then
		return 0 == indate.year % 4
	end
	return p.isLeapYearGregorian(indate.year)
end

return p