{
  "schemaVersion": 1,
  "slug": "time-duration-calculator",
  "category": "date-time",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "51c53ec5b07f9252541e54eedf9b73f5a97e06ac298161d442bee67055b6865f",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/time-duration-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": "M₀ = (60h₂ + m₂) − (60h₁ + m₁); M = { M₀, M₀ ≥ 0; M₀ + 1440, M₀ < 0 }; D = M ÷ 1440 × 100%",
    "vars": [
      [
        "M,M₀",
        "Duration in minutes; raw difference before wrap"
      ],
      [
        "h₁,m₁",
        "Start hour, minute"
      ],
      [
        "h₂,m₂",
        "End hour, minute"
      ],
      [
        "D",
        "Share of day (%)"
      ]
    ],
    "note": "When the end time is earlier, 1440 minutes are added (past-midnight wrap)."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const parse=(s)=>{const m=/^(\\d{1,2}):(\\d{2})$/.exec(String(s).trim());if(!m)return null;const h=+m[1],mi=+m[2];if(h>23||mi>59)return null;return h*60+mi;}; const a=parse(startTime),b=parse(endTime); if(a===null||b===null) return { hours: null, minutes: null, seconds: null, duration: null, percentageOfDay: null, __error: 'inputError' }; let mins=b-a;if(mins<0)mins+=1440;return {hours:mins/60,minutes:mins,seconds:mins*60,duration:Math.floor(mins/60)+'h '+(mins%60)+'m',percentageOfDay:mins/1440*100};",
    "inputs": [
      {
        "name": "startTime",
        "type": "text",
        "default": "08:15",
        "step": 1
      },
      {
        "name": "endTime",
        "type": "text",
        "default": "16:45",
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "hours",
        "precision": 3,
        "unit": "h"
      },
      {
        "name": "minutes",
        "precision": 0,
        "unit": "min"
      },
      {
        "name": "seconds",
        "precision": 0,
        "unit": "s"
      },
      {
        "name": "duration",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "percentageOfDay",
        "precision": 2,
        "unit": "%"
      }
    ],
    "interpret": null
  }
}
