From 7079378fefcbaed8a4943cf3681f6c5dec954860 Mon Sep 17 00:00:00 2001 From: mrafei Date: Fri, 27 Jan 2023 11:12:56 +0330 Subject: [PATCH] fix: update jalaali-utils getDaysInMonth and add missing overrides --- packages/jalaali/src/jalaali-utils.ts | 37 ++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/jalaali/src/jalaali-utils.ts b/packages/jalaali/src/jalaali-utils.ts index 81d9625a..f08496ae 100644 --- a/packages/jalaali/src/jalaali-utils.ts +++ b/packages/jalaali/src/jalaali-utils.ts @@ -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) => { @@ -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; + }; }