python/cpython · error · ValueError

minute must be in 0..59, not {minute}

Error message

minute must be in 0..59, not {minute}

What it means

Raised by _check_time_fields() when the minute argument to time()/datetime() is not in 0..59. Minutes never reach 60 even for leap-second-aware timestamps — Python datetime does not model leap seconds, so 60 is rejected here (it is also rejected for seconds).

Source

Thrown at Lib/_pydatetime.py:589

    day = _index(day)
    if not MINYEAR <= year <= MAXYEAR:
        raise ValueError(f"year must be in {MINYEAR}..{MAXYEAR}, not {year}")
    if not 1 <= month <= 12:
        raise ValueError(f"month must be in 1..12, not {month}")
    dim = _days_in_month(year, month)
    if not 1 <= day <= dim:
        raise ValueError(f"day {day} must be in range 1..{dim} for month {month} in year {year}")
    return year, month, day

def _check_time_fields(hour, minute, second, microsecond, fold):
    hour = _index(hour)
    minute = _index(minute)
    second = _index(second)
    microsecond = _index(microsecond)
    if not 0 <= hour <= 23:
        raise ValueError(f"hour must be in 0..23, not {hour}")
    if not 0 <= minute <= 59:
        raise ValueError(f"minute must be in 0..59, not {minute}")
    if not 0 <= second <= 59:
        raise ValueError(f"second must be in 0..59, not {second}")
    if not 0 <= microsecond <= 999999:
        raise ValueError(f"microsecond must be in 0..999999, not {microsecond}")
    if fold not in (0, 1):
        raise ValueError(f"fold must be either 0 or 1, not {fold}")
    return hour, minute, second, microsecond, fold

def _check_tzinfo_arg(tz):
    if tz is not None and not isinstance(tz, tzinfo):
        raise TypeError(
            "tzinfo argument must be None or of a tzinfo subclass, "
            f"not {type(tz).__name__!r}"
        )

def _divide_and_round(a, b):
    """divide a by b and round result to the nearest integer

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Use timedelta arithmetic instead of mutating minute fields
  2. Normalize: h, m = divmod(total_minutes, 60) before constructing
  3. Validate 0 <= minute <= 59 in parser input paths

Example fix

// before
t = time(11, 75)  # ValueError
// after
base = datetime(y, m, d, 11, 0) + timedelta(minutes=75)
t = base.time()
Defensive patterns

Strategy: validation

Validate before calling

if not 0 <= minute <= 59:
    raise ValueError('minute must be 0..59')

Type guard

def valid_minute(m) -> bool:
    return 0 <= m <= 59

Prevention

When it happens

Trigger: time(12, 60); datetime(2024, 1, 1, 12, -1); parsing strings like '12:60'; carrying errors when adding minutes without normalizing.

Common situations: Hand-written time parsers accepting mm=60; arithmetic that adds minutes to the field instead of using timedelta; timezone offsets applied to the minute field directly.

Related errors


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/fdd8f99105619fa8. Report an issue: GitHub.