business day calculation causing errors in verion3.1 only

Hi guys,

I’ve been wanting to migrate my solution from 2.2.7 over to 3.1. We discovered that my business day calculation fields are causing servoy 3.1 (even developer) to lock up. Using up 100% CPU. i have to force quit the software. someone please guide me how to correctly make this code 3.1 compatible. I just need to calculate +10 business days from the issue date (another field)

thanks!
sammy

Here’s my code that works perfectly fine in servoy 2.2.7:

var oldDate = a_date_issued;

if (oldDate == null) {
return null
}

var newDate = new Date();
newDate.setYear(oldDate.getYear());
newDate.setMonth(oldDate.getMonth());
newDate.setDate(oldDate.getDate());

switch( oldDate.getDay() )
{
case 0 :
newDate.setDate(oldDate.getDate() + 12);
break;
case 6 :
newDate.setDate(oldDate.getDate() + 13);
break;
default:
newDate.setDate(oldDate.getDate() + 14);
};

return newDate;

This same code works fine in my developer.
Where are you calling the method from? Maybe there is some infinite recursion occurring.

You could also create a case on our support site and include a small sample solution.

Rob

rgansevles:
This same code works fine in my developer.
Where are you calling the method from? Maybe there is some infinite recursion occurring.

You could also create a case on our support site and include a small sample solution.

Rob

Sorry for the confusion, but this is not a method. it’s actually a stored CALCULATED field

For some reason, Servoy recalculates the value when a new value is calculated what happens every time because the ‘new Date()’ generates a date value that differs in milisecs with the previous value.

A workaround for you is the code below, it reuses the date object resulting in the same value every time for the same input value.

var oldDate = a_date_issued;

if (oldDate == null) {
return null
}

var newDate = oldDate;

switch( oldDate.getDay() )
{
case 0 :
newDate.setDate(oldDate.getDate() + 12);
break;
case 6 :
newDate.setDate(oldDate.getDate() + 13);
break;
default:
newDate.setDate(oldDate.getDate() + 14);
};

return newDate;

This works. Thanks!!!

rgansevles:
For some reason, Servoy recalculates the value when a new value is calculated what happens every time because the ‘new Date()’ generates a date value that differs in milisecs with the previous value.

A workaround for you is the code below, it reuses the date object resulting in the same value every time for the same input value.

var oldDate = a_date_issued;

if (oldDate == null) {
return null
}

var newDate = oldDate;

switch( oldDate.getDay() )
{
case 0 :
newDate.setDate(oldDate.getDate() + 12);
break;
case 6 :
newDate.setDate(oldDate.getDate() + 13);
break;
default:
newDate.setDate(oldDate.getDate() + 14);
};

return newDate;