import { isValidDate } from './helpers';
/**
 * Take the date-part from `newDate` and the time-of-day from `prev`. When
 * `prev` is null/invalid the merged time-of-day defaults to midnight.
 */
export function mergeDate(prev, newDate) {
    const next = new Date(newDate);
    if (isValidDate(prev)) {
        next.setHours(prev.getHours(), prev.getMinutes(), prev.getSeconds(), prev.getMilliseconds());
    }
    else {
        next.setHours(0, 0, 0, 0);
    }
    return next;
}
/**
 * Take the time-of-day from `newTime` and the date-part from `prev`. When
 * `prev` is null/invalid the merged date-part defaults to today.
 */
export function mergeTime(prev, newTime) {
    const base = isValidDate(prev) ? new Date(prev) : new Date();
    base.setHours(newTime.getHours(), newTime.getMinutes(), newTime.getSeconds(), newTime.getMilliseconds());
    return base;
}
//# sourceMappingURL=mergeDateTime.js.map