﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://xn--90aogluj.xn--p1ai/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3AWikidata%2Fdate</id>
	<title>Модуль:Wikidata/date - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://xn--90aogluj.xn--p1ai/index.php?action=history&amp;feed=atom&amp;title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%3AWikidata%2Fdate"/>
	<link rel="alternate" type="text/html" href="http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;action=history"/>
	<updated>2026-04-27T19:37:52Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=9777&amp;oldid=prev</id>
		<title>Peandre2: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=9777&amp;oldid=prev"/>
		<updated>2020-02-22T13:53:28Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Версия 13:53, 22 февраля 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Peandre2</name></author>
		
	</entry>
	<entry>
		<id>http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=9776&amp;oldid=prev</id>
		<title>ru&gt;Ghuron: options.i18n приходит из головного модуля, их тут имеет смысл только переопределять</title>
		<link rel="alternate" type="text/html" href="http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=9776&amp;oldid=prev"/>
		<updated>2019-10-25T06:16:33Z</updated>

		<summary type="html">&lt;p&gt;options.i18n приходит из головного модуля, их тут имеет смысл только переопределять&lt;/p&gt;
&lt;a href=&quot;http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;amp;diff=9776&amp;amp;oldid=629&quot;&gt;Внесённые изменения&lt;/a&gt;</summary>
		<author><name>ru&gt;Ghuron</name></author>
		
	</entry>
	<entry>
		<id>http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=629&amp;oldid=prev</id>
		<title>Peandre2: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://xn--90aogluj.xn--p1ai/index.php?title=%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C:Wikidata/date&amp;diff=629&amp;oldid=prev"/>
		<updated>2015-01-05T08:37:07Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--settings&lt;br /&gt;
