Editing
Module:DRNTimeAgo
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- Replacement for [[Template:Time ago]] local numberSpell = require('Module:NumberSpell')._main local yesno = require('Module:Yesno') local p = {} function p._main( args ) -- Initialize variables local lang = mw.language.getContentLanguage() local auto_magnitude_num local min_magnitude_num local result local result_unit local magnitude = args.magnitude local min_magnitude = args.min_magnitude local purge = args.purge local spell_out = args.spellout local spell_out_max = args.spelloutmax -- Add a purge link if something (usually "yes") is entered into the purge parameter if purge then purge = ' <span class="plainlinks">([' .. mw.title.getCurrentTitle():fullUrl('action=purge') .. ' purge])</span>' else purge = '' end -- Check that the entered timestamp is valid. If it isn't, then give an error message. local noError, inputTime = pcall( lang.formatDate, lang, 'U', args[1], true ) if not noError then return '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>' end -- Store the difference between the current time and the inputted time, as well as its absolute value. local timeDiff = lang:formatDate( 'U', nil, true ) - inputTime local absTimeDiff = math.abs( timeDiff ) -- Calculate the appropriate unit of time if it was not specified as an argument. local autoMagnitudeData = { { unit = 'days', amn = 86400 }, { unit = 'hours', amn = 3600 } } result = '' for i, t in ipairs( autoMagnitudeData ) do if absTimeDiff / t.amn >= 1 then local result_num = math.floor( absTimeDiff / t.amn ) if t.unit == 'hours' then result = result .. tostring(result_num) .. ' ' .. t.unit else result = result .. tostring(result_num) .. ' ' .. t.unit .. ', ' absTimeDiff = absTimeDiff - (t.amn * result_num) end end end if result == '' then local result_num = math.floor(absTimeDiff/60) result = tostring(result_num) .. ' minutes' end return result end function p.main( frame ) local args = require( 'Module:Arguments' ).getArgs( frame, { valueFunc = function( k, v ) if v then v = v:match( '^%s*(.-)%s*$' ) -- Trim whitespace. if k == 'ago' or v ~= '' then return v end end return nil end, wrappers = 'Template:DRNAgo' }) return p._main( args ) end return p
Summary:
Please note that all contributions to Eurovision Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Eurovision Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Page included on this page:
Module:DRNTimeAgo/doc
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Tools
What links here
Related changes
Page information