32 lines
830 B
JavaScript
32 lines
830 B
JavaScript
function getDayArea(date = new Date(), type) {
|
|
const now = date
|
|
if (type === 'start') {
|
|
const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
return startOfDay
|
|
}
|
|
if (type === 'end') {
|
|
const endOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
|
|
return endOfDay;
|
|
}
|
|
return `${startOfDay}-${endOfDay}`
|
|
}
|
|
function getMonthArea(date = new Date(), type) {
|
|
let now = date
|
|
let currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
let currentMonthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0 , 23, 59, 59, 999);
|
|
if (type === 'start') {
|
|
return currentMonthStart
|
|
}
|
|
if (type === 'end') {
|
|
return currentMonthEnd;
|
|
}
|
|
return {
|
|
start: currentMonthStart,
|
|
end: currentMonthEnd
|
|
};
|
|
}
|
|
|
|
|
|
export default {
|
|
getDayArea, getMonthArea
|
|
} |