Module:ChangePerDay

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:ChangePerDay/doc. [edit] [history] [purge]
Module:ChangePerDay requires Module:Number.
Function list
L 9 — p._change

This module is a helper module to be used by other modules; it may not be designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
_changetableDetermines the percent change in price (from last) over a given time interval. The args table expects the following parameters:
  • @param args[1] number price parameter. defaults to 1
  • @param args[2] number last price parameter. defaults to 1
  • @param args[3] string start date. defaults to 'January 1'.
  • @param args[3] string last date. defaults to 'July 1'.

-- <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