Модуль:Вікізьвесткі/дата

Зьвесткі зь Вікіпэдыі — вольнай энцыкляпэдыі

Дакумэнтацыю да гэтага модуля можна стварыць у Модуль:Вікізьвесткі/дата/Дакумэнтацыя

--налады
local nowLabel = 'цяпер'

local moduleDates = require( "Модуль:Даты" )
local moduleWikidata = require( "Модуль:Вікізьвесткі" )
local dateCat = require("Модуль:Карткі/Катэгорыі для датаў")

local function deepcopy(orig)
	local orig_type = type(orig)
	local copy
	if orig_type == 'table' then
		copy = {}
		for orig_key, orig_value in next, orig, nil do
			copy[deepcopy(orig_key)] = deepcopy(orig_value)
		end
		setmetatable(copy, deepcopy(getmetatable(orig)))
	else -- лік, радок, булевы і да т. п.
		copy = orig
	end
	return copy
end

local function ageImpl ( bStructure, bPrecision, dStructure, dPrecision )
	if ( not bStructure or not dStructure or bPrecision < 10 or dPrecision < 10 ) then
		return nil
	end

	local shift = 0
	if ( bStructure.year < 0 and dStructure.year > 0 ) then
		shift = -1
	end

	if ( bPrecision == 10 or dPrecision == 10 ) then
		if ( bStructure.month < dStructure.month ) then
			return dStructure.year - bStructure.year + shift
		end
		if ( bStructure.month == dStructure.month ) then
			return nil
		end
		if ( bStructure.month > dStructure.month ) then
			return dStructure.year - bStructure.year - 1 + shift
		end
	end
 
	if ( bStructure.month < dStructure.month ) then
		return dStructure.year - bStructure.year + shift
	end
	if ( bStructure.month == dStructure.month ) then
		if ( bStructure.day <= dStructure.day ) then
			return dStructure.year - bStructure.year + shift
		else 
			return dStructure.year - bStructure.year - 1 + shift
		end
	end
	if ( bStructure.month > dStructure.month ) then
		return dStructure.year - bStructure.year - 1 + shift
	end

	return nil
end

-- прымае табліцу значэньняў часу+дакладнасьці
local function ageCurrent ( bTable )
	local possibleAge = "NYA" -- гэта азначае „Not Yet Assigned“, а ня тое, што вы падумалі!

	for bKey, bValue in pairs(bTable) do
		if ( bValue.unknown ) then
			return nil
		end
		local bStructure = bValue.structure
		local bPrecision = bValue.precision

		local dStructure = os.date( "*t" )

		local calculatedAge = ageImpl ( bStructure, bPrecision, dStructure, 11 )
		if ( possibleAge == "NYA" ) then
			possibleAge = calculatedAge
		else
			if ( possibleAge ~= calculatedAge ) then
				possibleAge = nil
			end
		end
	end

	return possibleAge
end

-- прымае табліцы значэньняў часу+дакладнасьці
local function age ( bTable, dTable )
	local possibleAge = "NYA" -- гэта азначае „Not Yet Assigned“, а ня тое, што вы падумалі!

	for bKey, bValue in pairs( bTable ) do
		if ( bValue.unknown ) then
			return nil
		end
		local bStructure = bValue.structure
		local bPrecision = bValue.precision

		for dKey, dValue in pairs( dTable ) do
			if ( dValue.unknown ) then
				return nil
			end
			local dStructure = dValue.structure
			local dPrecision = dValue.precision
			if ( bValue.calendar == 'julian' and dValue.calendar == 'gregorian' ) then
				-- каб вылічыць век, трэба дапасаваць bStructure да грыгарыянскага календара
				local shift = math.floor(bStructure.year/100-2) - math.floor(bStructure.year/400)
				-- TODO: re-implement this properly
				bStructure.day = bStructure.day + shift
			end

			local calculatedAge = ageImpl ( bStructure, bPrecision, dStructure, dPrecision )
			if ( possibleAge == "NYA" ) then
				possibleAge = calculatedAge
			else
				if ( possibleAge ~= calculatedAge ) then
					possibleAge = nil
				end
			end
		end
	end

	return possibleAge
