Content deleted Content added
More days, apparently is 6 days behind! |
remove the tests based on REVISIONTIMESTAMP which fail for long periods because subtraction is wrong; use Module:Date for some |
||
Line 1:
-- Unit tests for [[Module:TimeAgo]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local Date = require('Module:Date')._Date
function p:test_main()
local lang = mw.language.getContentLanguage()
-- Calculate the time since/until the test dates here, since the expected output is dependent on the current time in most cases.
local currentTime = lang:formatDate( 'U' )
Line 17 ⟶ 18:
local monthsuntiljul49 = math.floor( ( lang:formatDate ( 'U', '1 July 2049' ) - currentTime ) / 2678400 )
local yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - currentTime ) / 31557600 )
local nowDateObj = Date('currentdate')
local oldDateObj = nowDateObj - '18y'
local oldDateDiff = nowDateObj - oldDateObj
local oldDateText = oldDateObj:text()
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|15 September 2013}}', monthssincesep13 .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
Line 42 ⟶ 47:
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|{{#time: r | -4 years -14 days}}|magnitude=years|spellout=auto}}', 'four years ago')
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|July 1 2009|magnitude=weeks|spellout=yes}}', weekssincejul09 .. ' weeks ago') -- [[Module:NumberSpell]] can only spell numbers up to 100.
self:preprocess_equals_preprocess('{{#invoke:TimeAgo/sandbox|main|
self:preprocess_equals_preprocess('{{#invoke:TimeAgo/sandbox|main|
self:preprocess_equals_preprocess('{{#invoke:TimeAgo/sandbox|main|
self:preprocess_equals_preprocess('{{#invoke:TimeAgo/sandbox|main|
-- Testing whether the module is accurate on the day
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|{{#time: r | -10 years }}}}', '10 years ago')
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|{{#time: r | -10 years -1 days}}}}', '10 years ago')
self:preprocess_equals('{{#invoke:TimeAgo/sandbox|main|{{#time: r | -1 years }}}}', '12 months ago')
|