diff --git a/__tests__/jalaali.test.ts b/__tests__/jalaali.test.ts index c87e062..2590147 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 27f74b9..e7c3b7f 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(); };