Dates.js
650 Bytes
function toYMD(dateObj) {
const year = dateObj.getFullYear();
const month = dateObj.getMonth() + 1;
const date = dateObj.getDate();
return { year, month, date };
}
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, toSunday, moveDate };