Learning ColdFusion 8: Javascript Object Notation (JSON) Part II - Remote Method Calls

<cfcomponent
	output="false"
	hint="Date/time utility functions.">
 
 
	<cffunction
		name="GetWeekDates"
		access="remote"
		returntype="struct"
		returnformat="JSON"
		output="false"
		hint="Given a date, it will return all dates in that week in a day-keyed struct.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Date"
			type="date"
			required="false"
			default="#Now()#"
			/>
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
		<!--- Get first day of week. --->
		<cfset LOCAL.Sunday = (
			Fix( ARGUMENTS.Date ) -
			DayOfWeek( ARGUMENTS.Date ) +
			1
			) />
 
		<!--- Create week object. --->
		<cfset LOCAL.Week = {
			Sunday = LOCAL.Sunday,
			Monday = (LOCAL.Sunday + 1),
			Tuesday = (LOCAL.Sunday + 2),
			Wednesday = (LOCAL.Sunday + 3),
			Thursday = (LOCAL.Sunday + 4),
			Friday = (LOCAL.Sunday + 5),
			Saturday = (LOCAL.Sunday + 6)
			} />
 
 
		<!---
			At this point, we have the Week object filled with
			numeric date (data conversion caused from the date
			math we are using. Let's loop over the struct and
			convert these back to actual dates). This is vital
			since we might be returning this remotely to a
			system that has a differen "Zero Date" on which our
			numeric date conversions are based.
		--->
		<cfloop
			item="LOCAL.Day"
			collection="#LOCAL.Week#">
 
			<!---
				Convert back to standard, ColdFusion date/time
				formatting (that can be parsed by remote system.
			--->
			<cfset LOCAL.Week[ LOCAL.Day ] = CreateDate(
				Year( LOCAL.Week[ LOCAL.Day ] ),
				Month( LOCAL.Week[ LOCAL.Day ] ),
				Day( LOCAL.Week[ LOCAL.Day ] )
				) />
 
		</cfloop>
 
		<!--- Return week. --->
		<cfreturn LOCAL.Week />
	</cffunction>
 
 
</cfcomponent>

For Cut-and-Paste