Dates.js 796 Bytes
function toYMD(dateObj) {
  const year = dateObj.getFullYear();
  const month = dateObj.getMonth() + 1;
  const date = dateObj.getDate();

  return { year, month, date };
}

function toYMDStr(dateObj) {
  return [
    dateObj.getFullYear(),
    dateObj.getMonth() + 1,
    dateObj.getDate(),
  ].join("/");
}

function toSunday(dateObj) {
  const day = dateObj.getDay();
  moveDate(dateObj, "day", -day);
}

function moveDate(dateObj, scope, distance) {
  switch (scope) {
    case "month":
      dateObj.setMonth(dateObj.getMonth() + distance);
      break;
    case "week":
      dateObj.setDate(dateObj.getDate() + distance * 7);
      break;
    case "day":
      dateObj.setDate(dateObj.getDate() + distance);
      break;
    default:
  }
}

export { toYMD, toYMDStr, toSunday, moveDate };