Module:ChangePerDay
Revision as of 14:05, 9 November 2022 by Jacmob (talk | contribs) (Created page with "-- <nowiki> -- -- Implements {{ChangePerDay}} --  local p = {} local round = require( 'Module:Number' )._round  function p._change( args )     local lang = mw.language.getContentLanguage()      local price = tonumber( args[1] ) or 1     local last = tonumber( args[2] ) or 1     local date = args[3] or 'January 1'     local lastDate = args[4] or 'July 1'      local diff = lang:formatDate( 'U', date ) - lang:formatDate( 'U', lastDate )     local ret      diff = diff / 8640...")
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:ChangePerDay/doc. [edit]
Module:ChangePerDay requires Module:Number.
Module:ChangePerDay is required by Module:Exchange.
-- <nowiki>
--
-- Implements {{ChangePerDay}}
--
local p = {}
local round = require( 'Module:Number' )._round
function p._change( args )
    local lang = mw.language.getContentLanguage()
    local price = tonumber( args[1] ) or 1
    local last = tonumber( args[2] ) or 1
    local date = args[3] or 'January 1'
    local lastDate = args[4] or 'July 1'
    local diff = lang:formatDate( 'U', date ) - lang:formatDate( 'U', lastDate )
    local ret
    diff = diff / 86400 -- diff / no. secs in a day
    if diff < 1 then
        ret = price / last - 1
    else
        ret = ( price / last - 1 ) / math.ceil( diff )
    end
    return round( ret, 3 )
end
return p