Skip to content

Commit

Permalink
fix: update jalaali-utils getDaysInMonth and add missing overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
mrafei committed Jan 27, 2023
1 parent 6c16bac commit 7079378
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/jalaali/src/jalaali-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class MomentUtils extends DefaultMomentUtils {
};

public getDaysInMonth = (date: Moment) => {
return date.daysInMonth();
return this.moment.jDaysInMonth(date.jYear(), date.jMonth());
};

public startOfYear = (date: Moment) => {
Expand Down Expand Up @@ -201,4 +201,39 @@ export default class MomentUtils extends DefaultMomentUtils {

return years;
};
public addMonths = (date: Moment, count: number) => {
return count < 0
? date.clone().subtract(Math.abs(count), "jMonth")
: date.clone().add(count, "jMonth");
};

public addYears = (date: Moment, count: number) => {
return count < 0
? date.clone().subtract(Math.abs(count), "jYear")
: date.clone().add(count, "jYear");
};

public isSameMonth = (date: Moment, comparing: Moment) => {
return date.jYear() === comparing.jYear() && date.jMonth() === comparing.jMonth();
};

public isSameYear = (date: Moment, comparing: Moment) => {
return date.jYear() === comparing.jYear();
};

public setMonth = (date: Moment, count: number) => {
return date.clone().jMonth(count);
};

public getMonthArray = (date: Moment) => {
const firstMonth = date.clone().startOf("jYear");
const monthArray = [firstMonth];

while (monthArray.length < 12) {
const prevMonth = monthArray[monthArray.length - 1];
monthArray.push(this.getNextMonth(prevMonth));
}

return monthArray;
};
}

0 comments on commit 7079378

Please sign in to comment.