I have covered Leap Year 1403 for calendar but and it is now leap year, but the problem is that the date picker still shows 29 days for last month of that year.
And the other problem is dates are not adjusted with days, for example: if months starts with Sunday it shows the first date in Monday (only for that 1403 year) the 1404 is correct (it is first date of 1404 year and it is Friday 21 March 2025).
/* Persian calendar for jQuery v2.1.0.
Written by Keith Wood, updated to fix leap year calculation and date conversion.
Available under the MIT license. */
(function ($) {
'use strict';
function PersianCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
PersianCalendar.prototype = new $.calendars.baseCalendar();
$.extend(PersianCalendar.prototype, {
name: 'Persian',
jdEpoch: 1948320.5,
daysPerMonth: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30],
hasYearZero: false,
minMonth: 1,
firstMonth: 1,
minDay: 1,
regionalOptions: {
'': {
name: 'Persian',
epochs: ['BP', 'AP'],
monthNames: ['حمل', 'ثور', 'جوزا', 'سرطان', 'اسد', 'سنبله', 'میزان', 'عقرب', 'قوس', 'جدی', 'دلو', 'حوت'],
monthNamesShort: ['حمل', 'ثور', 'جوزا', 'سرطان', 'اسد', 'سنبله', 'میزان', 'عقرب', 'قوس', 'جدی', 'دلو', 'حوت'],
dayNames: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'],
dayNamesShort: ['یک', 'دو', 'سه', 'چهار', 'پنج', 'جمعه', 'شنبه'],
dayNamesMin: ['ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش'],
digits: null,
dateFormat: 'yyyy-mm-dd',
firstDay: 6,
isRTL: false
}
},
leapYear: function (year) {
var date = this._validate(year, this.minMonth, this.minDay, $.calendars.local.invalidYear);
var y = date.year();
var modYear = (y + 38) % 2820;
var leapYears = [0, 4, 8, 12, 16, 20, 24, 28, 33, 37, 41, 45, 49, 53, 57, 61, 66, 70, 74, 78, 82, 86, 90, 95, 99, 103, 107, 111, 115, 119, 124, 128];
return leapYears.includes(modYear % 128);
},
daysInMonth: function (year, month) {
var date = this._validate(year, month, this.minDay, $.calendars.local.invalidMonth);
var days = this.daysPerMonth[date.month() - 1];
if (date.month() === 12 && this.leapYear(date.year())) {
days = 30; // Esfand has 30 days in leap years
}
return days;
},
toJD: function (year, month, day) {
var date = this._validate(year, month, day, $.calendars.local.invalidDate);
year = date.year();
month = date.month();
day = date.day();
var epBase = year - (year >= 0 ? 474 : 473);
var epYear = 474 + (epBase % 2820);
return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) +
Math.floor((epYear * 682 - 110) / 2816) + (epYear - 1) * 365 +
Math.floor(epBase / 2820) * 1029983 + this.jdEpoch;
},
fromJD: function (jd) {
jd = Math.floor(jd) + 0.5;
var depoch = jd - this.toJD(475, 1, 1);
var cycle = Math.floor(depoch / 1029983);
var cyear = depoch % 1029983;
var ycycle = 2820;
if (cyear !== 1029982) {
var aux1 = Math.floor(cyear / 366);
var aux2 = cyear % 366;
ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1;
}
var year = ycycle + (2820 * cycle) + 474;
if (year <= 0) {
year--;
}
var yday = jd - this.toJD(year, 1, 1) + 1;
var month = yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30);
var day = jd - this.toJD(year, month, 1) + 1;
return this.newDate(year, month, day);
},
fromJSDate: function (jsd) {
var utcDate = new Date(Date.UTC(
jsd.getFullYear(),
jsd.getMonth(),
jsd.getDate()
));
var gregCal = $.calendars.instance('gregorian');
var jd = gregCal.toJD(
utcDate.getUTCFullYear(),
utcDate.getUTCMonth() + 1,
utcDate.getUTCDate()
);
return this.fromJD(jd);
},
weekOfYear: function (year, month, day) {
var checkDate = this.newDate(year, month, day);
checkDate.add(-((checkDate.dayOfWeek() + 1) % 7), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
weekDay: function (year, month, day) {
return this.dayOfWeek(year, month, day) !== 5;
},
dayOfWeek: function (year, month, day) {
var date = this._validate(year, month, day, $.calendars.local.invalidDate);
return (Math.floor(date.toJD()) + 2) % 7; // Adjusted to +2
},
});
function mod(a, b) {
return a - (b * Math.floor(a / b));
}
$.calendars.calendars.persian = PersianCalendar;
$.calendars.calendars.jalali = PersianCalendar;
})(jQuery);
This is my code for that
