Module:Autochangecat

--Automatically changes categories/templates after xx days -- use in template or directly -- Syntax = -- This module uses module:utility make sure it import it, or it won't work. local p = {} local u = require("Module:Utility") function p.main(frame) local oArgTableParent,oArgTableChild = u.getArgs(frame) oArgTable = oArgTableChild or oArgTableParent local iDays, sArg1, sArg2 = oArgTable["days"], oArgTable["category1"] or oArgTable["template1"], oArgTable["category2"] or oArgTable["template2"] local bTemplate = oArgTable["template"] local sNewCategory = p.changeCategory(iDays,sArg1,sArg2,bTemplate) return sNewCategory end function p.changeCategory(iDays,sArg1,sArg2,bChangeTemplate) local sCat ="" if (iDays and sArg1 and sArg2) then local iFutureDate = u.addDays (os.date("%Y-%m-%d"),iDays) local iDaysLeft = u.datediff(os.date("%Y-%m-%d"),iFutureDate) local sPrefix = "".. "Category:"       local sSuffix = "" if (bChangeTemplate=="true") then sPrefix = "" end local sCategoryPrefix = sPrefix if (iDaysLeft<1) then sCat = preprocess(sCategoryPrefix .. sArg2 .. sSuffix) else sCat = preprocess(sCategoryPrefix .. sArg1 .. sSuffix) end end return sCat end function preprocess(sText) if (mw.getCurrentFrame) then sText = mw.getCurrentFrame:preprocess(sText) end return sText end return p