end

local function parseISO8601Date(str)
	local pattern = "(%-?%d+)%-(%d+)%-(%d+)T"
	local Y, M, D = mw.ustring.match( str, pattern )
	return tonumber(Y), tonumber(M), tonumber(D)
end

local function parseISO8601Time(str)
	local pattern = "T(%d+):(%d+):(%d+)%Z"
	local H, M, S = mw.ustring.match( str, pattern)
	return tonumber(H), tonumber(M), tonumber(S)
end

local function parseISO8601Offset(str)
	if str:sub(-1)=="Z" then return 0,0 end -- ends with Z, Zulu time
 
	-- matches ±hh:mm, ±hhmm or ±hh; else returns nils 
	local pattern = "([-+])(%d%d):?(%d?%d?)$"
	local sign, oh, om = mw.ustring.match( str, pattern) 
	sign, oh, om = sign or "+", oh or "00", om or "00"
 
	return tonumber(sign .. oh), tonumber(sign .. om)
end

local function parseISO8601(str)
	if 'table' == type(str) then
		if str.args and str.args[1] then
			str = '' .. str.args[1]
		else
			return 'невядомы тып аргумэнту: ' .. type( str ) .. ': ' .. table.tostring( str )
		end
	end

	local Y,M,D = parseISO8601Date(str)
	local h,m,s = parseISO8601Time(str)
	local oh,om = parseISO8601Offset(str)

	if not Y or not M or not D or not h or not m or not s or not oh or not om then
		return nil
	end

	return tonumber(os.time({year=Y, month=M, day=D, hour=(h+oh), min=(m+om), sec=s}))
end

local function parseClaim ( claim )
	if ( claim.mainsnak.snaktype == "value" ) then
		local timeISO8601 = string.gsub( string.gsub( tostring( claim.mainsnak.datavalue.value.time ), '-00%-', '-01-' ), '-00T', '-01T' )
		local unixtime = parseISO8601( timeISO8601 )
		local structure = os.date("*t", unixtime)
		local precision = tonumber( claim.mainsnak.datavalue.value.precision )
		local calendarmodel = 'gregorian'
		if (mw.ustring.find(claim.mainsnak.datavalue.value.calendarmodel, 'Q1985786', 1, true)) then
			calendarmodel = 'julian'
		end
		local item = { structure=structure, precision=precision, calendar = calendarmodel }
		return item;
	elseif ( claim.mainsnak.snaktype == "novalue" ) then
		-- ня мае значэньня
		return { unknown="novalue" };
	else
		--невядома
		return { unknown="unknown" };
	end
end

-- вяртае табліцу значэньняў часу+дакладнасьці для вызначанай уласьцівасьці
local function parseProperty ( context, options, propertyId )
	if ( not context ) then error( 'кантэкст не зададзены'); end
	if ( not options ) then error( 'опцыі не зададзеныя'); end
	if ( not options.entity ) then error( 'адсутнічае options.entity'); end
	if ( not propertyId ) then error( 'propertyId не зададзены'); end

	local claims = context.selectClaims( options, propertyId )
	if not claims then
		return nil
	end

	local result = {}
	for key, claim in pairs( claims ) do
		table.insert ( result, parseClaim( claim ) )
	end
	return result
end

