• Resolved eabonie

    (@eabonie)


    I have added some invalid dates into the date-picker and also excluded weekends.

    When I calculate C.date + 2….,

    lets say C.date is Friday, it gives me Tuesday…so its correct, as it doesn’t include the weekends.

    However, now I have added Monday as an invalid date, so running the same equation should give me result = Wednesday, but it doesn’t.

    It still gives me Tuesday, meaning that it hasn’t removed the invalid dates from the equation.

    How can I make sure it removes invalid dates from equations?

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    There are two different fields in your ticket, the date/time fields, and the calculated fields, the invalid dates and weekends are related only to the date/time fields, and not the calculated ones, so, you should check the weekends from the equation.

    For example, if the date/time field is the fieldname1, and the fieldname2 is an number field for the number of days, the equation associated to the calculated field would be similar to:

    (function(){
    var d = new Date(fieldname1*86400000), c = 0;
    while(c < fieldname2)
    {
    d.setDate(d.getDate()+1);
    if(d.getDay() != 0 || d.getDay() != 6) c++;
    }
    
    return CDATE(FLOOR(d/86400000), 'mm/dd/yyyy');
    })()

    If you need additional help implementing your project, I can offer you a custom coding service through my personal website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter eabonie

    (@eabonie)

    Thanks for your speedy reply.

    The code above works …. that is to say it will produce the new date

    That is new date – or + (fieldname value) = new date

    The new date takes into account the fact that weekends are invalid so does not add them to the count…..however, it still counts the invalid dates that I have set.

    How can I make sure that the invalid dates are treated just like invalid weekends (as ticked in the field settings) during a calculation?

    Thanks

    Plugin Author codepeople

    (@codepeople)

    Hello,

    As I said previously the equations are independent of the date/time fields, even if you are assigning the calculated date to the date/time field programmatically (the equation associated to the calculated field is who determines the next date). So, in the previous equation, you should check the date against the list of invalid dates, for example, if the invalid dates are:

    07/23/2017 and 09/30/2017

    The piece of code:

    if(d.getDay() != 0 && d.getDay() != 6) c++;

    should be modified as follows:

    if(d.getDay() != 0 && d.getDay() != 6 && jQuery.inArray(CDATE(FLOOR(d/86400000), 'mm/dd/yyyy'), ['07/23/2017', '09/30/2017']) == -1) c++;

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calculations with invalid dates’ is closed to new replies.