Compiler helper method: attempt to compile constant into object representing
    timedelta object to enable math operations and relations with datetime objects
    using Python operators.

def compile_timedelta(rule):
    """
    Compiler helper method: attempt to compile constant into object representing
    timedelta object to enable math operations and relations with datetime objects
    using Python operators.
    """
    if isinstance(rule.value, datetime.timedelta):
        return rule
    try:
        # Try numeric type
        return TimedeltaRule(datetime.timedelta(seconds = int(rule.value)))
    except:
        pass
    # Try RFC3339 timestamp string
    res = DURATION_RE.match(str(rule.value))
    if res is not None:
        days, hours, minutes, seconds = (int(n or 0) for n in res.group('days','hrs','mins','secs'))
        return TimedeltaRule(datetime.timedelta(days = days, hours = hours, minutes = minutes, seconds = seconds))
    raise ValueError("Wrong timedelta format '{}'".format(rule.value))