-- праверка на супадальныя даты з рознай мадэльлю календара
local function checkDupDates( t )
	if #t > 1 then
		local removed = false;
		local j = 1;
		-- праверка на супадальныя даты з рознай мадэльлю календара
		while (j <= #t)  do
			local i = 1;
			while (i <= #t)  do
				if i ~= j then
					if (os.time(t[j].structure) == os.time(t[i].structure)) then
						if ((t[j].calendarmodel == 'gregorian') and 
							(t[i].calendarmodel == 'julian')) then
							removed = true;
							break;
						else
							table.remove(t, i)
						end
					else
					  i = i + 1;
					end
				else
					i = i + 1;
				end
			end
			if removed then
				removed = false;
				table.remove(t, j);
			else
				j = j + 1;
			end
		end
	end
end

-- вяртае першы кваліфікатар пазначанай propertyId
local function getQualifierWithDataValue( statement, qualifierPropertyId )
	if ( statement.qualifiers
			and statement.qualifiers[qualifierPropertyId] ) then
		local qualifiers = statement.qualifiers[qualifierPropertyId]
		for _, qualifier in ipairs( qualifiers ) do
			if (qualifier.datavalue) then
				return qualifier;
			end
		end
	end
	return nil
end

local p = {}

local function formatDecade( time, categoryNamePrefix )
	if ( time.year < 0 ) then
		local year = math.floor( math.abs(time.year) / 10 ) * 10
		if ( categoryNamePrefix ) then
			return year .. '-я да н. э.[[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. year .. '-я гады да н. э.]]';
		else
			return '' .. year .. ' да н. э.';
		end
	else
		local year = math.floor( time.year / 10 ) * 10
		if ( categoryNamePrefix ) then
			return year .. '-е[[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. year .. '-я гады]]';
		else
			return '' .. year
		end
	end
end

local function formatCentury( time, categoryNamePrefix )
	local moduleRoman = require( 'Модуль:Рымскі лік' )
	if ( time.year < 0 ) then
		local century = math.floor( (math.abs( time.year) - 1) / 100 ) + 1
		if ( moduleRoman ) then
			century = moduleRoman.toRomanNumber( century )
		end
		if ( categoryNamePrefix ) then
			return '[[' .. century .. ' стагодзьдзе да н. э.]][[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. century .. ' стагодзьдзі да н. э.]]'
		else
			return '[[' .. century .. ' стагодзьдзе да н. э.]]'
		end
	else
		local century = math.floor( (time.year - 1) / 100 ) + 1
		if ( moduleRoman ) then
			century = moduleRoman.toRomanNumber( century )
		end
		if ( categoryNamePrefix ) then
			return '[[' .. century .. ' стагодзьдзе]][[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. century .. ' стагодзьдзі]]'
		else
			return '[[' .. century .. ' стагодзьдзе]]'
		end
	end
end

local function formatMillenium( time, categoryNamePrefix )
	local moduleRoman = require( 'Модуль:Рымскі лік' )
	if ( time.year < 0 ) then
		local millenium = math.floor( (math.abs( time.year) - 1) / 1000 ) + 1
		if ( moduleRoman ) then
			millenium = moduleRoman.toRomanNumber( millenium )
		end
		if ( categoryNamePrefix ) then
			return '[[' .. millenium .. ' тысячагодзьдзе да н. э.]][[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. millenium .. ' тысячагодзьдзі да н. э.]]'
		else
			return '[[' .. millenium .. ' тысячагодзьдзе да н. э.]]'
		end
	else
		local millenium = math.floor( (time.year - 1) / 1000 ) + 1
		if ( moduleRoman ) then
			millenium = moduleRoman.toRomanNumber( millenium )
		end
		if ( categoryNamePrefix ) then
			return '[[' .. millenium .. ' тысячагодзьдзе]][[Катэгорыя:' .. categoryNamePrefix .. ' ў ' .. millenium .. ' тысячагодзьдзі]]'
		else
			return '[[' .. millenium .. ' тысячагодзьдзе]]'
		end
	end
end

