export const now = () => new Date();
export const isValidDate = (value) => value instanceof Date && value.getTime();
export const year = (date) => date.getFullYear();
export const month = (date) => date.getMonth();
export const day = (date) => date.getDate();
export const increaseYear = (date, years) => year(date) + years;
export const decreaseYear = (date, years) => year(date) - years;
export const isInRange = (date, minDate, maxDate) => {
  if (date && minDate && maxDate) {
    return minDate <= date && date <= maxDate;
  }
  return true;
};
export const format = (date) => {
  function pad(value) {
    var s = `0${value}`;
    return s.substr(s.length - 2);
  }
  return `${pad(day(date))}.${pad(month(date) + 1)}.${year(date)}`;
};
export const getLastDayOfMonth = (year, month) => {
  const d = new Date(year, month + 1, 0);
  return d.getDate();
};
export const getFirstDayOfTheWeek = (date) => {
  const weekdayDiff = [6, 0, 1, 2, 3, 4, 5];
  const d = new Date(date);
  d.setDate(d.getDate() - weekdayDiff[d.getDay()]);
  return d;
};
export const isSameYear = (a, b) => {
  return a.getFullYear() === b.getFullYear();
};
export const isSameMonth = (a, b) => {
  return isSameYear(a, b) && a.getMonth() === b.getMonth();
};
export const isSameDay = (a, b) => {
  return isSameMonth(a, b) && a.getDate() === b.getDate();
};
export const isSameWeek = (a, b) => {
  return isSameDay(getFirstDayOfTheWeek(a), getFirstDayOfTheWeek(b));
};
