local myModule = require 'Modul:Wikidata/Formatters/time'
local Time = require 'Modul:Time'
local i18n = mw.loadData('Modul:Wikidata/i18n')
local ScribuntoUnit = require 'Modul:ScribuntoUnit'
local suite = ScribuntoUnit:new()
function suite:testYearDifference()
local provider = {
{ '1890-01-09', '1938-12-25', 48 },
{ '1890-01-09', '1990-01-09', 100 },
{ '1890-01-09', '1938-12', 48 },
{ '1890-01-09', '1938-01', 47, '47–48' },
{ '1890-01-09', '1938', 47, '47–48' },
{ '1890-01', '1938-12-25', 48 },
{ '1890-12', '1938-12-25', 47, '47–48' },
{ '1890-01', '1938-12', 48 },
{ '1890-12', '1938-12', 47, '47–48' },
{ '1890-01', '1938', 47, '47–48' },
{ '1890', '1938-12-25', 47, '47–48' },
{ '1890', '1938-12', 47, '47–48' },
{ '1890', '1938', 47, '47–48' },
}
for _, dates in ipairs(provider) do
local sooner = Time.newFromIso8601(dates[1])
local later = Time.newFromIso8601(dates[2])
local num_age, display_age = myModule.yearDifference(sooner, later)
self:assertEquals(dates[3], num_age)
self:assertEquals(dates[4] or dates[3], display_age)
end
end
function suite:testJulianToGregorian()
local provider = {
{
gregorian = '1582-10-15',
julian = '1582-10-05'
},
{
gregorian = '1582-11-10',
julian = '1582-10-31'
},
{
gregorian = '1583-01-09',
julian = '1582-12-30'
},
{
gregorian = '1583-01-09',
julian = '1582-12-30'
},
{
gregorian = '1583-03-09',
julian = '1583-02-27'
},
{
gregorian = '1584-03-08',
julian = '1584-02-27'
},
{
gregorian = '1600-03-08',
julian = '1600-02-27'
},
{
gregorian = '1700-02-28',
julian = '1700-02-18'
},
{
gregorian = '1700-03-01',
julian = '1700-02-19'
},
{
gregorian = '1700-03-10',
julian = '1700-02-28'
},
{
gregorian = '1700-03-11',
julian = '1700-02-29'
},
}
for _, data in ipairs(provider) do
local julian = Time.newFromIso8601(data.julian)
local gregorian = Time.newFromIso8601(data.gregorian)
julian.calendar = julian.CALENDAR.JULIAN
gregorian.calendar = julian.CALENDAR.GREGORIAN
self:assertEquals(gregorian, myModule.julianToGregorian(julian))
end
end
function suite:testFormatRawValue()
local lang = mw.getContentLanguage()
local provider = {
{
iso = '1890-01-09',
formatted = '[[9. leden|9. ledna]] [[1890]]'
},
{
iso = '1890-01-09',
formatted = '[[9. leden|9. ledna]] [[1890]] n. l.',
options = { showera = true },
},
{
iso = '1890-01-09',
formatted = '9. ledna 1890',
options = { nolink = true }
},
{
iso = '123',
formatted = '[[123]]'
},
{
iso = '123',
formatted = '123',
options = { nolink = true }
},
{
iso = '-123',
formatted = '[[123 př. n. l.|123 př. n. l.]]'
},
{
iso = '-123',
formatted = '123 př. n. l.',
options = { nolink = true }
},
{
iso = '-0601',
formatted = '7. století př. n. l.',
options = { nolink = true, precision = Time.PRECISION.YEAR100 }
},
{
iso = '-0600',
formatted = '6. století př. n. l.',
options = { nolink = true, precision = Time.PRECISION.YEAR100 }
},
{
iso = '-0599',
formatted = '6. století př. n. l.',
options = { nolink = true, precision = Time.PRECISION.YEAR100 }
},
{
iso = '1890-01-09',
formatted = '[[1890]]',
options = { precision = Time.PRECISION.YEAR }
},
{
iso = '1890',
formatted = '[[1890]]',
options = { precision = Time.PRECISION.MONTH }
},
{
iso = '1890',
precision = Time.PRECISION.YEAR10,
formatted = 'Desetiletí od 1890'
},
{
iso = '1890',
formatted = '[[19. století|19. století]]',
options = { precision = Time.PRECISION.YEAR100 }
},
{
iso = '1900',
precision = Time.PRECISION.YEAR100,
formatted = '[[19. století|19. století]]'
},
{
iso = '1400',
precision = Time.PRECISION.KY,
formatted = '2. tisíciletí',
options = { nolink = true }
},
{
iso = '20000',
precision = Time.PRECISION.KY10,
formatted = lang:formatNum(20000) .. ' let'
},
{
iso = '-20000',
precision = Time.PRECISION.KY10,
formatted = lang:formatNum(20000) .. ' let př. n. l.'
},
{
iso = '-20000000',
precision = Time.PRECISION.MY,
formatted = '20 milionů let př. n. l.'
},
{
iso = '1700-02-29',
calendar = Time.CALENDAR.JULIAN,
formatted = '29. února' .. i18n.date.julian .. ' / [[11. březen|11. března]] [[1700]]' .. i18n.date.gregorian,
},
}
for _, data in ipairs(provider) do
local timevalue = Time.newFromIso8601(data.iso)
if data.precision then
timevalue.precision = data.precision
end
if data.calendar then
timevalue.calendar = data.calendar
end
local options = data.options or {}
self:assertEquals(data.formatted, myModule.formatRawValue(timevalue, options))
end
end
return suite