local function formatDateImpl( value, options, microformatClass, categoryPrefix, leftBracket, rightBracket, nolinks )
	if ( not value ) then error( 'значэньне не зададзенае'); end
	if ( not options ) then error( 'опцыі не зададзеныя'); end

	-- The calendar model used for saving the data is always the proleptic Gregorian calendar according to ISO 8601.
	local timeISO8601 = string.gsub( string.gsub( tostring( value.time ), '-00%-', '-01-' ), '-00T', '-01T' )
	local unixtime = parseISO8601( timeISO8601 )
	
	if not unixtime then
		return ''
	end

	local structure = os.date("*t", unixtime)
	local precision = tonumber( value.precision )
	
	if precision <= 6 then
		return formatMillenium(structure, categoryPrefix)
	end	
	if precision == 7 then
		return formatCentury(structure, categoryPrefix)
	end

	if precision == 8 then
		return formatDecade(structure, categoryPrefix)
	end

	if precision == 9 then
		local tCopy = deepcopy( structure )
		tCopy.day = nil
		tCopy.month = nil
		return moduleDates.formatWikiImpl(tCopy, tCopy, infoclass, categoryPrefix, leftBracket, rightBracket, nolinks )
	end

	-- толькі рок і месяц
	if precision == 10 then
		local tCopy = deepcopy( structure )
		tCopy.day = nil
		return moduleDates.formatWikiImpl(tCopy, tCopy, infoclass, categoryPrefix, leftBracket, rightBracket, nolinks )
	end

	local calendarmodel = 'gregorian'
	if (mw.ustring.find(value.calendarmodel, 'Q1985786', 1, true)) then
		calendarmodel = 'julian'
	end

	if (calendarmodel == 'gregorian') then
		return moduleDates.formatWikiImpl( structure, structure, microformatClass, categoryPrefix, leftBracket, rightBracket, nolinks )
	else
		return p.formatAsJulian( unixtime, infoclass, categoryPrefix, leftBracket, rightBracket, nolinks )
	end
end

local function formatApproximateDateClaim( context, options, statement, unknownDateCategory )
	if ( not context ) then error( 'кантэкст не зададзены'); end
	if ( not options ) then error( 'опцыі не зададзеныя'); end
	if ( not options.entity ) then error( 'адсутнічае options.entity'); end
	if ( not statement ) then error( 'сьцьверджаньне не зададзенае'); end
	if options.nocat then unknownDateCategory = "" end
	
	local qNotSoonerThan = getQualifierWithDataValue( statement, 'P1319' )
	local qNotLaterThan = getQualifierWithDataValue( statement, 'P1326' )
	if ( qNotSoonerThan or qNotLaterThan ) then
		local results = {}
		if ( qNotSoonerThan ) then
			local formattedDate = formatDateImpl( qNotSoonerThan.datavalue.value, {}, nil, nil, options.leftBracket, options.rightBracket, options.nolinks );
			local value = 'не раней за ' .. context.wrapSnak( formattedDate, qNotSoonerThan.hash );
			table.insert( results, context.wrapQualifier( value, 'P1319' ) )
		end
		if ( qNotLaterThan ) then
			local formattedDate = formatDateImpl( qNotLaterThan.datavalue.value, {}, nil, nil, options.leftBracket, options.rightBracket, options.nolinks );
			local value = 'не пазьней за ' .. context.wrapSnak( formattedDate, qNotLaterThan.hash );
			table.insert( results, context.wrapQualifier( value, 'P1326' ) )
		end
		return mw.text.listToText( results, ' і ' , ' і ' ) .. unknownDateCategory .. context.formatRefs( options, statement )
	end
	
	return nil
end

