Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

custom function strange behavior

Featured Replies

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

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 ) ) ; "" )

  )

 

  • Author

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

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 ) ) ; "" )

  )

 

  • Author

I will give it a try, thanks again.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.