#!/usr/bin/env python3
from datetime import datetime
from dateutil.relativedelta import relativedelta

# when 32-bit time counters are exhausted
TIME_32BIT_EPOCH = datetime(year=2038, month=1, day=19)
EARLY_RETIRE = datetime(year=2031, month=6, day=2)

def time_until(epoch: datetime) -> str:
    '''returns the difference in time down to the number of days'''
    delta = relativedelta(epoch, datetime.now())

    def unit(value: int, noun: str) -> str:
        result = f'{value} {noun}'
        if value == 1:
            result += 's'

        return result + ' '

    result = f'{delta.days} days'
    if delta.months or delta.years:
        result = unit(delta.months, 'month') + result

    if delta.years:
        result = unit(delta.years, 'year') + result

    return result


print(time_until(TIME_32BIT_EPOCH), 'until int32 time fails')
print(time_until(EARLY_RETIRE), 'until early retirement')