function p.formatDateOfBirthClaim( context, options, statement )
	local value = formatApproximateDateClaim( context, options, statement, dateCat.categoryUnknownBirthDate)
	if value then
		return value
	end

    options['conjunction'] = '&#32;або&#32;';
    options['value-module'] = 'Вікізьвесткі/дата';
    options['value-function'] = 'formatBirthDate';
    options.i18n.somevalue = '\'\'невядома\'\'' .. dateCat.categoryUnknownBirthDate;
	local result = context.formatStatementDefault( context, options, statement );

	local bTable = { parseClaim( statement ) };
	local dTable = parseProperty ( context, options, 'P570' )

	if ( bTable and not dTable ) then
		local age = ageCurrent( bTable )
		if ( age ) then
			if ( options.suppressAge == nil or options.suppressAge == '' ) then
				result = result .. ' <span style="white-space:nowrap;">(' .. age .. ' ' .. mw.language.new( 'be' ):plural( age, 'год', 'гады', 'гадоў') .. ')</span>'
			end
			if ( not options.nocat ) then
				if ( age > 115 ) then
					result = result .. dateCat.categoryBigCurrentAge
				elseif (age >= 0) then
					result = result .. dateCat.categoryBiographiesOfLivingPersons
				else
					result = result .. dateCat.categoryNegativeAge
				end
			end
		end
	end

	return result;
end

function p.formatDateOfDeathClaim( context, options, statement )
	local value = formatApproximateDateClaim( context, options, statement, dateCat.categoryUnknownDeathDate )
	if value then
		return value
	end

    options['conjunction'] = '&#32;або&#32;';
    options['value-module'] = 'Вікізьвесткі/дата';
    options['value-function'] = 'formatDeathDate';
    options.i18n.somevalue = '\'\'невядома\'\'';
	local result = context.formatStatementDefault( context, options, statement );

	local bTable = parseProperty ( context, options, 'P569' )
	local dTable = { parseClaim( statement ) };

	if ( bTable and dTable ) then
		local age = age( bTable, dTable )
		if ( age ) then
			if ( options.suppressAge == nil or options.suppressAge == '' ) then
				result = result .. ' <span style="white-space:nowrap;">(' .. age .. ' ' .. mw.language.new( 'be' ):plural( age, 'год', 'гады', 'гадоў') .. ')</span>'
			end
			if ( not options.nocat and age < 0) then
				result = result .. dateCat.categoryNegativeAge
			end
		end
		
		-- вяртае катэгорыю для нядаўна памерлых асобаў
		local unixAvailable, unixDateOfDeath = pcall(function()
			local r = os.time(dTable[1].structure)
			if ( r ~= os.time() ) then
				return r
			end
			error()
		end)
		if ( unixAvailable and os.time() - unixDateOfDeath < 31536000 and not options.nocat ) then
			result = result .. dateCat.categoryRecentlyDeceased
		end
	end

	return result;
end

-- Reentry point for Wikidata Snak formatting
function p.formatBirthDate( context, options, value )
	if ( not context ) then error( 'кантэкст не зададзены'); end;
	if ( not options ) then error( 'опцыі не зададзеныя'); end;
	if ( not value ) then error( 'значэньне не зададзенае'); end;
	
	local microformatClass = nil
	if options.microformat ~= '-' then
		microformatClass = options.microformat or 'bday'
	end
	if ( options.nocat ) then
		return formatDateImpl( value, options, microformatClass, nil, options.leftBracket, options.rightBracket, options.nolinks )
	else
		return formatDateImpl( value, options, microformatClass, 'Нарадзіліся', options.leftBracket, options.rightBracket, options.nolinks )
	end
end

-- Reentry point for Wikidata Snak formatting
function p.formatDeathDate( context, options, value )
	if ( not context ) then error( 'кантэкст не зададзены'); end;
	if ( not options ) then error( 'опцыі не зададзеныя'); end;
	if ( not value ) then error( 'значэньне не зададзенае'); end;

	local microformatClass = nil
	if options.microformat ~= '-' then
		microformatClass = options.microformat or 'dday'
	end
	if ( options.nocat and options.nocat ~= '' ) then
		return formatDateImpl( value, options, microformatClass, nil, options.leftBracket, options.rightBracket, options.nolinks )
	else
		return formatDateImpl( value, options, microformatClass, 'Памерлі', options.leftBracket, options.rightBracket, options.nolinks )
	end
end

