Skip to content

Commit 8d43c2f

Browse files
SoheilHasankhaniSoheil HasankhanidmtrKovalenko
authored
fix(moment-jalaali): setMonth behavior (#661)
* Fixed set month Modified setMonth method to works with jalali month value * chore: Change test name --------- Co-authored-by: Soheil Hasankhani <[email protected]> Co-authored-by: Dmitriy Kovalenko <[email protected]>
1 parent 9d30428 commit 8d43c2f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

__tests__/jalaali.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ describe("Jalaali", () => {
227227
expect(yearRange).toHaveLength(4);
228228
});
229229

230+
it("Jalaali -- setMonth", () => {
231+
const date = jalaaliUtils.date(TEST_TIMESTAMP);
232+
const newDate = jalaaliUtils.setMonth(date, 0);
233+
expect(jalaaliUtils.getMonth(newDate)).toBe(0);
234+
});
235+
230236
test.each`
231237
format | expected
232238
${"keyboardDate"} | ${"۱۳۹۸/۱۰/۱۱"}

packages/jalaali/src/jalaali-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export default class MomentUtils extends DefaultMomentUtils {
107107
return date.jMonth();
108108
};
109109

110+
public setMonth = (date: Moment, month: number) => {
111+
return date.clone().jMonth(month);
112+
};
113+
110114
public getDaysInMonth = (date: Moment) => {
111115
return date.daysInMonth();
112116
};

0 commit comments

Comments
 (0)