Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 2480 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi CFD, longtime user, first time builder!

I need to build a list of dates, from a starting date, up to the 1st of the month after Get ( CurrentDate ).
Each date will start on the 1st, and will spaced by an interval of so many months.

EXAMPLE
ƒ serviceSchedule ( Date ( 5 ; 1 ; 2017 ) ; 1 )    //monthly
= 5/1/2017, 6/1/2017, 7/1/2017, 8/1/2017, 9/1/2017, 10/1/2017, 11/1/2017, 12/1/2017, 1/1/2018, 2/1/2018, 3/1/2018

ƒ serviceSchedule ( Date ( 5 ; 1 ; 2017 ) ; 3 )   //quarterly
= 7/1/2017, 10/1/2017, 1/1/2018

 

I have the loop start on January of the startDate year, and loop from there.  I do get the results but the behavior of the CF is peculiar, which I am guess might be use of local variables ($).  

Attached is a test file, try the function in the data viewer and note that you have to click evaluation twice to get the result.

 

 

// serviceSchedule ( startDate ; interval )


Case (

	// Initialize
	not $loopStopDate ;
  
	Let ( [

		$itvl = interval ;
		$sd = startDate ;
		$startYear = Year ($sd) ;
		$cd = Get ( CurrentDate ) ;
		$loopStopDate = Date ( Month($cd)+1 ; 1 ; Year($cd) ) ;
		$loopInterval = 1 ;

		$dte = Date ( 1 ; 1 ; $startYear ) 
  
	];

		serviceSchedule ( $dte ; $itvl )
  
	) ;



	// Ignore and up date
	startDate < $sd ;
	
	Let ( [

		$dte = Date ( 0 + $loopInterval ; 1 ; $startYear ) ;
		$loopInterval = $loopInterval + $itvl

	];

		serviceSchedule ( $dte ; $itvl )
 
	) ;



	// Add to array up date
	startDate < $loopStopDate ;
	
	Let ( [

		$array = case ( isEmpty ($array) ; "" ; $array & "¶" ) & $dte  ; 
		$dte = Date ( 0 + $loopInterval ; 1 ; $startYear ) ;
		$loopInterval = $loopInterval + $itvl

	];

		serviceSchedule ( $dte ; $itvl )
 
	) ;



 	 // END
	startDate > $loopStopDate ;
	
	Let ( [
		result = $array ;

		$array = "" ;
		$cd  = "" ;
		$dte = "" ;
		$itvl = "" ;
		$loopInterval = "" ;
		$loopStopDate = "" ;
		$sd = "" ;
		$startYear = "" 

     ];

		result 

     )


)

 

serviceSchedule.zip

Posted

That seems unnecessarily complicated. You just need to feed the date + the interval back into the function:

// serviceSchedule ( startDate ; interval )
 

Let ( [
    cd = Get ( CurrentDate ) ;
    stopDate = Date ( Month(cd)+1 ; 1 ; Year(cd) ) ;
    startDate = Date ( Month( startDate ) ; 1 ; Year(startDate) )
    ];

If ( startDate <= stopDate ;
    List( startDate ;
    serviceSchedule (  Date ( Month( startDate ) + interval ; 1 ; Year(startDate) ) ; interval ) ) ; "" )

  )

 

Posted (edited)

Thanks Fitch for taking a look at this.  I sensed it might be over built but I still need an extra step.   The schedules are monthly, bi-monthly and quarterly.  So I would only want to start the list once the calculated date is on or after startDate.

i.e. startDate of May1
monthly schedule would start month 5 and onward
quarterly schedule would start month 7 and onward.

 

 

 

Edited by rivet
Posted

There might be a more elegant solution, but try this:

Let ( [
    cd = Get ( CurrentDate ) ;
    stopDate = Date ( Month(cd)+1 ; 1 ; Year(cd) ) ;
    mb = Choose( Month( startDate ) ; "" ; 1 ; 3 ; 3 ; 5 ; 5 ; 7 ; 7 ; 9 ; 9 ; 11 ; 11 ; 1 ) ;  // bimonthly
    mq = Choose( Month( startDate ) ; "" ; 1 ; 4 ; 4 ; 4 ; 7 ; 7 ; 7 ; 10 ; 10 ; 10 ; 1 ; 1 ) ;  // quarterly
    m = Choose( interval ; "" ;  Month( startDate ) ; mb ; mq ) ;
    startDate = Date ( m ; 1 ; Year(startDate) )
    ];

If ( startDate <= stopDate ;
    List( startDate ;
    serviceSchedule (  Date ( Month( startDate ) + interval ; 1 ; Year(startDate) ) ; interval ) ) ; "" )

  )

 

This topic is 2480 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.