From f5a4a881e261af0636252610c44e878e87d4930b Mon Sep 17 00:00:00 2001 From: Soheil Hasankhani Date: Tue, 12 Mar 2024 12:55:03 +0330 Subject: [PATCH] Fixed set month Modified setMonth method to works with jalali month value --- __tests__/jalaali.test.ts | 6 ++++++ packages/jalaali/src/jalaali-utils.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/__tests__/jalaali.test.ts b/__tests__/jalaali.test.ts index c87e0628..25901471 100644 --- a/__tests__/jalaali.test.ts +++ b/__tests__/jalaali.test.ts @@ -227,6 +227,12 @@ describe("Jalaali", () => { expect(yearRange).toHaveLength(4); }); + it("Jalaali -- setAndGetMonth", () => { + const date = jalaaliUtils.date(TEST_TIMESTAMP); + const newDate = jalaaliUtils.setMonth(date, 0); + expect(jalaaliUtils.getMonth(newDate)).toBe(0); + }); + test.each` format | expected ${"keyboardDate"} | ${"۱۳۹۸/۱۰/۱۱"} diff --git a/packages/jalaali/src/jalaali-utils.ts b/packages/jalaali/src/jalaali-utils.ts index 27f74b96..e7c3b7f3 100644 --- a/packages/jalaali/src/jalaali-utils.ts +++ b/packages/jalaali/src/jalaali-utils.ts @@ -107,6 +107,10 @@ export default class MomentUtils extends DefaultMomentUtils { return date.jMonth(); }; + public setMonth = (date: Moment, month: number) => { + return date.clone().jMonth(month); + }; + public getDaysInMonth = (date: Moment) => { return date.daysInMonth(); };