export function cloneDate(date) {
  return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
}
export function dateToString(date) {
  return date.getFullYear() + '-' + pad((date.getMonth() + 1).toString(), 2) + '-' + pad(date.getDate().toString(), 2);
}
export function isEqual(first, second) {
  return first.getTime() === second.getTime();
}
export function isBefore(first, second) {
  return first.getTime() < second.getTime();
}
export function isBeforeOrEqual(first, second) {
  return first.getTime() <= second.getTime();
}
export function isAfter(first, second) {
  return first.getTime() > second.getTime();
}
export function isSameDay(first, second) {
  return first.getFullYear() === second.getFullYear() && first.getMonth() === second.getMonth() && first.getDate() === second.getDate();
}
export function moveToDayOfWeek(date, dayOfWeek) {
  while (date.getDay() !== dayOfWeek)
    date.setDate(date.getDate() - 1);
  return date;
}
export function pad(value, length = 0) {
  while (value.length < length)
    value = '0' + value;
  return value;
}
export function toDayOfMonthString(date) {
  return pad(date.getDate().toString());
}
const months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
export function toMonthAndYearString(strings, date) {
  return strings[months[date.getMonth()]] + ' ' + date.getFullYear();
}
export function iterateMonth(date, count) {
  const clone = new Date(date);
  if (count === 0) {
    return clone;
  }
  return new Date(clone.setMonth(clone.getMonth() + count));
}
export function iterateWeek(date, count) {
  const clone = new Date(date);
  if (count === 0) {
    return clone;
  }
  return new Date(clone.setDate(clone.getDate() + (count * 7)));
}
export function iterateMinutes(date, count) {
  const clone = new Date(date);
  if (count === 0) {
    return clone;
  }
  return new Date(clone.setMinutes(clone.getMinutes() + count));
}
export function iterateSeconds(date, count) {
  const clone = new Date(date);
  if (count === 0) {
    return clone;
  }
  return new Date(clone.setSeconds(clone.getSeconds() + count));
}
