Calculate Planned End Date based on Initial Estimate or Effort

📘

How to apply this rule?

Calculate Planned End Date based on Initial Estimate and Planned Start Date

👍

The rule converts Initial Estimate to working days (weekends are not included)

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "feature",
      "epic"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "InitialEstimate",
        "PlannedStartDate"
      ]
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "InitialEstimate",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": {
              "type": "constant",
              "value": 0
            },
            "operator": {
              "type": ">"
            }
          },
          {
            "target": {
              "type": "field",
              "name": "PlannedStartDate",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": null,
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "//8 ideal hours or points -> 1 wokring day\nlet daysToAdd = args.Current.InitialEstimate / 8;\n\nvar date = new Date(args.Current.PlannedStartDate);\n\nconst dow = date.getDay();\nif (dow === 0) { daysToAdd++; }\n\n// If the start date plus the additional days falls on or after the closest Saturday calculate weekends\nif (dow + daysToAdd >= 6) {\n  //Subtract days in current working week from work days\n  var remainingWorkDays = daysToAdd - (5 - dow);\n  //Add current working week's weekend\n  daysToAdd += 2;\n  if (remainingWorkDays > 5) {\n    //Add two days for each working week by calculating how many weeks are included\n    daysToAdd += 2 * Math.floor(remainingWorkDays / 5);\n    //Exclude final weekend if remainingWorkDays resolves to an exact number of weeks\n    if (remainingWorkDays % 5 === 0)\n      daysToAdd -= 2;\n  }\n}\n\ndate.setDate(date.getDate() + daysToAdd);\n\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: args.ResourceType,\n    resourceId: args.ResourceId,\n    fields:\n    {\n      PlannedEndDate: date\n    }\n  }\n};"
  }
]

Calculate Planned End Date based on Effort and Planned Start Date

👍

The rule converts Effort to working days (weekends are not included)

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "userstory"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "PlannedStartDate",
        "Effort"
      ]
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Effort",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": {
              "type": "constant",
              "value": 0
            },
            "operator": {
              "type": ">"
            }
          },
          {
            "target": {
              "type": "field",
              "name": "PlannedStartDate",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": null,
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "//8 ideal hours or points -> 1 wokring day\nlet daysToAdd = args.Current.Effort / 8;\n\nvar date = new Date(args.Current.PlannedStartDate);\n\nconst dow = date.getDay();\nif (dow === 0) { daysToAdd++; }\n\n// If the start date plus the additional days falls on or after the closest Saturday calculate weekends\nif (dow + daysToAdd >= 6) {\n  //Subtract days in current working week from work days\n  var remainingWorkDays = daysToAdd - (5 - dow);\n  //Add current working week's weekend\n  daysToAdd += 2;\n  if (remainingWorkDays > 5) {\n    //Add two days for each working week by calculating how many weeks are included\n    daysToAdd += 2 * Math.floor(remainingWorkDays / 5);\n    //Exclude final weekend if remainingWorkDays resolves to an exact number of weeks\n    if (remainingWorkDays % 5 === 0)\n      daysToAdd -= 2;\n  }\n}\n\ndate.setDate(date.getDate() + daysToAdd);\n\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: args.ResourceType,\n    resourceId: args.ResourceId,\n    fields:\n    {\n      PlannedEndDate: date\n    }\n  }\n};"
  }
]