Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Abstract

This code snippet adds a certain number of days to a date excluding the weekends. Currently, when you add a certain number of days to a date the weekends are included. To exclude them, you can use this snippet.

...

Placeholder

Description

Example

<from>Date to which the number of days should be addednew Date()
<nod>Number of days to add22


Examples

The output of the code snippet is a Moment.js date object which you could use to:

  • Set a Date/Date-time picker field - Eg: Set the Due date to issue created plus 5 days excluding weekends in
    • one of the Set Field Value post-functions
    • in the Create issue post-function under Set fields of new issue section

      Code Block
      languagejs
      linenumberstrue
      {% macro add(from, nod) %}
      	{% set weeks = nod//5 %}
          {% set remDays = nod%5 %}
          
          {#- Adding the whole weeks #}
          {%- set from = from | date('add', weeks,'weeks') %}
          
          {#- Run a loop and check each day to skip a weekend #}
          {%- for i in range(0,remDays) %}
          {% set from = from | date('add',1,'d') | date %}
          {% if from | date('day') == "6" %}
                {% set from = from | date('add',1,'d') | date %}
            {% endif %}
            {% if from | date('day') == "0" %}
                {% set from = from | date('add',1,'d') | date %}
            {% endif %}
          {% endfor %}
          
          {#- Skipping the ending weekend #}
          {%- if from | date('day') == "6" %}
              {% set from = from | date('add',1,'d') %}
          {% endif %}
          {% if from | date('day') == "0" %}
              {% set from = from | date('add',1,'d') -%}
          {% endif -%}
          
          {#-Return the Momentjs#}
          {{-from | date}}  
      {% endmacro -%}
      {{add(issue.fields.created,5)}}
      


  • Notify the customer that the issue will be resolved in 6 days from today through the
    • Comment in one of the Comment issue post-functions
    • Subject/HTML body/Text body of Email issue post-function

      Code Block
      languagejs
      linenumberstrue
      {% macro add(from, nod) %}
      	{% set weeks = nod//5 %}
          {% set remDays = nod%5 %}
          
          {#- Adding the whole weeks #}
          {%- set from = from | date('add', weeks,'weeks') %}
          
          {#- Run a loop and check each day to skip a weekend #}
          {%- for i in range(0,remDays) %}
          {% set from = from | date('add',1,'d') | date %}
          {% if from | date('day') == "6" %}
                {% set from = from | date('add',1,'d') | date %}
            {% endif %}
            {% if from | date('day') == "0" %}
                {% set from = from | date('add',1,'d') | date %}
            {% endif %}
          {% endfor %}
          
          {#- Skipping the ending weekend #}
          {%- if from | date('day') == "6" %}
              {% set from = from | date('add',1,'d') %}
          {% endif %}
          {% if from | date('day') == "0" %}
              {% set from = from | date('add',1,'d') -%}
          {% endif -%}
          
          {#-Return the Momentjs#}
          {{-from | date}}  
      {% endmacro -%}
      Your issue will be resolved on or before: {{add(now,6)}}


...

Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "jmwe-nunjucks" and type = "page" and space = "KBJMWEC"
labelsjmwe-nunjucks jmwe-cloud

...