Module:Time ago/testcases
Appearance
![]() | This is the test cases page for the module Module:Time ago. Results of the test cases. |
-- Unit tests for [[Module:TimeAgo]]. Click talk page to run tests.
local p = require('Module:UnitTests')
function p:test_timeAgo()
local lang = mw.language.getContentLanguage()
-- Calculate the time since/until the test dates here, so that the test cases do not fail in the future.
minutessincejul09 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '1 July 2009' ) ) / 60 )
dayssincejul09 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '1 July 2009' ) ) / 86400 )
weekssincejul09 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '1 July 2009' ) ) / 604800 )
monthssincejul09 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '1 July 2009' ) ) / 2678400 )
yearssincejul09 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '1 July 2009' ) ) / 31557600 )
monthssincesep13 = math.floor( ( lang:formatDate( 'U' ) - lang:formatDate( 'U', '15 September 2013' ) ) / 2678400 )
monthsuntiljul49 = math.floor( ( lang:formatDate ( 'U', '1 July 2049' ) - lang:formatDate( 'U' ) ) / 2678400 )
yearsuntilaug57 = math.floor( ( lang:formatDate ( 'U', '4 August 2057' ) - lang:formatDate( 'U' ) ) / 31557600 )
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 September 2013}}', monthssincesep13 .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|15 September 2013|purge=yes}}', '{{Time ago|1 January 2012|purge=yes}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|{{CURRENTTIMESTAMP}}}}|purge=yes}}', '{{Time ago|{{CURRENTTIMESTAMP}}|purge=yes}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009}}', yearssincejul09 .. ' years ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=minutes}}', minutessincejul09 .. ' minutes ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=days}}', dayssincejul09 .. ' days ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=weeks}}', weekssincejul09 .. ' weeks ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=months}}', monthssincejul09 .. ' months ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2049|magnitude=months}}', monthsuntiljul49 .. ' months\' time')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|Julio 1}}', '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=fruits}}', '{{Time ago|July 1 2009|July 1 2009|magnitude=fruits}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo}}', '0 seconds ago')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|July 1 2009|magnitude=HoUrS}}', '{{Time ago|July 1 2009|magnitude=HoUrS}}')
self:preprocess_equals('{{#invoke:TimeAgo|timeAgo|4 August 2057}}', yearsuntilaug57 .. ' years\' time')
end
return p