<cfcomponent displayname="SecondTuesday" implements="DateIterator" extends="BaseDateIterator" hint="I iterate over every second Tuesday of the month between two dates."> <cffunction name="GetSecondTuesday" access="private" returntype="date" output="false" hint="I get the second tuesday of the month (for the given date)."> <!--- Define arguments. ---> <cfargument name="Date" type="numeric" required="true" hint="I am the date in the month for which we are getting the second Tuesday." /> <!--- Define the local scope. ---> <cfset var LOCAL = {} /> <!--- Get the first day in this month. ---> <cfset LOCAL.Month = CreateDate( Year( ARGUMENTS.Date ), Month( ARGUMENTS.Date ), 1 ) /> <!--- Get the second tuesday based on the first date of the month. ---> <cfif (DayOfWeek( LOCAL.Month ) GT 3)> <!--- Get second tuesday. ---> <cfreturn (LOCAL.Month + (8 - DayOfWeek( LOCAL.Month )) + 9) /> <cfelse> <!--- Return second tuesday. ---> <cfreturn (LOCAL.Month + (3 - DayOfWeek( LOCAL.Month )) + 7) /> </cfif> </cffunction> <cffunction name="SetNextDate" access="private" returntype="void" output="false" hint="I determine what the next valid date of iteration is."> <!--- Define the local scope. ---> <cfset var LOCAL = {} /> <!--- Check to see if we have a next date index yet. If not, then this is our intialization. If so, then we are already in the midst of the iteration. ---> <cfif NOT IsNumericDate( VARIABLES.NextDateIndex )> <!--- We are initializing our next date. ---> <!--- Get the second tuesday of the starting month. This may not be the Tuesday that we need, but it gives us a basis for iteration. ---> <cfset LOCAL.Tuesday = VARIABLES.GetSecondTuesday( VARIABLES.DateIndex ) /> <!--- Check to see if this first tuesday is before our start date. If so, then we need to start in the next month. ---> <cfif (VARIABLES.DateIndex LTE LOCAL.Tuesday)> <!--- Use this tuesday. ---> <cfset VARIABLES.NextDateIndex = LOCAL.Tuesday /> <cfelse> <!--- Use the tuesday of the next month. ---> <cfset VARIABLES.NextDateIndex = VARIABLES.GetSecondTuesday( DateAdd( "m", 1, LOCAL.Tuesday ) ) /> </cfif> <cfelse> <!--- We just iterated. Get the second tuesday of the next month. ---> <cfset VARIABLES.NextDateIndex = VARIABLES.GetSecondTuesday( DateAdd( "m", 1, VARIABLES.NextDateIndex ) ) /> </cfif> <!--- Return out. ---> <cfreturn /> </cffunction> </cfcomponent>