Here is a little puzzler that I think will be fun, and hopefully much simpler than my last one. For today's puzzler, you must use ColdFusion to create a function that returns the day of the week (numerical) for a date. I know what you're thinking - doesn't ColdFusion have that built in? It does. But your task is to recreate it. I have absolutely no guidelines for how you recreate it - except that you can't - obviously - use the same logic that someone else does. While the winner of these things are pretty much always picked arbitrarily, today's is going to be even more crazy. I want to see the most weird, stupid, insane, etc, ways to solve this problem. Go crazy. The only restriction is that you have to run your code via a test harness to ensure it works right. I've written one for you. It allows you to pass in your UDF and it confirms it works for a large sample of dates.
<cffunction name="testHarness">
<cfargument name="myfunc" required="true">
<cfset var dates = []>
<cfset var x = "">
<cfset var result = {}>
<!--- first make the dates --->
<cfloop index="x" from="1" to="100">
<cfset arrayAppend(dates, dateAdd("d", randRange(-1000,1000), now()))>
</cfloop>
<cfloop index="x" from="1" to="#arrayLen(dates)#">
<cfif dayOfWeek(dates[x]) neq myfunc(dates[x])>
<cfset result.status = "fail">
<cfset result.message = "Your function said the DOW for #dateformat(dates[x])# was #myfunc(dates[x])# and it should be #dayofweek(dates[x])#">
<cfreturn result>
</cfif>
</cfloop>
<cfset result.status = "pass">
<cfreturn result>
</cffunction>
And as an example, check this one. It will fail - eventually.
<cfscript>
function mycheatfunc(d) {
if(dayofweek(d) == 7) return 8;
return dayofweek(d);
}
</cfscript>
<cfset res = testHarness(mycheatfunc)>
<cfdump var="#res#" label="The Result">
Unfortunately, I don't have anything to give away today - except the pride of being called King Nerd. So get cracking!