diff --git a/moment-hijri.js b/moment-hijri.js index 8fd782d..9b9b43c 100644 --- a/moment-hijri.js +++ b/moment-hijri.js @@ -645,6 +645,10 @@ lastDay = Math.min(h.hd, hMoment.iDaysInMonth(input, h.hm)) g = toGregorian(input, h.hm, lastDay) setDate(this, g.gy, g.gm, g.gd) + //Workaround: sometimes moment wont set the date correctly if current day is the last in the month + if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) { + setDate(this, g.gy, g.gm, g.gd) + } moment.updateOffset(this) return this } else { @@ -673,6 +677,10 @@ } g = toGregorian(this.iYear(), input, lastDay) setDate(this, g.gy, g.gm, g.gd) + //Workaround: sometimes moment wont set the date correctly if current day is the last in the month + if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) { + setDate(this, g.gy, g.gm, g.gd) + } moment.updateOffset(this) return this } else { @@ -686,6 +694,10 @@ h = toHijri(this.year(), this.month(), this.date()) g = toGregorian(h.hy, h.hm, input) setDate(this, g.gy, g.gm, g.gd) + //Workaround: sometimes moment wont set the date correctly if current day is the last in the month + if (this.month() !== g.gm || this.date() !== g.gd || this.year() !== g.gy) { + setDate(this, g.gy, g.gm, g.gd) + } moment.updateOffset(this) return this } else {