function isFirstDayOfMonth(dateString) {
const date = new Date(dateString);
return date.getDate() === 1;
}
function isLastDayOfMonth(dateString) {
const date = new Date(dateString);
const nextMonthFirstDay = new Date(date.getFullYear(), date.getMonth() + 1, 1);
const lastDayOfMonth = new Date(nextMonthFirstDay.getTime() - 1);
return date.getDate() === lastDayOfMonth.getDate();
}
// 示例用法
const date1 = new Date('2022-08-01');
console.log(isFirstDayOfMonth(date1)); // 输出: true
console.log(isLastDayOfMonth(date1)); // 输出: false
const date2 = new Date('2022-08-31');
console.log(isFirstDayOfMonth(date2)); // 输出: false
console.log(isLastDayOfMonth(date2)); // 输出: true
var start = this.options.form.getWidgetByName("start_date").getValue();
var end = this.options.form.getWidgetByName("end_date").getValue();
var starta = this.options.form.getWidgetByName("start_date_yoy").getValue();
var enda = this.options.form.getWidgetByName("end_date_yoy").getValue();
var kdate = this.options.form.getWidgetByName("start_date_yoy");
// 判断控件是否可用,可用为比对模式
console.log(kdate.isEnabled())
if (kdate.isEnabled()) {
// 需求1
if (starta < "2022-08-01" && enda > "2022-08-01") {
const isItFirstDay = isFirstDayOfMonth(starta);
if (!isItFirstDay) {
FR.Msg.toast("对比开始日期不是月的第一天");
return false;
}
}
}
if (kdate.isEnabled()) {
// 需求2
if (starta < "2022-08-01" && enda < "2022-08-01") {
const isItLastDay = isLastDayOfMonth(enda);
if (!isItLastDay) {
FR.Msg.toast("对比结束日期不是月的最后一天");
return false;
}
}
}
if (start == "" || start == null || starta == "" || starta == null) { //判断开始日期是否为空
FR.Msg.toast("开始时间不能为空");
return false;
} else if (end == "" || end == null || enda == "" || enda == null) { //判断结束日期是否为空
FR.Msg.toast("结束时间不能为空");
return false;
} else if (start > end || starta > enda) { //判断开始日期是否大于结束日期
FR.Msg.toast("开始时间不能大于结束时间"); //开始日期大于结束日期