53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
// src/utils/date.util.ts
|
|
var ONE_DAY = 24 * 60 * 60 * 1e3;
|
|
var formatDate = (date) => {
|
|
const year = date.getFullYear();
|
|
const month = (date.getMonth() + 1 + "").padStart(2, "0");
|
|
const day = (date.getDate() + "").padStart(2, "0");
|
|
return `${year}${month}${day}`;
|
|
};
|
|
var yesterday = (date) => {
|
|
date = date || /* @__PURE__ */ new Date();
|
|
date.setDate(date.getDate() - 1);
|
|
return date;
|
|
};
|
|
var nextday = (date) => {
|
|
date = date || /* @__PURE__ */ new Date();
|
|
date.setDate(date.getDate() + 1);
|
|
return date;
|
|
};
|
|
function daysBetween(date1, date2) {
|
|
const diffInMs = Math.abs(date1.getTime() - date2.getTime());
|
|
const diffInDays = Math.round(diffInMs / ONE_DAY);
|
|
return diffInDays;
|
|
}
|
|
var getDayBegin = (date) => {
|
|
const year = date.getFullYear();
|
|
const month = date.getMonth();
|
|
const day = date.getDate();
|
|
return new Date(year, month, day);
|
|
};
|
|
var getNDayAgo = (n, begin) => {
|
|
const date = new Date(Date.now() - n * 24 * 60 * 60 * 1e3);
|
|
if (begin) {
|
|
return getDayBegin(date);
|
|
} else {
|
|
return date;
|
|
}
|
|
};
|
|
var getMonthBegin = (date) => {
|
|
const year = date.getFullYear();
|
|
const month = date.getMonth();
|
|
return new Date(year, month, 1);
|
|
};
|
|
export {
|
|
ONE_DAY,
|
|
daysBetween,
|
|
formatDate,
|
|
getDayBegin,
|
|
getMonthBegin,
|
|
getNDayAgo,
|
|
nextday,
|
|
yesterday
|
|
};
|
|
//# sourceMappingURL=date.util.js.map
|