Skip to content

Commit

Permalink
fix(moment-jalaali): setMonth behavior (#661)
Browse files Browse the repository at this point in the history
* Fixed set month

Modified setMonth method to works with jalali month value

* chore: Change test name

---------

Co-authored-by: Soheil Hasankhani <soheil.hasankhani@pishtazan.onmicrosoft.com>
Co-authored-by: Dmitriy Kovalenko <dmtr.kovalenko@outlook.com>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent 9d30428 commit 8d43c2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __tests__/jalaali.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ describe("Jalaali", () => {
expect(yearRange).toHaveLength(4);
});

it("Jalaali -- setMonth", () => {
const date = jalaaliUtils.date(TEST_TIMESTAMP);
const newDate = jalaaliUtils.setMonth(date, 0);
expect(jalaaliUtils.getMonth(newDate)).toBe(0);
});

test.each`
format | expected
${"keyboardDate"} | ${"۱۳۹۸/۱۰/۱۱"}
Expand Down
4 changes: 4 additions & 0 deletions packages/jalaali/src/jalaali-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit 8d43c2f

Please sign in to comment.