jquery - 某些月份的自定义视图中的问题 - FullCalendar.io
问题描述
我有这样的自定义视图:
views: {
dayGridMonthPersian:
{
type: "dayGrid",
buttonText: 'ماه شمسی',
visibleRange: function () {
const currentDate = new Date();
const thisMonthArray = GetStartEndMonth(currentDate);
return { start: thisMonthArray[0], end: thisMonthArray[1] }
},
},
我怎样才能解决这个问题??
解决方案
可能对某人有用。波斯月的第一天和最后一天:
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];
}
推荐阅读
- linux - make:如何将文本附加到列表的开头和结尾?
- reactjs - 删除 react-select 选择组件上的下划线
- android - 不同的屏幕尺寸问题?
- mongodb - mongodb中的UpdateMany使用其他字段的值
- java - junit5 创建临时文件
- laravel - 在 Laravel -Mysql 中将 id 数组存储为不同的实体
- azure-active-directory - 部署 Azure AD 密码保护服务
- airflow-scheduler - 在气流中成功执行 DAG1 和 DAG2 后如何触发 DAG3?
- api - Youtube API3 配额错误超过
- mysql - 我无法添加 MySQL 外键约束