-- Reentry point for Wikidata Snak formatting -- default one
function p.formatDate( context, options, value )
	if ( not context ) then error( 'кантэкст не зададзены'); end
	if ( not options ) then error( 'опцыі не зададзеныя'); end
	if ( not value ) then error( 'значэньне не зададзенае'); end

	local microformatClass = options.microformat or nil
	if ( options.nocat and options.nocat ~= '' ) then
		return formatDateImpl( value, options, microformatClass, nil, options.leftBracket, options.rightBracket, options.nolinks )
	else
		local categoryPrefix = options.categoryPrefix or nil;
		return formatDateImpl( value, options, microformatClass, categoryPrefix, options.leftBracket, options.rightBracket, options.nolinks )
	end
end

function p.formatDateIntervalProperty( context, options )
	if ( not context ) then error( 'кантэкст не зададзены' ); end;
	if ( not options ) then error( 'опцыі не зададзеныя' ); end;
	if ( not options.entity ) then error( 'адсутнічае options.entity' ); end;

	-- Атрыманьне патрэбных сьцьвярджэньняў
	local WDS = require( 'Модуль:Сьцьверджаньні Вікізьвестак' );
	local fromProperty = options.property
	if options.from and options.from ~= '' then
		fromProperty = options.from
	end
	local fromClaims = WDS.filter( options.entity.claims, fromProperty );
	local toClaims = WDS.filter( options.entity.claims, options.to );
	local withinClaims = WDS.filter( options.entity.claims, options.within );

    if fromClaims == nil and toClaims == nil then
        return ''
    end

	local formattedFromClaims = {}
	if fromClaims then
		for i, claim in ipairs( fromClaims ) do
			local formattedStatement = context.formatStatement( options, claim )
			if formattedStatement then
				formattedStatement = '<span class="wikidata-claim" data-wikidata-property-id="' .. string.upper( options.property ) .. '" data-wikidata-claim-id="' .. claim.id .. '">' .. formattedStatement .. '</span>'
				table.insert( formattedFromClaims, formattedStatement )
			end
		end
	end

	local formattedToClaims = {}
	local toOptions = deepcopy( options )
	toOptions.property = options.to
	toOptions.novalue = nowLabel
	if toClaims then
		for i, claim in ipairs( toClaims ) do
			local formattedStatement = context.formatStatement( toOptions, claim )
			if formattedStatement then
				formattedStatement = '<span class="wikidata-claim" data-wikidata-property-id="' .. string.upper( toOptions.property ) .. '" data-wikidata-claim-id="' .. claim.id .. '">' .. formattedStatement .. '</span>'
				table.insert( formattedToClaims, formattedStatement )
			end
		end
	end

	local out = ''
	local fromOut = mw.text.listToText( formattedFromClaims, options.separator, options.conjunction )
	local toOut = mw.text.listToText( formattedToClaims, options.separator, options.conjunction )

	if fromOut ~= '' or toOut ~= '' then
		if fromOut ~= '' then
			out = fromOut
		else
			out = '?'
		end

		if toOut ~= '' then
			out = out .. ' — ' .. toOut
		else
			if withinClaims ~= nil then
				out = 'з ' .. out
			else
				out = out .. ' — ' .. nowLabel
			end
		end
	end

	if out ~= '' then
		if options.before then
			out = options.before .. out
		end
		if options.after then
			out = out .. options.after
		end
	end

    return out
end

local lowestBoundary = parseISO8601('-900-02-20T00:00:00Z')
local mainBoundary = parseISO8601('1582-10-05T00:00:00Z')
local lastBoundary = parseISO8601('1918-01-31T00:00:00Z');

