{"record":{"id":"b894afdef827343e","repo":"python/cpython","slug":"day-of-the-year-directive-j-is-not-compatible-w","errorCode":null,"errorMessage":"Day of the year directive '%j' is not compatible with ISO year directive '%G'. Use '%Y' instead.","messagePattern":"Day of the year directive '(.+?)' is not compatible with ISO year directive '%G'\\. Use '%Y' instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/_strptime.py","lineNumber":737,"sourceCode":"            # it can be something other than -1.\n            found_zone = found_dict['Z'].lower()\n            for value, tz_values in enumerate(locale_time.timezone):\n                if found_zone in tz_values:\n                    # Deal with bad locale setup where timezone names are the\n                    # same and yet time.daylight is true; too ambiguous to\n                    # be able to tell what timezone has daylight savings\n                    if (time.tzname[0] == time.tzname[1] and\n                       time.daylight and found_zone not in (\"utc\", \"gmt\")):\n                        break\n                    else:\n                        tz = value\n                        break\n\n    # Deal with the cases where ambiguities arise\n    # don't assume default values for ISO week/year\n    if iso_year is not None:\n        if julian is not None:\n            raise ValueError(\"Day of the year directive '%j' is not \"\n                             \"compatible with ISO year directive '%G'. \"\n                             \"Use '%Y' instead.\")\n        elif iso_week is None or weekday is None:\n            raise ValueError(\"ISO year directive '%G' must be used with \"\n                             \"the ISO week directive '%V' and a weekday \"\n                             \"directive ('%A', '%a', '%w', or '%u').\")\n    elif iso_week is not None:\n        if year is None or weekday is None:\n            raise ValueError(\"ISO week directive '%V' must be used with \"\n                             \"the ISO year directive '%G' and a weekday \"\n                             \"directive ('%A', '%a', '%w', or '%u').\")\n        else:\n            raise ValueError(\"ISO week directive '%V' is incompatible with \"\n                             \"the year directive '%Y'. Use the ISO year '%G' \"\n                             \"instead.\")\n\n    leap_year_fix = False\n    if year is None:","sourceCodeStart":719,"sourceCodeEnd":755,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_strptime.py#L719-L755","documentation":"In the ambiguity-resolution block of _strptime, if the ISO year directive %G produced a value and the day-of-year directive %j also produced one (both map to absolute day positions), the two can contradict, so a ValueError tells you to use the regular year %Y with %j instead.","triggerScenarios":"datetime.strptime('2020 100 3', '%G %j %u') — any format combining %G and %j; %j is compatible only with %Y/%y, not with the ISO-week calendar year.","commonSituations":"ISO 8601 week-date strings mistakenly parsed with %j; mixing Ordinal-date formats (YYYY-DDD) with ISO week-date formats (YYYY-Www-D).","solutions":["Use %Y with %j for ordinal dates: '%Y %j'","Keep %G only with %V and a weekday directive (%A/%a/%w/%u) for ISO week dates"],"exampleFix":"# before\n>>> datetime.strptime('2020 100 3', '%G %j %u')\nValueError: Day of the year directive '%j' is not compatible with ISO year directive '%G'. Use '%Y' instead.\n\n# after\n>>> datetime.strptime('2020 100', '%Y %j')\ndatetime.datetime(2020, 4, 9, 0, 0)","handlingStrategy":"validation","validationCode":"def check_iso_fmt(fmt: str) -> None:\n    if '%G' in fmt.replace('%%', '') and '%j' in fmt.replace('%%', ''):\n        raise ValueError('format mixes %G and %j; use %Y with %j')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair %j only with %Y/%y (ordinal dates)","Pair %G only with %V + weekday (ISO week dates)","Decide once per data source which calendar the strings use and pin the format"],"tags":["strptime","iso-week","datetime","format-string","cpython"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}