{
  "schemaVersion": 1,
  "slug": "add-time-calculator",
  "category": "date-time",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "286e914532ef0e170ab83fad2ee62f5f1a72bb7f9f0a883b2a3bdccbcab3eb53",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/add-time-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "t = (h₁×3600 + m₁×60 + s₁) ± (h₂×3600 + m₂×60 + s₂)",
    "vars": [
      [
        "t",
        "total time in seconds"
      ],
      [
        "h₁,m₁,s₁",
        "first time: hours, minutes, seconds"
      ],
      [
        "h₂,m₂,s₂",
        "second time: hours, minutes, seconds"
      ],
      [
        "±",
        "addition or subtraction"
      ]
    ],
    "note": "Displayed as H:MM:SS; a subtraction may give a negative result."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const t1 = hours1*3600 + minutes1*60 + seconds1;\nconst t2 = hours2*3600 + minutes2*60 + seconds2;\nconst total = Number(operation)===2 ? t1-t2 : t1+t2;\nconst neg = total < 0;\nconst abs = Math.abs(total);\nconst h = Math.floor(abs/3600), m = Math.floor((abs%3600)/60), s = abs%60;\nconst pad = (v)=> String(v).length<2 ? '0'+v : String(v);\nreturn { result: (neg?'-':'') + h + ':' + pad(m) + ':' + pad(s), decimalHours: total/3600, totalSeconds: total, hoursPart: h, minutesPart: m, secondsPart: s };",
    "inputs": [
      {
        "name": "hours1",
        "type": "number",
        "default": 1,
        "min": 0,
        "max": 100000,
        "step": 1
      },
      {
        "name": "minutes1",
        "type": "number",
        "default": 45,
        "min": 0,
        "max": 59,
        "step": 1,
        "slider": true
      },
      {
        "name": "seconds1",
        "type": "number",
        "default": 30,
        "min": 0,
        "max": 59,
        "step": 1,
        "slider": true
      },
      {
        "name": "hours2",
        "type": "number",
        "default": 2,
        "min": 0,
        "max": 100000,
        "step": 1
      },
      {
        "name": "minutes2",
        "type": "number",
        "default": 20,
        "min": 0,
        "max": 59,
        "step": 1,
        "slider": true
      },
      {
        "name": "seconds2",
        "type": "number",
        "default": 45,
        "min": 0,
        "max": 59,
        "step": 1,
        "slider": true
      },
      {
        "name": "operation",
        "type": "select",
        "default": 1,
        "options": [
          {
            "value": 1
          },
          {
            "value": 2
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "decimalHours",
        "precision": 4,
        "unit": "h"
      },
      {
        "name": "totalSeconds",
        "precision": 0,
        "unit": "s"
      },
      {
        "name": "hoursPart",
        "precision": 0,
        "unit": "h"
      },
      {
        "name": "minutesPart",
        "precision": 0,
        "unit": "min"
      },
      {
        "name": "secondsPart",
        "precision": 0,
        "unit": "s"
      }
    ],
    "interpret": null
  }
}
