const MI_TO_KM = 1.609344; // exact, international mile function clock(totalMinutes) { let totalSeconds = Math.round(totalMinutes * 60); const hours = Math.floor(totalSeconds / 3600); totalSeconds -= hours * 3600; const minutes = Math.floor(totalSeconds / 60); const seconds = totalSeconds - minutes * 60; const pad = (n) => String(n).padStart(2, "0"); return `${hours}:${pad(minutes)}:${pad(seconds)}`; } module.exports = { slug: "running-pace-and-finish-time", title: "Running pace and finish time", deck_category: "health", description: "Computes finish time from distance and pace, and converts distance and pace between kilometers and miles using the exact international mile.", inputs: [ { name: "distance", type: "number", unit: "km or mi", required: true, description: "Race or run distance", min: 0 }, { name: "distance_unit", type: "string", required: true, description: "Unit of the distance value", enum: ["km", "mi"] }, { name: "pace_minutes_per_unit", type: "number", unit: "minutes per distance_unit", required: true, description: "Pace expressed in minutes per the given distance_unit", min: 0 } ], outputs: [ { name: "finish_time_minutes", unit: "minutes", description: "Total finish time in decimal minutes" }, { name: "finish_time_clock", unit: "h:mm:ss", description: "Total finish time formatted as hours:minutes:seconds" }, { name: "equivalent_distance", unit: "the other unit", description: "Distance converted to the other unit" }, { name: "equivalent_pace", unit: "minutes per the other unit", description: "Pace converted to the other unit" } ], steps: [ "finish_time_minutes = distance * pace_minutes_per_unit, rounded to 2 decimals.", "finish_time_clock converts finish_time_minutes to hours:minutes:seconds.", "If distance_unit is km: equivalent_distance (mi) = distance / 1.609344; equivalent_pace (min/mi) = pace_minutes_per_unit * 1.609344.", "If distance_unit is mi: equivalent_distance (km) = distance * 1.609344; equivalent_pace (min/km) = pace_minutes_per_unit / 1.609344.", "Round equivalent_distance and equivalent_pace to 2 decimals." ], constants: [ { name: "mi_to_km", value: 1.609344, unit: "km per mi", source: 0 } ], sources: [ { kind: "edition_page", value: "International Yard and Pound Agreement, 1959", title: "Exact statute mile to kilometer conversion factor", publisher: "NIST Handbook 44, Appendix C", retrieved_utc: "2026-09-30T19:40:00Z", note: "Defines 1 international mile = 1.609344 km exactly." } ], disclaimer: "General formula only. Not medical advice. Dosing decisions belong to a licensed clinician and the product's label.", questionText(inputs) { return `At a pace of ${inputs.pace_minutes_per_unit} minutes per ${inputs.distance_unit}, what is the finish time for ${inputs.distance} ${inputs.distance_unit}?`; }, run(inputs) { const { distance, distance_unit, pace_minutes_per_unit } = inputs; if (typeof distance !== "number" || distance <= 0) throw new Error("distance must be a positive number"); if (typeof pace_minutes_per_unit !== "number" || pace_minutes_per_unit <= 0) throw new Error("pace_minutes_per_unit must be a positive number"); if (distance_unit !== "km" && distance_unit !== "mi") throw new Error("distance_unit must be km or mi"); const finishRaw = distance * pace_minutes_per_unit; const finishTime = Math.round(finishRaw * 100) / 100; let equivDistanceRaw, equivPaceRaw; if (distance_unit === "km") { equivDistanceRaw = distance / MI_TO_KM; equivPaceRaw = pace_minutes_per_unit * MI_TO_KM; } else { equivDistanceRaw = distance * MI_TO_KM; equivPaceRaw = pace_minutes_per_unit / MI_TO_KM; } const equivDistance = Math.round(equivDistanceRaw * 100) / 100; const equivPace = Math.round(equivPaceRaw * 100) / 100; const otherUnit = distance_unit === "km" ? "mi" : "km"; const finishClock = clock(finishRaw); const answer = `Finish time ${finishClock} (${finishTime.toFixed(2)} min); equivalent ${equivDistance.toFixed(2)} ${otherUnit} at ${equivPace.toFixed(2)} min/${otherUnit}`; return { answer, values: { finish_time_minutes: finishTime, finish_time_clock: finishClock, equivalent_distance: equivDistance, equivalent_pace: equivPace } }; }, examples: [ { name: "worked example", inputs: { distance: 10, distance_unit: "km", pace_minutes_per_unit: 5 }, expected: { answer: "Finish time 0:50:00 (50.00 min); equivalent 6.21 mi at 8.05 min/mi" }, check: "10*5=50 min = 0:50:00. 10/1.609344=6.21371 rounds to 6.21. 5*1.609344=8.04672 rounds to 8.05." }, { name: "test vector: miles input", inputs: { distance: 13.1, distance_unit: "mi", pace_minutes_per_unit: 9 }, expected: { answer: "Finish time 1:57:54 (117.90 min); equivalent 21.08 km at 5.59 min/km" }, check: "13.1*9=117.9 min = 1 hr 57.9 min = 1:57:54 (0.9 min = 54 sec). 13.1*1.609344=21.08241 rounds to 21.08. 9/1.609344=5.5924 rounds to 5.59." } ] };