xsoh / moment-hijri

A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js
http://momentjs.com/docs/#/plugins/hijri/
MIT License
200 stars 82 forks source link

moment().endOf('hUnit') is not working .. #7

Closed MhdSyrwan closed 9 years ago

MhdSyrwan commented 9 years ago

Hi, Thank you very much for making this plugin :+1: . I'm trying to execute this line (from the readme)

moment('2014-11-28 16:40:00', 'YYYY-M-D HH:mm:ss').endOf('hMonth').format('hYYYY/hM/hD HH:mm:ss'); // 1436/2/30 23:59:59

it doesn't give the result mentioned in the comment 1436/2/30 23:59:59 and also tried many variants, it looks like endOf method is not affecting the date if given hmounth or hyear or anything outside the standard moment units.

Any thoughts about this ?

MhdSyrwan commented 9 years ago

After looking at the original code of moment here i tried doing it manually like

moment('2014-11-28 16:40:00', 'YYYY-M-D HH:mm:ss').startOf('hmonth').add(1, 'hmonth').subtract(1, 'milliseconds').format('hYYYY/hM/hD HH:mm:ss'); // 1436/2/30 23:59:59

And it worked ! :smile:

It seems that there's a problem running normalizeUnits or it could be solved by adding a definition for the method endOf in this repo just like what have you done for the startOf here

msarhan commented 9 years ago

Issue fixed! Thanks!

MhdSyrwan commented 9 years ago

Thanks for your quick response :+1: