Search code examples
lotus-noteslotuslotus-formula

Unexpected @Adjust formula behaviour


I've got a task, to calculate end date of validity period for an object.

Let's say start date of validity is: 18 Sept. 2014

Validity period (for example) is: 3 months

End date (last date when object is still valid, + 3 months and -1 day): 17 Dec 2014

Looks correct, and to calcuate end date I used the following @-formula:

@Adjust(start; 0; 3; -1; 0; 0; 0);

where I add 3 months and decrease 1 day from the start date.

But when I set start date as 01 Oct. 2014 I get end date 30 Dec 2014 instead of 31 Dec 2014.

Looks strange and looks like a bug in the Lotus Notes engine.


Solution

  • The solution was a bit unexpected and simple.

    @Adjust function evaluates it's parameters from right to left.

    In other words it decreases 1 day and then adds 3 months to the start date.

    And if start date is 01 Oct 2014, then @Adjust formula gets 30 Sept. 2014 by adding -1 day and then adds 3 months and get 30 Dec 2014.

    And to solve this issue I needed to change the initial formula:

    to

    temp_ := @Adjust(start; 0; 3; 0; 0; 0; 0);
    @Adjust(temp_; 0; 0; -1; 0; 0; 0);
    

    temp_ variable gets start date increased to 3 months, and only after that we decrease 1 day from the calculation result.