local boundaries = {
	-- from (G) till next will be diff(G = J + diff), at current
	{ lowestBoundary,                       -9 },
	{ parseISO8601('-700-02-29T00:00:00Z'), -8 },
	{ parseISO8601('-600-02-29T00:00:00Z'), -7 },
	{ parseISO8601('-500-02-29T00:00:00Z'), -6 },
	{ parseISO8601('-300-02-29T00:00:00Z'), -5 },
	{ parseISO8601('-200-02-29T00:00:00Z'), -4 },
	{ parseISO8601('-100-02-29T00:00:00Z'), -3 },
	{ parseISO8601('0000-00-00T00:00:00Z'), -2 },
	{ parseISO8601('0100-02-29T00:00:00Z'), -1 },
	{ parseISO8601('0200-02-29T00:00:00Z'),  0 },
	{ parseISO8601('0300-02-29T00:00:00Z'),  1 },
	{ parseISO8601('0500-02-29T00:00:00Z'),  2 },
	{ parseISO8601('0600-02-29T00:00:00Z'),  3 },
	{ parseISO8601('0700-02-29T00:00:00Z'),  4 },
	{ parseISO8601('0900-02-29T00:00:00Z'),  5 },
	{ parseISO8601('1000-02-29T00:00:00Z'),  6 },
	{ parseISO8601('1100-02-29T00:00:00Z'),  7 },
	{ parseISO8601('1300-02-29T00:00:00Z'),  8 },
	{ parseISO8601('1400-02-29T00:00:00Z'),  9 },
	{ parseISO8601('1500-02-29T00:00:00Z'), 10 },
	{ parseISO8601('1700-02-29T00:00:00Z'), 11 },
	{ parseISO8601('1800-02-29T00:00:00Z'), 12 },
	{ parseISO8601('1900-02-29T00:00:00Z'), 13 },
	{ lastBoundary, '' },
};

-- Перадаваны час мусіць быць паводле юліянскага календара (стары стыль)
function p.formatAsJulian( julTime, infocardClass, categoryNamePrefix, leftBracket, rightBracket, nolinks )
	if 'table' == type( julTime ) then
		if julTime.args and julTime.args[1] then
			julTime = tonumber( julTime.args[1] )
		else
			return 'невядомы тып аргумэнту: ' .. type( julTime ) .. ': ' .. table.tostring( julTime )
		end
	end

	local t = os.date( "*t", julTime )
	if ( julTime <= lowestBoundary ) then
		return "''няслушная дата (недасяжная дакладнасьць)''"
	end
	if ( julTime >= lastBoundary ) then
		return "''няслушная дата (юліянскі не выкарыстоўваецца пасьля 26.01.1918)''"
	end

	for i=1,#boundaries,1 do
		local b1 = boundaries[i][1]
		local b2 = boundaries[i + 1][1]
		if ( b1 <= julTime and julTime < b2 ) then
			local b1s = os.date( "*t", b1 )
			if ( b1s.year == t.year and b1s.month == t.month and b1s.day == t.day) then
				if ( julTime < mainBoundary ) then
					-- толькі юліянскі
					return moduleDates.formatWikiImpl( {year=t.year, month=2, day=29}, {year=t.year, month=2, day=29}, infocardClass, categoryNamePrefix, leftBracket, rightBracket, nolinks )
				else
					-- юліянскі і грыгарыянскі
					return moduleDates.formatWikiImpl( {year=t.year, month=2, day=29}, t, infocardClass, categoryNamePrefix, leftBracket, rightBracket, nolinks )
				end
			else
				local gregTime = os.date( "*t", julTime + boundaries[i][2] * 24 * 60 * 60 )
				if ( julTime < mainBoundary ) then
					-- толькі юліянскі
					return moduleDates.formatWikiImpl( t, t, infocardClass, categoryNamePrefix, leftBracket, rightBracket, nolinks )
				else
					-- юліянскі і грыгарыянскі
					return moduleDates.formatWikiImpl( t, gregTime, infocardClass, categoryNamePrefix, leftBracket, rightBracket, nolinks )
				end
			end
		end
	end

    if ( julTime >= lastBoundary ) then
		return "''памылка ў модулі Модуль:Вікізьвесткі/дата (ня знойдзены зрух канвэртацыі календара)''";
	end
end

return p