import moment from "moment";

export const formattedDateDiff = (start, end) => {
    const days = Math.abs(moment(end).diff(start, "days"));
    return daysToReadable(days);
};

export const daysToReadable = (days, today = true) => {
    if (days >= 365) {
        return `~${Math.floor(days / 365)} years`;
    } else if (days >= 30) {
        return `~${Math.floor(days / 30)} months`;
    } else if (days >= 7) {
        return `~${Math.floor(days / 7)} weeks`;
    } else if (days >= 1) {
        return `${days} days`;
    } else {
        return today ? "Today" : `${days} day`;
    }
};
