Browse Source

Merge pull request #1308 from colinin/date-utils

feat(vben5): enhanced `dateUtils`
pull/1312/head
yx lin 6 months ago
committed by GitHub
parent
commit
787828e4ae
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 61
      apps/vben5/packages/@abp/core/src/utils/date.ts

61
apps/vben5/packages/@abp/core/src/utils/date.ts

@ -35,11 +35,43 @@ export function getAppointDate(days: number): dayjs.Dayjs {
return dayjs(tomorrow);
}
/**
*
* @returns
*/
export function firstDayOfWeek(): dayjs.Dayjs {
const now = new Date();
const today = now.getDay();
const dayOffset = today === 0 ? -6 : 1 - today;
const monday = new Date(now);
monday.setDate(now.getDate() + dayOffset);
return dayjs(
new Date(monday.getFullYear(), monday.getMonth(), monday.getDate()),
);
}
/**
*
* @returns
*/
export function firstDayOfMonth(): dayjs.Dayjs {
const now = new Date();
return dayjs(new Date(now.getFullYear(), now.getMonth(), 1));
}
/**
* 获取当月最后一天00:00:00
* @returns 返回当月最后一天00:00:00
*/
export function lastDayOfMonth(): dayjs.Dayjs {
const now = new Date();
return dayjs(new Date(now.getFullYear(), now.getMonth() + 1, 0));
}
/**
* 获取当月最后一天23:59:59
* @returns 返回当月最后一天23:59:59
*/
export function lastDateOfMonth(): dayjs.Dayjs {
const now = new Date();
return dayjs(
@ -47,4 +79,33 @@ export function lastDateOfMonth(): dayjs.Dayjs {
);
}
/**
*
* @returns
*/
export function firstDayOfLastMonth(): dayjs.Dayjs {
const now = new Date();
return dayjs(new Date(now.getFullYear(), now.getMonth() - 1, 1));
}
/**
* 获取上个月最后一天23:59:59
* @returns 返回上个月最后一天23:59:59
*/
export function lastDateOfLastMonth(): dayjs.Dayjs {
const now = new Date();
return dayjs(
new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999), // 当月第0天 = 上月最后一天
);
}
/**
*
* @returns
*/
export function firstDayOfYear(): dayjs.Dayjs {
const now = new Date();
return dayjs(new Date(now.getFullYear(), 0, 1));
}
export const dateUtil = dayjs;

Loading…
Cancel
Save