Module:Autochangecat

--Automatically changes categories after xx days

local p = {} local u = require("Module:Utility")

function p.main(frame) local oArgTableParent,oArgTableChild = u.getArgs(frame) oArgTable = oArgTableChild or oArgTableParent local iDays, sCategory1, sCategory2 = oArgTable["days"], oArgTable["category1"], oArgTable["category2"] local sNewCategory = p.changeCategory(iDays,sCategory1,sCategory2) return sNewCategory end

function p.changeCategory(iDays,sCategory1,sCategory2) local sCat ="" if (iDays and sCategory1 and sCategory2) then local iFutureDate = u.addDays (os.date("%Y-%m-%d"),iDays) local iDaysLeft = u.datediff(os.date("%Y-%m-%d"),iFutureDate) local sCategoryPrefix = "" .. "Category:"       if (iDaysLeft<1) then            sCat = preprocess(sCategoryPrefix .. sCategory2 .. "") else sCat = preprocess(sCategoryPrefix .. sCategory1 .. "]]") end end return sCat end

function preprocess(sText) if (mw.getCurrentFrame) then sText = mw.getCurrentFrame.preprocess(sText) end return sText end

return p