Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/nepaliDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,22 @@ var calendarFunctions = {};
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2081 && bsMonth === 12) {
daysNumFromMinBsYear += bsDate - 1;
} else if (bsYear === 2082 && bsMonth === 2) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is forcefull way of doing it, instead i think we can update the core data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. I guess the core maintainers have to take a crack at it. This fix is just a brute force method intended to get the job done for a couple of months. We are bound to face this issue again next year or a year after.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this isn't correct. Nepali calendar data is readily available using that would simply this.

daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2082 && bsMonth === 4) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2082 && bsMonth === 7) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2082 && bsMonth === 8) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2082 && bsMonth === 10) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2083 && bsMonth === 7) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2083 && bsMonth === 8) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear === 2083 && bsMonth === 10) {
daysNumFromMinBsYear += bsDate + 1;
} else if (bsYear > 2088) {
daysNumFromMinBsYear += bsDate - 4;
} else if (bsYear === 2088 && bsMonth > 5) {
Expand Down Expand Up @@ -894,6 +910,30 @@ var calendarFunctions = {};
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2081 && bsMonth === 12) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2082 && bsMonth === 1) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2082 && bsMonth === 2) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2082 && bsMonth === 3) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2082 && bsMonth === 4) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2082 && bsMonth === 6) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2082 && bsMonth === 8) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2082 && bsMonth === 9) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2082 && bsMonth === 10) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2083 && bsMonth === 6) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2083 && bsMonth === 8) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else if (bsYear === 2083 && bsMonth === 9) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] + 1;
} else if (bsYear === 2083 && bsMonth === 10) {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex] - 1;
} else {
return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex];
}
Expand Down
212 changes: 212 additions & 0 deletions test/calendarFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,218 @@ describe('Test: calendarFunctions.getBsMonthInfoByBsDate(bsYear, bsMonth, bsDate
bsMonthDays: 31
});
});

it('Should return correct date for edge cases of 2082 BS', function () {
expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 1, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 1,
bsDate: 31,
weekDay: 4,
formattedDate: 'बुध, बैशाख ३१, २०८२',
adDate: new Date(2025, 4, 14),
bsMonthFirstAdDate: new Date(2025, 3, 14),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 2, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 2,
bsDate: 31,
weekDay: 7,
formattedDate: 'शनि, जेठ ३१, २०८२',
adDate: new Date(2025, 5, 14),
bsMonthFirstAdDate: new Date(2025, 4, 15),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 3, 32, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 3,
bsDate: 32,
weekDay: 4,
formattedDate: 'बुध, असार ३२, २०८२',
adDate: new Date(2025, 6, 16),
bsMonthFirstAdDate: new Date(2025, 5, 15),
bsMonthDays: 32
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 4, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 4,
bsDate: 31,
weekDay: 7,
formattedDate: 'शनि, साउन ३१, २०८२',
adDate: new Date(2025, 7, 16),
bsMonthFirstAdDate: new Date(2025, 6, 17),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 5, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 5,
bsDate: 31,
weekDay: 3,
formattedDate: 'मंगल, भदौ ३१, २०८२',
adDate: new Date(2025, 8, 16),
bsMonthFirstAdDate: new Date(2025, 7, 17),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 6, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 6,
bsDate: 31,
weekDay: 6,
formattedDate: 'शुक्र, असोज ३१, २०८२',
adDate: new Date(2025, 9, 17),
bsMonthFirstAdDate: new Date(2025, 8, 17),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 7, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 7,
bsDate: 30,
weekDay: 1,
formattedDate: 'आइत, कार्तिक ३०, २०८२',
adDate: new Date(2025, 10, 16),
bsMonthFirstAdDate: new Date(2025, 9, 18),
bsMonthDays: 30
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 8, 29, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 8,
bsDate: 29,
weekDay: 2,
formattedDate: 'सोम, मंसिर २९, २०८२',
adDate: new Date(2025, 11, 15),
bsMonthFirstAdDate: new Date(2025, 10, 17),
bsMonthDays: 29
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 9, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 9,
bsDate: 30,
weekDay: 4,
formattedDate: 'बुध, पौष ३०, २०८२',
adDate: new Date(2026, 0, 14),
bsMonthFirstAdDate: new Date(2025, 11, 16),
bsMonthDays: 30
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 10, 29, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 10,
bsDate: 29,
weekDay: 5,
formattedDate: 'बिही, माघ २९, २०८२',
adDate: new Date(2026, 1, 12),
bsMonthFirstAdDate: new Date(2026, 0, 15),
bsMonthDays: 29
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 11, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 11,
bsDate: 30,
weekDay: 7,
formattedDate: 'शनि, फागुन ३०, २०८२',
adDate: new Date(2026, 2, 14),
bsMonthFirstAdDate: new Date(2026, 1, 13),
bsMonthDays: 30
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2082, 12, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2082,
bsMonth: 12,
bsDate: 30,
weekDay: 2,
formattedDate: 'सोम, चैत ३०, २०८२',
adDate: new Date(2026, 3, 13),
bsMonthFirstAdDate: new Date(2026, 2, 15),
bsMonthDays: 30
});
});

it('Should return correct date for edge cases of 2083 BS', function () {
expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 6, 31, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 6,
bsDate: 31,
weekDay: 7,
formattedDate: 'शनि, असोज ३१, २०८३',
adDate: new Date(2026, 9, 17),
bsMonthFirstAdDate: new Date(2026, 8, 17),
bsMonthDays: 31
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 7, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 7,
bsDate: 30,
weekDay: 2,
formattedDate: 'सोम, कार्तिक ३०, २०८३',
adDate: new Date(2026, 10, 16),
bsMonthFirstAdDate: new Date(2026, 9, 18),
bsMonthDays: 30
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 8, 29, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 8,
bsDate: 29,
weekDay: 3,
formattedDate: 'मंगल, मंसिर २९, २०८३',
adDate: new Date(2026, 11, 15),
bsMonthFirstAdDate: new Date(2026, 10, 17),
bsMonthDays: 29
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 9, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 9,
bsDate: 30,
weekDay: 5,
formattedDate: 'बिही, पौष ३०, २०८३',
adDate: new Date(2027, 0, 14),
bsMonthFirstAdDate: new Date(2026, 11, 16),
bsMonthDays: 30
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 10, 29, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 10,
bsDate: 29,
weekDay: 6,
formattedDate: 'शुक्र, माघ २९, २०८३',
adDate: new Date(2027, 1, 12),
bsMonthFirstAdDate: new Date(2027, 0, 15),
bsMonthDays: 29
});

expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 11, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 11,
bsDate: 30,
weekDay: 1,
formattedDate: 'आइत, फागुन ३०, २०८३',
adDate: new Date(2027, 2, 14),
bsMonthFirstAdDate: new Date(2027, 1, 13),
bsMonthDays: 30
});
expect(calendarFunctions.getBsMonthInfoByBsDate(2083, 12, 30, '%D, %M %d, %y')).toEqual({
bsYear: 2083,
bsMonth: 12,
bsDate: 30,
weekDay: 3,
formattedDate: 'मंगल, चैत ३०, २०८३',
adDate: new Date(2027, 3, 13),
bsMonthFirstAdDate: new Date(2027, 2, 15),
bsMonthDays: 30
});
});
});

describe('Test: calendarFunctions.getAdDateByBsDate(bsYear, bsMonth, BsDate)', function () {
Expand Down