Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TryCF Gist
<cfscript>
lastExecuted = dateAdd('y', -66, now());
writedump(lastExecuted)
coupon = {
"scheduled" = true,
"scheduledType" = "w",
"schedulerLastExecuted" = lastExecuted
};
runScheduler= runSchedulerForCoupon(coupon=coupon);
writedump(runScheduler)
</cfscript>
<cffunction name="runSchedulerForCoupon" returnType="boolean">
<cfargument name="coupon" type="struct" required="true">
<cfscript>
var dateNow = now();
if(NOT arguments.coupon.scheduled){
return false;
}
if(NOT isDefined("arguments.coupon.schedulerLastExecuted") OR arguments.coupon.schedulerLastExecuted EQ ""){
return true;
}
switch(arguments.coupon.scheduledType){
case "d":
return DatePart('y', dateNow) GT DatePart('y', arguments.coupon.schedulerLastExecuted);
case "w":
return Abs(DateDiff('d', dateNow, arguments.coupon.schedulerLastExecuted)) GTE 7;
case "m":
var isNextMonth = DatePart('m', dateNow) GT DatePart('m', arguments.coupon.schedulerLastExecuted);
return Abs(DateDiff('d', dateNow, arguments.coupon.schedulerLastExecuted)) GTE DaysInMonth(dateNow);
return isNextMonth AND (DatePart('d', dateNow) GTE DatePart('d', arguments.coupon.schedulerLastExecuted) OR DatePart('d', dateNow) GTE daysInMonth);
case "y":
var isNextYear = DatePart('yyyy', dateNow) GT DatePart('yyyy', arguments.coupon.schedulerLastExecuted);
return isNextYear AND (DatePart('y', arguments.coupon.schedulerLastExecuted) EQ DatePart('y', dateNow) OR (DatePart('y', dateNow) - DatePart('y', arguments.coupon.schedulerLastExecuted) GT 365));
default:
return false;
}
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment