import re


def IntervalToSeconds(specified_interval):
    """
    Convert an ISO8601 duration string (e.g. PT5M, PT1H30M, PT30S) to a number of seconds.
    :param specified_interval: ISO8601 duration string. Must not include units larger than Hours.
    :return: An integer number of seconds. Raises ValueError if the duration string is syntactically invalid or beyond
             the supported range.
    """
    interval = specified_interval.upper()
    if interval[0] != 'P':
        raise ValueError('"{0}" is not an IS8601 duration string'.format(interval))
    if interval[1] != 'T':
        raise ValueError('IS8601 durations based on days or larger intervals are not supported: "{0}"'.format(interval))

    seconds = 0
    matches = re.findall(r'(\d+)(S|M|H)', interval[2:].upper())
    for qty, unit in matches:
        qty = int(qty)
        if unit == 'S':
            seconds += qty
        elif unit == 'M':
            seconds += qty * 60
        elif unit == 'H':
            seconds += qty * 3600

    if 0 == seconds:
        raise ValueError('Could not parse interval specification "{0}"'.format(specified_interval))
    return seconds