2 Replies Latest reply on May 25, 2014 9:51 AM by keith.r

# 28 day cycle

I’m trying to deconstruct this code (JaveScript?) so I can attempt to replicate in FMP. Its a 28 day cycle which results in:

1405 – effective 01 MAY 2014 to 29 MAY 2014

So if today is May 24, 2014, the current cycle is 1405 (the 5th 28th day cycle of 2014). The next cycle is: 1406 – effective 29 MAY 2014 to 26 JUN 2014

Code:

{{padleft:{{#expr:((({{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}}-2454483+364)/364)-0.5 round 0)+7}}|2}}{{padleft:{{#expr:((({{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}}-2454483+28)/28)-0.5 round 0)-(((({{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}}-2454483+364)/364)-0.5 round 0)-1)*13}}|2}} – effective {{uc:{{#time:d M Y|{{JULIANDAY.TIMESTAMP|{{#expr:(((({{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}}-2454483+28)/28)-0.5 round 0)-1)*28+2454483}}}}}}}} to {{uc:{{#time:d M Y|{{JULIANDAY.TIMESTAMP|{{#expr:(((({{JULIANDAY|{{CURRENTYEAR}}|{{CURRENTMONTH}}|{{CURRENTDAY}}}}-2454483+28+(28*1))/28)-0.5 round 0)-1)*28+2454483}}}}}}}}

So I’ve figure out the equivalents.

JULIANDAY = DayOfYear (not sure on this)

CURRENTYEAR = Year

CURRENTMONTH = Month

CURRENTDAY = Day

These have me scratching my head what to do with. Not sure if it’s part of the html or equation

#expr

| <-pipe?

Any insight you can share would be much appreciated. Thanks!

• ###### 1. Re: 28 day cycle

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

] ;

_cycle

)

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 )

)

• ###### 2. Re: 28 day cycle

This is way more then I had hope for, works great. thank you for your help.

keith