{"record":{"id":"eca8b38bbabea06d","repo":"Lightning-AI/pytorch-lightning","slug":"timer-duration-duration-r-is-not-a-valid-dura","errorCode":null,"errorMessage":"`Timer(duration={duration!r})` is not a valid duration. Expected a string in the format DD:HH:MM:SS.","messagePattern":"`Timer\\(duration=(.+?)\\)` is not a valid duration\\. Expected a string in the format DD:HH:MM:SS\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/timer.py","lineNumber":94,"sourceCode":"\n        # query training/validation/test time (in seconds)\n        timer.time_elapsed(\"train\")\n        timer.start_time(\"validate\")\n        timer.end_time(\"test\")\n\n    \"\"\"\n\n    def __init__(\n        self,\n        duration: Optional[Union[str, timedelta, dict[str, int]]] = None,\n        interval: str = Interval.step,\n        verbose: bool = True,\n    ) -> None:\n        super().__init__()\n        if isinstance(duration, str):\n            duration_match = re.fullmatch(r\"(\\d+):(\\d\\d):(\\d\\d):(\\d\\d)\", duration.strip())\n            if not duration_match:\n                raise MisconfigurationException(\n                    f\"`Timer(duration={duration!r})` is not a valid duration. \"\n                    \"Expected a string in the format DD:HH:MM:SS.\"\n                )\n            duration = timedelta(\n                days=int(duration_match.group(1)),\n                hours=int(duration_match.group(2)),\n                minutes=int(duration_match.group(3)),\n                seconds=int(duration_match.group(4)),\n            )\n        elif isinstance(duration, dict):\n            duration = timedelta(**duration)\n        if interval not in set(Interval):\n            raise MisconfigurationException(\n                f\"Unsupported parameter value `Timer(interval={interval})`. Possible choices are:\"\n                f\" {', '.join(set(Interval))}\"\n            )\n        self._duration = duration.total_seconds() if duration is not None else None\n        self._interval = interval","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/timer.py#L76-L112","documentation":"Timer accepts a duration either as a timedelta/dict or as a string that must match DD:HH:MM:SS exactly (regex fullmatch of digits:2digits:2digits:2digits). Any other string format raises this MisconfigurationException in __init__.","triggerScenarios":"Timer(duration='90:00') (MM:SS), '1 day', '00:30:00' (HH:MM:SS, 3 groups instead of 4), or leading/trailing content that isn't strictly DD:HH:MM:SS.","commonSituations":"Assuming a friendlier duration parser (ISO8601, '2h'); writing hours:minutes:seconds and forgetting the days field.","solutions":["Use full DD:HH:MM:SS format, e.g. Timer(duration='00:01:30:00') for 1h30m","Or pass a timedelta: Timer(duration=datetime.timedelta(minutes=90))","Or pass a dict: Timer(duration={'minutes': 90})"],"exampleFix":"# before\ntimer = Timer(duration=\"01:30:00\")\n# after\nfrom datetime import timedelta\ntimer = Timer(duration=timedelta(hours=1, minutes=30))\n# or Timer(duration=\"00:01:30:00\")","handlingStrategy":"validation","validationCode":"import re\nfrom datetime import timedelta\n\ndef parse_duration(s):\n    if isinstance(s, str):\n        if not re.fullmatch(r'(\\d+):(\\d\\d):(\\d\\d):(\\d\\d)', s.strip()):\n            return timedelta(**{})  # fall back: reject early with your own error\n    return s\n# simplest: build timedelta directly\nTimer(duration=timedelta(hours=1, minutes=30))","typeGuard":"def is_valid_timer_str(s: str) -> bool:\n    import re\n    return bool(re.fullmatch(r'(\\d+):(\\d\\d):(\\d\\d):(\\d\\d)', s.strip()))","tryCatchPattern":null,"preventionTips":["Prefer timedelta or dict duration over string parsing","Remember the string format always includes days: DD:HH:MM:SS"],"tags":["timer","duration-format","validation","callback"],"backgroundTag":"invalid-duration-format","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}