Skip to content

Commit

Permalink
Fixed set month
Browse files Browse the repository at this point in the history
Modified setMonth method to works with jalali month value
  • Loading branch information
Soheil Hasankhani committed Mar 12, 2024
1 parent 9d30428 commit f5a4a88
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 -- setAndGetMonth", () => {
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 f5a4a88

Please sign in to comment.