local categoryUnknownBirthDate = '[[Категория:Персоналии, чья дата рождения не установлена]]';&lt;br /&gt;
local categoryUnknownDeathDate = '[[Категория:Персоналии, чья дата смерти не установлена]]';&lt;br /&gt;
local categoryBigCurrentAge = '[[Категория:Википедия:Статьи о персоналиях с большим текущим возрастом]]'&lt;br /&gt;
local categoryBigDeathAge = '[[Категория:Википедия:Статьи о персоналиях с большим возрастом во время смерти]]'&lt;br /&gt;
&lt;br /&gt;
local moduleDates = require( &amp;quot;Module:Dates&amp;quot; )&lt;br /&gt;
local moduleWikidata = require( &amp;quot;Module:Wikidata&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
function deepcopy(orig)&lt;br /&gt;
    local orig_type = type(orig)&lt;br /&gt;
    local copy&lt;br /&gt;
    if orig_type == 'table' then&lt;br /&gt;
        copy = {}&lt;br /&gt;
        for orig_key, orig_value in next, orig, nil do&lt;br /&gt;
            copy[deepcopy(orig_key)] = deepcopy(orig_value)&lt;br /&gt;
        end&lt;br /&gt;
        setmetatable(copy, deepcopy(getmetatable(orig)))&lt;br /&gt;
    else -- number, string, boolean, etc&lt;br /&gt;
        copy = orig&lt;br /&gt;
    end&lt;br /&gt;
    return copy&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- accepts table of time+precision values&lt;br /&gt;
function ageCurrent ( bTable )&lt;br /&gt;
	local possibleAge = &amp;quot;NYA&amp;quot; -- it meansm &amp;quot;Not Yet Assigned&amp;quot;, not what you imagined!&lt;br /&gt;
&lt;br /&gt;
	for bKey, bValue in pairs(bTable) do&lt;br /&gt;
		if ( bValue.unknown ) then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		local bStructure = bValue.structure&lt;br /&gt;
		local bPrecision = bValue.precision&lt;br /&gt;
&lt;br /&gt;
		local dStructure = os.date( &amp;quot;*t&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
		local calculatedAge = ageImpl ( bStructure, bPrecision, dStructure, 11 )&lt;br /&gt;
		if ( possibleAge == &amp;quot;NYA&amp;quot; ) then&lt;br /&gt;
			possibleAge = calculatedAge&lt;br /&gt;
		else&lt;br /&gt;
			if ( possibleAge ~= calculatedAge ) then&lt;br /&gt;
				possibleAge = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return possibleAge&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- accepts tables of time+precision values&lt;br /&gt;
function age ( bTable, dTable )&lt;br /&gt;
	local possibleAge = &amp;quot;NYA&amp;quot; -- it meansm &amp;quot;Not Yet Assigned&amp;quot;, not what you imagined!&lt;br /&gt;
&lt;br /&gt;
	for bKey, bValue in pairs( bTable ) do&lt;br /&gt;
		if ( bValue.unknown ) then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
		local bStructure = bValue.structure&lt;br /&gt;
		local bPrecision = bValue.precision&lt;br /&gt;
&lt;br /&gt;
		for dKey, dValue in pairs( dTable ) do&lt;br /&gt;
			if ( dValue.unknown ) then&lt;br /&gt;
				return nil&lt;br /&gt;
			end&lt;br /&gt;
			local dStructure = dValue.structure&lt;br /&gt;
			local dPrecision = dValue.precision&lt;br /&gt;
&lt;br /&gt;
			local calculatedAge = ageImpl ( bStructure, bPrecision, dStructure, dPrecision )&lt;br /&gt;
			if ( possibleAge == &amp;quot;NYA&amp;quot; ) then&lt;br /&gt;
				possibleAge = calculatedAge&lt;br /&gt;
			else&lt;br /&gt;
				if ( possibleAge ~= calculatedAge ) then&lt;br /&gt;
					possibleAge = nil&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return possibleAge&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function ageImpl ( bStructure, bPrecision, dStructure, dPrecision )&lt;br /&gt;
	if ( not bStructure or not dStructure or bPrecision &amp;lt; 10 or dPrecision &amp;lt; 10 ) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
 	if ( bPrecision == 10 or dPrecision == 10 ) then&lt;br /&gt;
 		if ( bStructure.month &amp;lt; dStructure.month ) then&lt;br /&gt;
 			return dStructure.year - bStructure.year&lt;br /&gt;
 		end&lt;br /&gt;
 		if ( bStructure.month == dStructure.month ) then&lt;br /&gt;
 			return nil&lt;br /&gt;
 		end&lt;br /&gt;
 		if ( bStructure.month &amp;gt; dStructure.month ) then&lt;br /&gt;
 			return dStructure.year - bStructure.year - 1&lt;br /&gt;
 		end&lt;br /&gt;
 	end&lt;br /&gt;
 &lt;br /&gt;
  	if ( bStructure.month &amp;lt; dStructure.month ) then&lt;br /&gt;
 		return dStructure.year - bStructure.year&lt;br /&gt;
 	end&lt;br /&gt;
 	if ( bStructure.month == dStructure.month ) then&lt;br /&gt;
	  	if ( bStructure.day &amp;lt;= dStructure.day ) then&lt;br /&gt;
	 		return dStructure.year - bStructure.year&lt;br /&gt;
	 	else &lt;br /&gt;
	 		return dStructure.year - bStructure.year - 1&lt;br /&gt;
 		end&lt;br /&gt;
 	end&lt;br /&gt;
 	if ( bStructure.month &amp;gt; dStructure.month ) then&lt;br /&gt;
 		return dStructure.year - bStructure.year - 1&lt;br /&gt;
 	end&lt;br /&gt;
&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- returns table of time+precision values for specified property&lt;br /&gt;
function parseProperty ( context, options, propertyId )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not options.entity ) then error( 'options.entity is missing'); end;&lt;br /&gt;
	if ( not propertyId ) then error( 'propertyId not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	local claims = context.selectClaims( options, propertyId );&lt;br /&gt;
	if not claims then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local result = {}&lt;br /&gt;
	for key, claim in pairs( claims ) do&lt;br /&gt;
		table.insert ( result, parseClaim( claim ) );&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function parseClaim ( claim )&lt;br /&gt;
	if ( claim.mainsnak.snaktype == &amp;quot;value&amp;quot; ) then&lt;br /&gt;
		-- The calendar model used for saving the data is always the proleptic Gregorian calendar according to ISO 8601.&lt;br /&gt;
		local timeISO8601 = string.gsub( string.gsub( tostring( claim.mainsnak.datavalue.value.time ), '-00%-', '-01-' ), '-00T', '-01T' )&lt;br /&gt;
		local unixtime = parseISO8601( timeISO8601 )&lt;br /&gt;
		local structure = os.date(&amp;quot;*t&amp;quot;, unixtime)&lt;br /&gt;
		local precision = tonumber( claim.mainsnak.datavalue.value.precision )&lt;br /&gt;
		local item = { structure=structure, precision=precision }&lt;br /&gt;
		return item;&lt;br /&gt;
	elseif ( claim.mainsnak.snaktype == &amp;quot;novalue&amp;quot; ) then&lt;br /&gt;
		-- novalue&lt;br /&gt;
		return { unknown=&amp;quot;novalue&amp;quot; };&lt;br /&gt;
	else&lt;br /&gt;
		--unknown &lt;br /&gt;
		return { unknown=&amp;quot;unknown&amp;quot; };&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- проверка на совпадающие даты с разной моделью календаря&lt;br /&gt;
function checkDupDates( t )&lt;br /&gt;
	if #t &amp;gt; 1 then&lt;br /&gt;
		local removed = false;&lt;br /&gt;
		local j = 1;&lt;br /&gt;
		-- проверка на совпадающие даты с разной моделью календаря&lt;br /&gt;
		while (j &amp;lt;= #t)  do&lt;br /&gt;
			local i = 1;&lt;br /&gt;
			while (i &amp;lt;= #t)  do&lt;br /&gt;
				if i ~= j then&lt;br /&gt;
					if (os.time(t[j].structure) == os.time(t[i].structure)) then&lt;br /&gt;
						if ((t[j].calendarmodel == 'gregorian') and &lt;br /&gt;
							(t[i].calendarmodel == 'julian')) then&lt;br /&gt;
							removed = true;&lt;br /&gt;
							break;&lt;br /&gt;
						else&lt;br /&gt;
							table.remove(t, i)&lt;br /&gt;
						end&lt;br /&gt;
					else&lt;br /&gt;
					  i = i + 1;&lt;br /&gt;
					end&lt;br /&gt;
				else&lt;br /&gt;
					i = i + 1;&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			if removed then&lt;br /&gt;
				removed = false;&lt;br /&gt;
				table.remove(t, j);&lt;br /&gt;
			else&lt;br /&gt;
				j = j+1;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- returns first qualifier of specified propertyId&lt;br /&gt;
function getQualifierDataValue( statement, qualifierPropertyId )&lt;br /&gt;
	if ( statement.qualifiers&lt;br /&gt;
			and statement.qualifiers[qualifierPropertyId] ) then&lt;br /&gt;
		local qualifiers = statement.qualifiers[qualifierPropertyId];&lt;br /&gt;
		for _, qualifier in ipairs( qualifiers ) do&lt;br /&gt;
			if (qualifier.datavalue) then&lt;br /&gt;
				return qualifier.datavalue;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return nil;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.formatDateOfBirthClaim( context, options, statement )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not options.entity ) then error( 'options.entity is missing'); end;&lt;br /&gt;
	if ( not statement ) then error( 'statement not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	if ( statement.mainsnak.snaktype == 'somevalue' ) then&lt;br /&gt;
		local qNotSoonerThan = getQualifierDataValue( statement, 'P1319' );&lt;br /&gt;
		local qNotLaterThan = getQualifierDataValue( statement, 'P1326' );&lt;br /&gt;
		if ( qNotSoonerThan or qNotLaterThan ) then&lt;br /&gt;
			local results = {};&lt;br /&gt;
			if ( qNotSoonerThan ) then&lt;br /&gt;
				table.insert( results, 'не&amp;amp;nbsp;ранее&amp;amp;nbsp;' .. formatDateImpl( qNotSoonerThan.value, {}, nil, nil ) );&lt;br /&gt;
			end&lt;br /&gt;
			if ( qNotLaterThan ) then&lt;br /&gt;
				table.insert( results, 'не&amp;amp;nbsp;позднее&amp;amp;nbsp;' .. formatDateImpl( qNotLaterThan.value, {}, nil, nil ) );&lt;br /&gt;
			end&lt;br /&gt;
		    return mw.text.listToText( results, ' и ' , ' и ' ) .. categoryUnknownBirthDate;&lt;br /&gt;
    	end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    options['conjunction'] = '&amp;amp;#32;или&amp;amp;#32;';&lt;br /&gt;
    options['value-module'] = 'Wikidata/date';&lt;br /&gt;
    options['value-function'] = 'formatBirthDate';&lt;br /&gt;
    options.i18n.somevalue = '\'\'неизвестно\'\'' .. categoryUnknownBirthDate;&lt;br /&gt;
    options.i18n.approximate = '&amp;lt;span style=&amp;quot;border-bottom: 1px dotted; cursor: help;&amp;quot; title=&amp;quot;около&amp;quot;&amp;gt;ок. &amp;lt;/span&amp;gt;';&lt;br /&gt;
	local result = context.formatStatementDefault( context, options, statement );&lt;br /&gt;
&lt;br /&gt;
	local bTable = { parseClaim( statement ) };&lt;br /&gt;
	local dTable = parseProperty ( context, options, 'P570' )&lt;br /&gt;
&lt;br /&gt;
	if ( bTable and not dTable ) then&lt;br /&gt;
		local age = ageCurrent( bTable )&lt;br /&gt;
		if ( age ) then&lt;br /&gt;
			result = result .. ' &amp;lt;span style=&amp;quot;white-space:nowrap;&amp;quot;&amp;gt;(' .. age .. ' ' .. mw.language.new( 'ru' ):plural( age, 'год', 'года', 'лет') .. ')&amp;lt;/span&amp;gt;'&lt;br /&gt;
		    if ( age &amp;gt; 150 and not options.nocat ) then&lt;br /&gt;
		        result = result .. categoryBigCurrentAge;&lt;br /&gt;
		    end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return result;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.formatDateOfDeathClaim( context, options, statement )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not options.entity ) then error( 'options.entity is missing'); end;&lt;br /&gt;
	if ( not statement ) then error( 'statement not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	if ( statement.mainsnak.snaktype == 'somevalue' ) then&lt;br /&gt;
		local qNotSoonerThan = getQualifierDataValue( statement, 'P1319' );&lt;br /&gt;
		local qNotLaterThan = getQualifierDataValue( statement, 'P1326' );&lt;br /&gt;
		if ( qNotSoonerThan or qNotLaterThan ) then&lt;br /&gt;
			local results = {};&lt;br /&gt;
			if ( qNotSoonerThan ) then&lt;br /&gt;
				table.insert( results, 'не&amp;amp;nbsp;ранее&amp;amp;nbsp;' .. formatDateImpl( qNotSoonerThan.value, {}, nil, nil ) );&lt;br /&gt;
			end&lt;br /&gt;
			if ( qNotLaterThan ) then&lt;br /&gt;
				table.insert( results, 'не&amp;amp;nbsp;позднее&amp;amp;nbsp;' .. formatDateImpl( qNotLaterThan.value, {}, nil, nil ) );&lt;br /&gt;
			end&lt;br /&gt;
		    return mw.text.listToText( results, ' и ' , ' и ' ) .. categoryUnknownDeathDate;&lt;br /&gt;
    	end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    options['conjunction'] = '&amp;amp;#32;или&amp;amp;#32;';&lt;br /&gt;
    options['value-module'] = 'Wikidata/date';&lt;br /&gt;
    options['value-function'] = 'formatDeathDate';&lt;br /&gt;
    options.i18n.somevalue = '\'\'неизвестно\'\'' .. categoryUnknownDeathDate;&lt;br /&gt;
    options.i18n.approximate = '&amp;lt;span style=&amp;quot;border-bottom: 1px dotted; cursor: help;&amp;quot; title=&amp;quot;около&amp;quot;&amp;gt;ок. &amp;lt;/span&amp;gt;';&lt;br /&gt;
	local result = context.formatStatementDefault( context, options, statement );&lt;br /&gt;
&lt;br /&gt;
	local bTable = parseProperty ( context, options, 'P569' )&lt;br /&gt;
	local dTable = { parseClaim( statement ) };&lt;br /&gt;
&lt;br /&gt;
	if ( bTable and dTable ) then&lt;br /&gt;
		local age = age( bTable, dTable )&lt;br /&gt;
		if ( age ) then&lt;br /&gt;
			result = result .. ' &amp;lt;span style=&amp;quot;white-space:nowrap;&amp;quot;&amp;gt;(' .. age .. ' ' .. mw.language.new( 'ru' ):plural( age, 'год', 'года', 'лет') .. ')&amp;lt;/span&amp;gt;'&lt;br /&gt;
		    if ( age &amp;gt; 150 and (not context.options or not context.options.nocat) ) then&lt;br /&gt;
		        result = result .. categoryBigDeathAge;&lt;br /&gt;
		    end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return result;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Reentry point for Wikidata Snak formatting&lt;br /&gt;
function p.formatBirthDate( context, options, value )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not value ) then error( 'value not specified'); end;&lt;br /&gt;
	&lt;br /&gt;
	if ( options.nocat ) then&lt;br /&gt;
		return formatDateImpl( value, options, 'bday', nil )&lt;br /&gt;
	else&lt;br /&gt;
		return formatDateImpl( value, options, 'bday', 'Родившиеся ' )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Reentry point for Wikidata Snak formatting&lt;br /&gt;
function p.formatDeathDate( context, options, value )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not value ) then error( 'value not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	if ( options.nocat ) then&lt;br /&gt;
		return formatDateImpl( value, options, 'dday', nil )&lt;br /&gt;
	else&lt;br /&gt;
		return formatDateImpl( value, options, 'dday', 'Умершие ' )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Reentry point for Wikidata Snak formatting -- default one&lt;br /&gt;
function p.formatDate( context, options, value )&lt;br /&gt;
	if ( not context ) then error( 'context not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
	if ( not value ) then error( 'value not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	local microformatClass = options.microfortmat or nil;&lt;br /&gt;
	if ( options.nocat ) then&lt;br /&gt;
		return formatDateImpl( value, options, microformatClass, nil )&lt;br /&gt;
	else&lt;br /&gt;
		local categoryPrefix = options.categoryPrefix or nil;&lt;br /&gt;
		return formatDateImpl( value, options, microformatClass, categoryPrefix )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function formatDateImpl( value, options, microformatClass, categoryPrefix )&lt;br /&gt;
	if ( not value ) then error( 'value not specified'); end;&lt;br /&gt;
	if ( not options ) then error( 'options not specified'); end;&lt;br /&gt;
&lt;br /&gt;
	-- The calendar model used for saving the data is always the proleptic Gregorian calendar according to ISO 8601.&lt;br /&gt;
	local timeISO8601 = string.gsub( string.gsub( tostring( value.time ), '-00%-', '-01-' ), '-00T', '-01T' )&lt;br /&gt;
	local unixtime = parseISO8601( timeISO8601 )&lt;br /&gt;
&lt;br /&gt;
	local structure = os.date(&amp;quot;*t&amp;quot;, unixtime)&lt;br /&gt;
	local precision = tonumber( value.precision )&lt;br /&gt;
	&lt;br /&gt;
	if precision == 7 then&lt;br /&gt;
		return formatCentury(structure, categoryPrefix)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if precision == 8 then&lt;br /&gt;
		return formatDecade(structure, categoryPrefix)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if precision == 9 then&lt;br /&gt;
		local tCopy = deepcopy( structure )&lt;br /&gt;
		tCopy.day = nil&lt;br /&gt;
		tCopy.month = nil&lt;br /&gt;
		return moduleDates.formatWikiImpl(tCopy, tCopy, infoclass, categoryPrefix)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- year and month only&lt;br /&gt;
	if precision == 10 then&lt;br /&gt;
		local tCopy = deepcopy( structure )&lt;br /&gt;
		tCopy.day = nil&lt;br /&gt;
		return moduleDates.formatWikiImpl(tCopy, tCopy, infoclass, categoryPrefix)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local calendarmodel = 'gregorian';&lt;br /&gt;
	if (mw.ustring.find(value.calendarmodel, 'Q1985786', 1, true)) then&lt;br /&gt;
		calendarmodel = 'julian';&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if (calendarmodel == 'gregorian') then&lt;br /&gt;
    	return moduleDates.formatWikiImpl( structure, structure, microformatClass, categoryPrefix )&lt;br /&gt;
    else&lt;br /&gt;
		return p.formatAsJulian( unixtime, infoclass, categoryPrefix )&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function formatDecade( time, categoryNamePrefix )&lt;br /&gt;
	local year = math.floor( time.year / 10 ) * 10;&lt;br /&gt;
	if ( categoryNamePrefix ) then&lt;br /&gt;
		return year .. '-е[[К:' .. categoryNamePrefix .. ' в ' .. year .. '-е годы]]';&lt;br /&gt;
	else&lt;br /&gt;
		return '' .. year;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function formatCentury( time, categoryNamePrefix )&lt;br /&gt;
	local moduleRoman = require( &amp;quot;Module:RomanNumber&amp;quot; )&lt;br /&gt;
	if ( time.year &amp;lt; 0 ) then&lt;br /&gt;
		local century = math.floor( (math.abs( time.year) - 1) / 100 ) + 1;&lt;br /&gt;
		if ( moduleRoman ) then&lt;br /&gt;
			century = moduleRoman.toRomanNumber( century );&lt;br /&gt;
		end&lt;br /&gt;
		if ( categoryNamePrefix ) then&lt;br /&gt;
			return '[[' .. century .. ' век до н. э.]][[К:' .. categoryNamePrefix .. ' в ' .. century .. ' веке до н. э.]]'&lt;br /&gt;
		else&lt;br /&gt;
			return '[[' .. century .. ' век до н. э.]]'&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		local century = math.floor( (time.year - 1) / 100 ) + 1;&lt;br /&gt;
		if ( moduleRoman ) then&lt;br /&gt;
			century = moduleRoman.toRomanNumber( century );&lt;br /&gt;
		end&lt;br /&gt;
		if ( categoryNamePrefix ) then&lt;br /&gt;
			return '[[' .. century .. ' век]][[К:' .. categoryNamePrefix .. ' в ' .. century .. ' веке]]'&lt;br /&gt;
		else&lt;br /&gt;
			return '[[' .. century .. ' век]]'&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function parseISO8601Date(str)&lt;br /&gt;
	local pattern = &amp;quot;(%-?%d+)%-(%d+)%-(%d+)T&amp;quot;&lt;br /&gt;
	local Y, M, D = mw.ustring.match( str, pattern )&lt;br /&gt;
	return tonumber(Y), tonumber(M), tonumber(D)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function parseISO8601Time(str)&lt;br /&gt;
	local pattern = &amp;quot;T(%d+):(%d+):(%d+)%Z&amp;quot;&lt;br /&gt;
	local H, M, S = mw.ustring.match( str, pattern)&lt;br /&gt;
	return tonumber(H), tonumber(M), tonumber(S)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function parseISO8601Offset(str)&lt;br /&gt;
	if str:sub(-1)==&amp;quot;Z&amp;quot; then return 0,0 end -- ends with Z, Zulu time&lt;br /&gt;
 &lt;br /&gt;
	-- matches ±hh:mm, ±hhmm or ±hh; else returns nils &lt;br /&gt;
	local pattern = &amp;quot;([-+])(%d%d):?(%d?%d?)$&amp;quot;&lt;br /&gt;
	local sign, oh, om = mw.ustring.match( str, pattern) &lt;br /&gt;
	sign, oh, om = sign or &amp;quot;+&amp;quot;, oh or &amp;quot;00&amp;quot;, om or &amp;quot;00&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	return tonumber(sign .. oh), tonumber(sign .. om)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function parseISO8601(str)&lt;br /&gt;
	if 'table'==type(str) then&lt;br /&gt;
		if str.args and str.args[1] then&lt;br /&gt;
			str = '' .. str.args[1]&lt;br /&gt;
		else&lt;br /&gt;
			return 'unknown argument type: ' .. type( str ) .. ': ' .. table.tostring( str )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local Y,M,D = parseISO8601Date(str)&lt;br /&gt;
	local h,m,s = parseISO8601Time(str)&lt;br /&gt;
	local oh,om = parseISO8601Offset(str)&lt;br /&gt;
	return tonumber(os.time({year=Y, month=M, day=D, hour=(h+oh), min=(m+om), sec=s}))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local lowestBoundary = parseISO8601('-900-02-20T00:00:00Z')&lt;br /&gt;
local mainBoundary = parseISO8601('1582-10-15T00:00:00Z')&lt;br /&gt;
local lastBoundary = parseISO8601('1918-01-26T00:00:00Z');&lt;br /&gt;
&lt;br /&gt;
boundaries = {&lt;br /&gt;
	-- from (G) till next will be diff(G = J + diff), at current&lt;br /&gt;
	{ lowestBoundary,                         -9 },&lt;br /&gt;
	{ parseISO8601('-700-02-21T00:00:00Z'), -8 },&lt;br /&gt;
	{ parseISO8601('-600-02-22T00:00:00Z'), -7 },&lt;br /&gt;
	{ parseISO8601('-500-02-23T00:00:00Z'), -6 },&lt;br /&gt;
	{ parseISO8601('-300-02-24T00:00:00Z'), -5 },&lt;br /&gt;
	{ parseISO8601('-200-02-25T00:00:00Z'), -4 },&lt;br /&gt;
	{ parseISO8601('-100-02-26T00:00:00Z'), -3 },&lt;br /&gt;
	{ parseISO8601('0000-00-00T00:00:00Z'), -2 },&lt;br /&gt;
	{ parseISO8601('0100-02-27T00:00:00Z'), -1 },&lt;br /&gt;
	{ parseISO8601('0200-02-28T00:00:00Z'),  0 },&lt;br /&gt;
	{ parseISO8601('0300-03-01T00:00:00Z'),  1 },&lt;br /&gt;
	{ parseISO8601('0500-03-02T00:00:00Z'),  2 },&lt;br /&gt;
	{ parseISO8601('0600-03-03T00:00:00Z'),  3 },&lt;br /&gt;
	{ parseISO8601('0700-03-04T00:00:00Z'),  4 },&lt;br /&gt;
	{ parseISO8601('0900-03-05T00:00:00Z'),  5 },&lt;br /&gt;
	{ parseISO8601('1000-03-06T00:00:00Z'),  6 },&lt;br /&gt;
	{ parseISO8601('1100-03-07T00:00:00Z'),  7 },&lt;br /&gt;
	{ parseISO8601('1300-03-08T00:00:00Z'),  8 },&lt;br /&gt;
	{ parseISO8601('1400-03-09T00:00:00Z'),  9 },&lt;br /&gt;
	{ parseISO8601('1500-03-10T00:00:00Z'), 10 },&lt;br /&gt;
	{ parseISO8601('1700-03-11T00:00:00Z'), 11 },&lt;br /&gt;
	{ parseISO8601('1800-03-12T00:00:00Z'), 12 },&lt;br /&gt;
	{ parseISO8601('1900-03-13T00:00:00Z'), 13 },&lt;br /&gt;
	{ lastBoundary, '' },&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
-- Передаваемое время обязано быть по Григорианскому календарю (новому стилю)&lt;br /&gt;
function p.formatAsJulian( time, infocardClass, categoryNamePrefix )&lt;br /&gt;
	if 'table'==type( time ) then&lt;br /&gt;
		if time.args and time.args[1] then&lt;br /&gt;
			time = tonumber( time.args[1] )&lt;br /&gt;
		else&lt;br /&gt;
			return 'unknown argument type: ' .. type( time ) .. ': ' .. table.tostring( time )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local t = os.date(&amp;quot;*t&amp;quot;, time)&lt;br /&gt;
	if ( time &amp;lt;= lowestBoundary ) then&lt;br /&gt;
		return &amp;quot;''некорректная дата (недостижимая точность)''&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
	if ( time &amp;gt;= lastBoundary ) then&lt;br /&gt;
		return &amp;quot;''некорректная дата (юлианский не используется после 1918-01-26)''&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    for i=1,#boundaries,1 do&lt;br /&gt;
		local b1 = boundaries[i][1];&lt;br /&gt;
		local b2 = boundaries[i + 1][1];&lt;br /&gt;
		if ( b1 &amp;lt;= time and time &amp;lt; b2 ) then&lt;br /&gt;
			local b1s = os.date(&amp;quot;*t&amp;quot;, b1)&lt;br /&gt;
			if ( b1s.year == t.year and b1s.month == t.month and b1s.day == t.day) then&lt;br /&gt;
				if ( time &amp;lt; mainBoundary ) then&lt;br /&gt;
					-- only julian&lt;br /&gt;
					return moduleDates.formatWikiImpl( {year=t.year, month=2, day=29}, {year=t.year, month=2, day=29}, infocardClass, categoryNamePrefix );&lt;br /&gt;
				else&lt;br /&gt;
					--julian and grigorian&lt;br /&gt;
					return moduleDates.formatWikiImpl( {year=t.year, month=2, day=29}, t, infocardClass, categoryNamePrefix )&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				local julian = os.date(&amp;quot;*t&amp;quot;, time - boundaries[i][2] * 24 * 60 * 60);&lt;br /&gt;
				if ( time &amp;lt; mainBoundary ) then&lt;br /&gt;
					-- only julian&lt;br /&gt;
					return moduleDates.formatWikiImpl( julian, julian, infocardClass, categoryNamePrefix );&lt;br /&gt;
				else&lt;br /&gt;
					--julian and grigorian&lt;br /&gt;
					return moduleDates.formatWikiImpl( julian, t, infocardClass, categoryNamePrefix )&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    if ( time &amp;gt;= lastBoundary ) then&lt;br /&gt;
		return &amp;quot;''ошибка в модуле Модуль:Wikidata/date (не найден сдвиг конвертации календаря)''&amp;quot;;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Peandre2</name></author>
		
	</entry>
</feed>