addDaysSkippingWeekends Resulting in a Weekend Date

Issue #240 resolved
jtabatabai created an issue

I have run into an bug with the addDaysSkippingWeekends function where the resulting date is occurring on a Saturday. Here are the details.

  1. A user creates an issue and set a custom Date field, Date Discovered = 2/3/2016 (Wed)
  2. The following post function is applied upon creation of the issue; Field Due date will be assigned with the calculation result of the formula: addDaysSkippingWeekends({Date Discovered}, 3, EST) This feature will be run as user in field Current user.

  3. The is created with the following values; Due Date = 2/6/2016 (Saturday) Date Discovered = 2/3/2016 (Wednesday)

I verified the JIRA system time and date on the System Info page are correct. I am not sure why this is occurring. Have you seen this before? Can you please assist?

Comments (13)

  1. Fidel Castro Armario repo owner

    I have reproduced your use case and I have found that there is a bug in the function. But in my case when adding 3 days to 2th march 2016 (wednesday) I'm obtaining 5th march 2016 (saturday), which is incorrect. Correct value would be 7th march 2016 (monday).

    I'm assuming that you are mistakenly saying that you are obtaining 2/6/2016 (Saturday).

    As a workaround until the bug is fixed, you can use the following expression:

    addTimeSkippingWeekends({nnnnn}, 3 * {DAY} + 1, EST)
    

    replacing nnnnn with field code of Date Discovered.

    The workaround consist in adding 3 days plus 1 millisecond, which makes the calculation skip the weekend.

  2. Fidel Castro Armario repo owner

    The problem has been fixed in version 2.2.8_beta_1.

    Can you please confirm that this version fixes the problem in your particular case?

    Thanks.

  3. jtabatabai reporter

    It appears to have fixed the issue. Thanks for the very quick feedback and thank you for providing a very useful tool. JIRA Workflow Toolbox is amazing!

  4. jtabatabai reporter
    • changed status to open

    Looks like the problem has re-appeared in 2.2.8. :( The exact same scenario as before.

  5. Fidel Castro Armario repo owner

    Hi,

    I can't reproduce the problem. Using version 2.2.8 with the following post-function:

    post-function.png

    I obtain the following result:

    dates.png

    This is the expected behavior.

    Can you please tell me exactly which scenario are you using?

  6. jtabatabai reporter

    Fidel,

    I modified the post function to use addTimeSkippingWeekends instead of addDaysSkippingWeekends and it has resolved the problem. However, the function addDaysSkippingWeekends still exhibits the same error.

    Thanks, Jeff

  7. Fidel Castro Armario repo owner

    The behavior using addTimeSkippingWeekends() and addDaysSkippingWeekends() should be the same, since they share the same code. If the first one is working, it should be because I mistakenly added 1 to the expression.

    addTimeSkippingWeekends({nnnnn}, 3 * {DAY}, EST)
    

    is equivalent to

    addDaysSkippingWeekends({nnnnn}, 3, EST)
    

    The thing is that I actually fixed a bug present in version 2.2.7 which behaves as you described, and I can easily reproduce it in 2.2.7, and how it has been fixed in version 2.2.8.

    The difference is that I'm using LOCAL timezone in all my test, but when I use a timezone different from LOCAL (i.e., the one set in the server), it doesn't work correctly, and also behaves as you describe. It should be related with the way JIRA stores date in Date Picker fields (which are rounded to 12:00 AM in server's timezone).

    You are using EST in your expression, but this timezone in summer is used by very few regions in the world. It's very probable that your server is using DST instead, which is similar to EST but observes daylight saving time/summer time during the summer.

    Anyway, I think that the better option is to use LOCAL instead of concrete timezone, this way you are sure that you are using your server's timezone.

    Can you please, try it and let me know if it solves your problem?

  8. jtabatabai reporter

    You are correct, that appears to be the root cause of the issue. I first tested by using;

    addDaysSkippingWeekends({nnnnn}, 3, EST)
    

    This exhibited the behavior with the Due Date set to Friday

    Then I tried;

    addDaysSkippingWeekends({nnnnn}, 3, LOCAL)
    

    And the Due Date was correctly set to Monday.

    Thanks again for all of your help and for a great Add-On! I think you can mark this one as Closed (again)

  9. Fidel Castro Armario repo owner

    Hi @jebteb,

    Since version 2.2.39, JIRA Workflow Toolbox supports Custom Schedules, and you can do all you are doing now using addTimeSkippingWeekends () and subtractDatesSkippingWeekends () functions, and much much more.

    I recommend you to take a look at it. You will be able to do amazing things using it.

  10. jtabatabai reporter

    Fidel,

    Your timing is impeccable! I am working on a new JIRA Workflow and was asked if it was possible to take holidays into account. The Custom Schedule feature will do the trick nicely! Thanks for the great product!!!

    Best regards, Jeff Tabatabai [Hill small] Director of Operations 2650 S. Mellonville Ave | Sanford, Florida | 32773 tel: 407.323.1887

  11. Fidel Castro Armario repo owner

    Hi @jebteb,

    Thanks for feedback. Please, consider sharing your experience with custom schedules in a review at the marketplace.

    It's a very new feature that will be very valuable to many users, but needs to be known.

    Thank you.

  12. Log in to comment