{"record":{"id":"bff4d9d872ab1f1a","repo":"geekcomputers/Python","slug":"time-out-of-range","errorCode":null,"errorMessage":"Time out of range","messagePattern":"Time out of range","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"Timetable_Operations.py","lineNumber":45,"sourceCode":"    if diff < 0:\n        diff += 24 * 3600\n    h = diff // 3600\n    m = (diff % 3600) // 60\n    s = diff % 60\n    return f\"{h:02}:{m:02}:{s:02}\"\n\n\ndef calculate() -> None:\n    \"\"\"Tkinter callback to calculate and display clock difference.\"\"\"\n    t1 = entry_t1.get().strip()\n    t2 = entry_t2.get().strip()\n    try:\n        for t in [t1, t2]:\n            if len(t) != 8 or t[2] != \":\" or t[5] != \":\":\n                raise ValueError(\"Format must be HH:MM:SS\")\n            h, m, s = int(t[0:2]), int(t[3:5]), int(t[6:8])\n            if not (0 <= h < 24 and 0 <= m < 60 and 0 <= s < 60):\n                raise ValueError(\"Time out of range\")\n        result = clock_diff(t1, t2)\n        label_result.config(text=f\"Difference: {result}\")\n    except Exception as e:\n        messagebox.showerror(\"Error\", f\"Invalid input!\\n{e}\")\n\n\nroot = tk.Tk()\nroot.title(\"Clock Difference Calculator\")\nroot.geometry(\"300x200\")\n\ntk.Label(root, text=\"Init schedule (HH:MM:SS):\").pack(pady=5)\nentry_t1 = tk.Entry(root)\nentry_t1.pack()\n\ntk.Label(root, text=\"Final schedule (HH:MM:SS):\").pack(pady=5)\nentry_t2 = tk.Entry(root)\nentry_t2.pack()\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Timetable_Operations.py#L27-L63","documentation":"This ValueError is raised by the Tkinter calculate callback after the HH:MM:SS shape check passes but the parsed components are out of calendar range: hours must satisfy 0 <= h < 24, minutes 0 <= m < 60, seconds 0 <= s < 60. It catches semantically impossible times like 25:00:00 or 12:61:00 that are shape-valid but not real clock times, and is displayed to the user via messagebox.showerror.","triggerScenarios":"Entering '24:00:00' (24 is rejected; use 00:00:00), '12:75:00', '09:30:99', or any well-formatted string whose component exceeds its bound. Note the int() parse of e.g. '0x' would raise a different ValueError caught by the same handler.","commonSituations":"Users entering 24 for midnight, typos in minutes/seconds, or times computed programmatically (e.g., adding durations) that overflow component bounds without carry normalization.","solutions":["Enter valid times: hours 00-23, minutes 00-59, seconds 00-59; use 00:00:00 for midnight","If computing times programmatically, normalize with divmod carry (s//60 etc.) or datetime arithmetic before display","Add a dropdown/spinbox constrained to valid ranges instead of free text"],"exampleFix":"# before\n# user enters 24:15:30 -> error\n\n# after\nfrom datetime import datetime, timedelta\nt = (datetime(2000,1,1) + timedelta(hours=24, minutes=15)).strftime('%H:%M:%S')  # '00:15:00'","handlingStrategy":"validation","validationCode":"def valid_time(t):\n    h, m, s = int(t[0:2]), int(t[3:5]), int(t[6:8])\n    return 0 <= h < 24 and 0 <= m < 60 and 0 <= s < 60\nif valid_time(t1) and valid_time(t2):\n    calculate()","typeGuard":"def is_valid_clock_time(t: str) -> bool:\n    import re\n    if not re.fullmatch(r'\\d{2}:\\d{2}:\\d{2}', t):\n        return False\n    h, m, s = map(int, t.split(':'))\n    return 0 <= h < 24 and 0 <= m < 60 and 0 <= s < 60","tryCatchPattern":"try:\n    calculate()\nexcept ValueError as e:\n    messagebox.showerror('Out of range', str(e))","preventionTips":["Use 00:00:00 for midnight, never 24:00:00","Normalize programmatically computed times with datetime/timedelta before display","Prefer spinboxes or time pickers bounded to valid ranges"],"tags":["python","tkinter","time-range","input-validation","gui"],"backgroundTag":"input-format-validation-failed","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}