{"record":{"id":"41a925e6989d056d","repo":"geekcomputers/Python","slug":"format-must-be-hh-mm-ss","errorCode":null,"errorMessage":"Format must be HH:MM:SS","messagePattern":"Format must be HH:MM:SS","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"Timetable_Operations.py","lineNumber":42,"sourceCode":"    sec1 = h1 * 3600 + m1 * 60 + s1\n    sec2 = h2 * 3600 + m2 * 60 + s2\n    diff = sec2 - sec1\n    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)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/Timetable_Operations.py#L24-L60","documentation":"This ValueError is raised by the Tkinter calculate callback in this clock-difference tool when one of the two time strings is not exactly in HH:MM:SS form: the string must be 8 characters long with ':' at positions 2 and 5 (e.g., '09:30:00'). It is a strict shape check performed before the hour/minute/second components are parsed, and the caught exception is shown to the user via messagebox.showerror.","triggerScenarios":"Entering '9:30:00' (missing leading zero), '09:30' (no seconds), '09-30-00', an empty field, or extra whitespace beyond what .strip() removes (e.g., '09:30:00 '). Any input where len(t) != 8 or the colons are misplaced triggers it.","commonSituations":"Users typing times without zero-padding, pasting times from other apps with different formats, omitting seconds, or leaving a field blank; also locales that produce '9:5:0'.","solutions":["Enter both times in exact HH:MM:SS format with leading zeros, e.g., 09:30:00","Normalize input before submission: pad components with zfill(2) and validate with a regex like ^\\d{2}:\\d{2}:\\d{2}$","Do not paste times with extra characters or spaces"],"exampleFix":"# before\nentry_t1.get() == '9:30:00'  # triggers error\n\n# after\nimport re\nraw = entry_t1.get().strip()\nparts = raw.split(':')\nraw = ':'.join(p.zfill(2) for p in parts)\nassert re.fullmatch(r'\\d{2}:\\d{2}:\\d{2}', raw)","handlingStrategy":"validation","validationCode":"import re\nTIME_RE = re.compile(r'^\\d{2}:\\d{2}:\\d{2}$')\nt1, t2 = entry_t1.get().strip(), entry_t2.get().strip()\nif all(TIME_RE.fullmatch(t) for t in (t1, t2)):\n    calculate()","typeGuard":"def is_hhmmss(t: str) -> bool:\n    import re\n    return bool(re.fullmatch(r'\\d{2}:\\d{2}:\\d{2}', t))","tryCatchPattern":"try:\n    calculate()\nexcept ValueError as e:\n    messagebox.showerror('Invalid input', str(e))","preventionTips":["Validate with a strict regex before invoking the callback","Normalize single-digit components with zfill(2)","Use masked/regentry widgets that enforce the HH:MM:SS mask"],"tags":["python","tkinter","time-format","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"}