首页 > 解决方案 > 某些月份的自定义视图中的问题 - FullCalendar.io

问题描述

我有这样的自定义视图:

 views: {
                dayGridMonthPersian:
                {
                    type: "dayGrid",
                    buttonText: 'ماه شمسی',
                    visibleRange: function () {
                        const currentDate = new Date();
                        const thisMonthArray = GetStartEndMonth(currentDate);
                        return { start: thisMonthArray[0], end: thisMonthArray[1] }
                    },
                },

在某些月份一切正常: 在此处输入图像描述

但在某些月份我有月份风格问题: 在此处输入图像描述

我怎样才能解决这个问题??

标签: jqueryfullcalendar

解决方案


可能对某人有用。波斯月的第一天和最后一天:

    function GetStartEndMonth(currentDate) {
    const splitDate = splitGeorgianDateToPersianDateArray(currentDate);
    const year = splitDate[0];
    const month = splitDate[1];
    const lastDayOfPersianMonth = GetLastDayOfPersianMonth(month, year);

    //Not Work in some Month !! => moment(currentPersianDate).clone().startOf('month').format('YYYY/MM/DD');
    //Not Work at All in persian => moment(currentPersianDate).clone().endof('month').format('YYYY/MM/DD');
    const startPersianMonth = year + "/" + month + "/" + 1;
    const endPersianMonth = year + "/" + month + "/" + lastDayOfPersianMonth;

    let startGeorgianDate = ConvertPersianDateStringToGeorgianDate(startPersianMonth);
    let endGeorgianDate = ConvertPersianDateStringToGeorgianDate(endPersianMonth);
    endGeorgianDate.setHours(23, 59, 59, 59);
    const newMonthArray = [startGeorgianDate, endGeorgianDate];
    return newMonthArray;
}

    function GetLastDayOfPersianMonth(month, year) {
    //محاسبه کبیسه
    const leapMatch = [1, 5, 9, 13, 17, 22, 26, 30];
    const number = year % 33;
    const isLeap = leapMatch.includes(number);

    if (month <= 6) {
        return 31;
    }
    if (month > 6 && month < 12) {
        return 30;
    }
    if (month == 12 && !isLeap) {
        return 29;
    }
    if (month == 12 && isLeap) {
        return 30;
    }
}

function splitGeorgianDateToPersianDateArray(georgianDate) {
    const persianStringDate = moment(georgianDate).locale('fa').format('YYYY/M/D');
    const splitDate = persianStringDate.split("/");
    const year = splitDate[0];
    const month = splitDate[1];
    const day = splitDate[2];
    return [year, month, day];
}

推荐阅读