def seconds(dhms):
    """Convert a time string "[[[DD:]HH:]MM:]SS" to seconds.
    """
    components = [int(i) for i in dhms.split(':')]
    pad = 4 - len(components)
    if pad < 0:
        raise ValueError('Too many components to match [[[DD:]HH:]MM:]SS')
    components = [0] * pad + components
    return sum(i * j for i, j in zip((86400, 3600, 60, 1), components))