我在我的网络应用程序中使用 ha-datetimepicker。但是对于1403年,一年的第一天不是从星期三开始,而是错误地从星期四开始。显然,问题与下面的一段代码有关,但我无法解决该问题。如果有人能帮助我解决这个问题,我将不胜感激。
谢谢大家...
HaSolarDate.prototype.getWeekDay = function (solarDate) {
if (solarDate == null)
solarDate = this;
var month = solarDate.getMonth() + 1;
var year = solarDate.getFullYear();
var day = solarDate.getDate();
if (Number(day) == "NaN" || Number(month) == "NaN" || Number(year) == "NaN")
return "Wrong Date!";
var firstDayOfYear95 = 1;
var step = year < 1395 ? 1 : -1;
var i = year;
var leapCount = 0;
while (i != 1395) {
if (this.isLeapYear(i))
leapCount++;
i += step;
}
if (year > 1395)
leapCount++;
var offset = (firstDayOfYear95 + (leapCount * -step)) % 7;
var firstDayOfYear = (((year - 1395) % 7) + offset) % 7;
if (firstDayOfYear < 0)
firstDayOfYear = 7 + firstDayOfYear;
if (month <= 6) {
var dayOfWeek = ((((month - 1) * 3) - 1) + day + firstDayOfYear) % 7;
} else {
var dayOfWeek = ((((month - 1) * 2) - 2) + day + firstDayOfYear) % 7;
}
dayOfWeek = Math.floor(dayOfWeek);
if (dayOfWeek == 7)
dayOfWeek = 0;
return dayOfWeek;
}
更改此行
if (year > 1395) leapCount++;
有了这个
if (year > 1395 && !this.isLeapYear()) leapCount++;
可能会解决问题。问题是每个闰年的开始都会增加一天,但每个闰年的年底都会增加一天。