export function datesEqual(dateA, dateB) {
    if (dateA instanceof Date && dateB instanceof Date) {
        return dateA.getTime() === dateB.getTime();
    }

    return dateA === dateB;
}

// returns the start of time relative to the provided date, for the given unit
// i.e. startOfDate(<2016, 12, 14>, 'month') = <2016, 12, 1>
export function startOfDate(date, unit = 'days') {
    if (!(date instanceof Date)) {
        return null;
    }

    const year = date.getFullYear();
    let month = date.getMonth() + 1,
        day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        s = date.getSeconds(),
        ms = date.getMilliseconds();

    /* eslint-disable no-fallthrough */
    switch (unit) {
        case 'years':
            month = 1;
        case 'months':
            day = 1;
        case 'days':
            hour = 0;
        case 'hours':
            min = 0;
        case 'minutes':
            s = 0;
        case 'seconds':
            ms = 0;
        default:
            break;
    }

    return new Date(year, month - 1, day, hour, min, s, ms);
}
