From b87b8cc54a06b9e9a9b41feb08558da42fd00c01 Mon Sep 17 00:00:00 2001 From: niroula-kushal Date: Wed, 19 Mar 2025 22:09:05 +0545 Subject: [PATCH 1/3] fix: dates for 2082 till Ashoj --- src/nepaliDatePicker.js | 14 ++++++ test/calendarFunctions.test.js | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/src/nepaliDatePicker.js b/src/nepaliDatePicker.js index 0b32047..bcf0877 100644 --- a/src/nepaliDatePicker.js +++ b/src/nepaliDatePicker.js @@ -809,6 +809,10 @@ var calendarFunctions = {}; daysNumFromMinBsYear += bsDate + 1; } else if (bsYear === 2081 && bsMonth === 12) { daysNumFromMinBsYear += bsDate - 1; + } else if (bsYear === 2082 && bsMonth === 2) { + daysNumFromMinBsYear += bsDate + 1; + } else if (bsYear === 2082 && bsMonth === 4) { + daysNumFromMinBsYear += bsDate + 1; } else if (bsYear > 2088) { daysNumFromMinBsYear += bsDate - 4; } else if (bsYear === 2088 && bsMonth > 5) { @@ -894,6 +898,16 @@ 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 { return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex]; } diff --git a/test/calendarFunctions.test.js b/test/calendarFunctions.test.js index 5628637..7f7c057 100644 --- a/test/calendarFunctions.test.js +++ b/test/calendarFunctions.test.js @@ -199,6 +199,85 @@ 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, 9, 16), + bsMonthFirstAdDate: new Date(2025, 8, 18), + bsMonthDays: 30 + }); + }); }); describe('Test: calendarFunctions.getAdDateByBsDate(bsYear, bsMonth, BsDate)', function () { From e64acc177e7b252b8028232e2446c025acdf1309 Mon Sep 17 00:00:00 2001 From: niroula-kushal Date: Thu, 20 Mar 2025 19:43:28 +0545 Subject: [PATCH 2/3] fix(mismatch): date mismatch for year 2082 --- src/nepaliDatePicker.js | 12 +++++++ test/calendarFunctions.test.js | 59 ++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/nepaliDatePicker.js b/src/nepaliDatePicker.js index bcf0877..ab93782 100644 --- a/src/nepaliDatePicker.js +++ b/src/nepaliDatePicker.js @@ -813,6 +813,12 @@ var calendarFunctions = {}; 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 > 2088) { daysNumFromMinBsYear += bsDate - 4; } else if (bsYear === 2088 && bsMonth > 5) { @@ -908,6 +914,12 @@ var calendarFunctions = {}; 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 { return calendarData.bsMonthUpperDays[bsMonth - 1][bsMonthUpperDaysIndex]; } diff --git a/test/calendarFunctions.test.js b/test/calendarFunctions.test.js index 7f7c057..f1e7c45 100644 --- a/test/calendarFunctions.test.js +++ b/test/calendarFunctions.test.js @@ -273,8 +273,63 @@ describe('Test: calendarFunctions.getBsMonthInfoByBsDate(bsYear, bsMonth, bsDate bsDate: 30, weekDay: 1, formattedDate: 'आइत, कार्तिक ३०, २०८२', - adDate: new Date(2025, 9, 16), - bsMonthFirstAdDate: new Date(2025, 8, 18), + 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(2025, 12, 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(2025, 12, 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 }); }); From 82e43afaba2d75212b362de90877dc988c5e99b4 Mon Sep 17 00:00:00 2001 From: niroula-kushal Date: Thu, 20 Mar 2025 20:42:06 +0545 Subject: [PATCH 3/3] fix(mismatch): date mismatch for year 2083 --- src/nepaliDatePicker.js | 14 ++++++ test/calendarFunctions.test.js | 82 +++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/nepaliDatePicker.js b/src/nepaliDatePicker.js index ab93782..1f28fde 100644 --- a/src/nepaliDatePicker.js +++ b/src/nepaliDatePicker.js @@ -819,6 +819,12 @@ var calendarFunctions = {}; 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) { @@ -920,6 +926,14 @@ var calendarFunctions = {}; 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]; } diff --git a/test/calendarFunctions.test.js b/test/calendarFunctions.test.js index f1e7c45..b09ba34 100644 --- a/test/calendarFunctions.test.js +++ b/test/calendarFunctions.test.js @@ -295,7 +295,7 @@ describe('Test: calendarFunctions.getBsMonthInfoByBsDate(bsYear, bsMonth, bsDate bsDate: 30, weekDay: 4, formattedDate: 'बुध, पौष ३०, २०८२', - adDate: new Date(2025, 12, 14), + adDate: new Date(2026, 0, 14), bsMonthFirstAdDate: new Date(2025, 11, 16), bsMonthDays: 30 }); @@ -307,7 +307,7 @@ describe('Test: calendarFunctions.getBsMonthInfoByBsDate(bsYear, bsMonth, bsDate weekDay: 5, formattedDate: 'बिही, माघ २९, २०८२', adDate: new Date(2026, 1, 12), - bsMonthFirstAdDate: new Date(2025, 12, 15), + bsMonthFirstAdDate: new Date(2026, 0, 15), bsMonthDays: 29 }); @@ -333,6 +333,84 @@ describe('Test: calendarFunctions.getBsMonthInfoByBsDate(bsYear, bsMonth, bsDate 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 () {