getYearAndMonth.ts 661 B

123456789101112131415
  1. import { TZDateUtil } from "../../utils/date-fns-extra";
  2. export default function getYearAndMonth(year: { left: number; right: number }, month: { left: number; right: number }, timeZone: string | number) {
  3. const nowDate = TZDateUtil.createTZDate(timeZone);
  4. const nowYear = nowDate.getFullYear();
  5. const nowMonth = nowDate.getMonth();
  6. const rightMonth = month.right || (nowMonth + 2);
  7. const rightYear = year.right || (rightMonth <= 12 ? nowYear : nowYear + 1);
  8. return {
  9. year: { left: year.left || nowYear, right: rightYear },
  10. month: { left: month.left || nowMonth + 1, right: rightMonth <= 12 ? rightMonth : 1 },
  11. };
  12. }