"use strict";

exports.__esModule = true;
exports.mergeDate = mergeDate;
exports.mergeTime = mergeTime;
var _helpers = require("./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.
 */
function mergeDate(prev, newDate) {
  const next = new Date(newDate);
  if ((0, _helpers.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.
 */
function mergeTime(prev, newTime) {
  const base = (0, _helpers.isValidDate)(prev) ? new Date(prev) : new Date();
  base.setHours(newTime.getHours(), newTime.getMinutes(), newTime.getSeconds(), newTime.getMilliseconds());
  return base;
}
//# sourceMappingURL=mergeDateTime.js.map