{
  "schemaVersion": 1,
  "slug": "drive-time-calculator",
  "category": "travel",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "93bce442f0c650f36999066ded3d20a58438a504d32c346a8b675d874fa30aff",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/drive-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 = d ÷ v + (max(0, ⌊d ÷ (v × b)⌋) × L + n × s) ÷ 60",
    "vars": [
      [
        "d",
        "Trip distance (mi)"
      ],
      [
        "v",
        "Average speed (mph)"
      ],
      [
        "b",
        "Break interval (h)"
      ],
      [
        "L",
        "Break length (min)"
      ],
      [
        "n",
        "Toll stops"
      ],
      [
        "s",
        "Minutes per toll stop"
      ],
      [
        "T",
        "Estimated duration (h)"
      ]
    ],
    "note": "Breaks = max(0, ceil(driving time ÷ interval) − 1); a break is counted only when driving continues after that interval. Arrival clock assumes 09:00, wraps at midnight and does not show a date. Fuel cost assumes 30 US mpg and $3.50 per US gallon."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const drivingHours = speed > 0 ? distance/speed : 0; const breaks = drivingHours > 0 ? Math.max(0, Math.ceil(drivingHours/(breakEvery || 2)) - 1) : 0; const breakTime = (breaks*breakLength+tolls*tollStopMinutes)/60; const totalHours = drivingHours+breakTime; const arrivalMinutes = ((Math.round((9+totalHours)*60)%1440)+1440)%1440; const arrivalClock = String(Math.floor(arrivalMinutes/60)).padStart(2,'0')+':'+String(arrivalMinutes%60).padStart(2,'0'); return { drivingHours, breaks, breakTime, totalHours, arrivalClock, fuelCost: distance/30*3.5 };",
    "inputs": [
      {
        "name": "distance",
        "type": "number",
        "default": 300,
        "min": 0.1,
        "max": 10000,
        "step": 1
      },
      {
        "name": "speed",
        "type": "number",
        "default": 55,
        "min": 5,
        "max": 120,
        "step": 1,
        "slider": true
      },
      {
        "name": "breakEvery",
        "type": "number",
        "default": 2,
        "min": 0.5,
        "max": 8,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "breakLength",
        "type": "number",
        "default": 20,
        "min": 0,
        "max": 120,
        "step": 5,
        "slider": true
      },
      {
        "name": "tolls",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 50,
        "step": 1,
        "slider": true
      },
      {
        "name": "tollStopMinutes",
        "type": "number",
        "default": 2,
        "min": 0,
        "max": 30,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "drivingHours",
        "precision": 2,
        "unit": "h"
      },
      {
        "name": "breaks",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "breakTime",
        "precision": 2,
        "unit": "h"
      },
      {
        "name": "totalHours",
        "precision": 2,
        "unit": "h"
      },
      {
        "name": "arrivalClock",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "fuelCost",
        "precision": 0,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
