To clarify what it is you're trying to accomplish, cycle 1405 includes the dates 1 - 28 May 2014, excluding 29 May; and cycle 1406 includes 29 May - 25 June 2014, excluding 26 June, right?
In general, calculating things based on periodic cycles usually involves modular arithmetic. Ignoring the code you're starting from (which looks like a mess to me, too), this calculation is working for me to get the cycle number from a $date:
Let ( [
_cycleOffset = Mod ( $date + 10 ; 28 ) ;
_cycle = Floor ( ( $date - _cycleOffset ) / 28 ) - 24857
And inverting that gives this calculation to get the start and end dates for a given $cycle:
Let ( [
_cycleStartDate = GetAsDate ( ( $cycle + 24857 ) * 28 + 18 ) ;
_cycleEndDate = _cycleStartDate + 27
List ( _cycleStartDate ; _cycleEndDate )
This is way more then I had hope for, works great. thank you for your help.