def get_diff()

in decisionai_plugin/common/util/timeutil.py [0:0]


def get_diff(start, graninfo, end):
    (gran_str, custom_in_seconds) = graninfo
    delta = dateutil.relativedelta.relativedelta(end, start)
    if gran_str == 'Daily':
        diff = (end - start).total_seconds() / DAY_IN_SECONDS
    elif gran_str == 'Weekly':
        diff = (end - start).total_seconds() / (DAY_IN_SECONDS * 7)
    elif gran_str == 'Monthly':
        diff = delta.years * 12 + delta.months
    elif gran_str == 'Yearly':
        diff = delta.years
    elif gran_str == 'Hourly':
        diff = (end - start).total_seconds() / HOUR_IN_SECONDS
    elif gran_str == 'Minutely':
        diff = (end - start).total_seconds() / MINT_IN_SECONDS
    elif gran_str == 'Secondly':
        diff = (end - start).total_seconds()
    elif gran_str == 'Custom':
        diff = (end - start).total_seconds() / custom_in_seconds
    else:
        raise Exception('Granularity not supported: {}|{}'.format(*graninfo))

    return int(diff)