def time_to_seconds(time_str):
    """
    Convert a string describing a time duration into seconds. The supported
    formats are: "minutes", "minutes:seconds", "hours:minutes:seconds",
    "days-hours", "days-hours:minutes", "days-hours:minutes:seconds",
    and "days:hours:minutes:seconds"

    >>> time_to_seconds('10')
    600
    >>> time_to_seconds('10:00')
    600
    >>> time_to_seconds('10:30')
    630
    >>> time_to_seconds('1:10:30')
    4230
    >>> time_to_seconds('1-1:10:30')
    90630
    >>> time_to_seconds('1-0')
    86400
    >>> time_to_seconds('1-10')
    122400
    >>> time_to_seconds('1-1:10')
    90600
    >>> time_to_seconds('1-1:10:30')
    90630
    >>> time_to_seconds('1:1:10:30')
    90630
    >>> time_to_seconds('1 1:10:30')
    Traceback (most recent call last):
      ...
    ValueError: '1 1:10:30' has invalid pattern
    """
    import re
    patterns = [re.compile(
        '^(?P<hours>\\d+):(?P<minutes>\\d+):(?P<seconds>\\d+)$'), re.
        compile('^(?P<days>\\d+)-(?P<hours>\\d+)$'), re.compile(
        '^(?P<minutes>\\d+)$'), re.compile(
        '^(?P<minutes>\\d+):(?P<seconds>\\d+)$'), re.compile(
        '^(?P<days>\\d+)-(?P<hours>\\d+):(?P<minutes>\\d+)$'), re.compile(
        '^(?P<days>\\d+)-(?P<hours>\\d+):(?P<minutes>\\d+):(?P<seconds>\\d+)$'
        ), re.compile(
        '^(?P<days>\\d+):(?P<hours>\\d+):(?P<minutes>\\d+):(?P<seconds>\\d+)$')
        ]
    seconds = 0
    for pattern in patterns:
        match = pattern.match(str(time_str).strip())
        if match:
            if 'seconds' in match.groupdict():
                seconds += int(match.group('seconds'))
            if 'minutes' in match.groupdict():
                seconds += 60 * int(match.group('minutes'))
            if 'hours' in match.groupdict():
                seconds += 3600 * int(match.group('hours'))
            if 'days' in match.groupdict():
                seconds += 86400 * int(match.group('days'))
            return seconds
    raise ValueError("'%s' has invalid pattern" % time_str)
