fingerpich/jalali-moment

Moment Difference returns wrong number if locale is set to 'fa'

ahmadx87 opened this issue ยท 10 comments

Describe the bug
The package returns wrong number when you want to find the differences (day, month, year, ...) if the locale is set to 'fa'.
moment('2019-10-26').locale('fa').diff(moment('2019-10-28').locale('fa'), 'month') // 108!!
moment('2019-10-26').locale('en').diff(moment('2019-10-28').locale('en'), 'month') // 0

To Reproduce
see demo

I added a test and it worked, but why the demo is wrong? can you check the demo?

Thank for your input.
The fiddle is pretty simple. I don't know how the tests are passing but the demo result is wrong. I even tested it again in a node environment but the result is the same. I get wrong numbers if locale is fa.

can you please check the code and find the problem?

Can you please check the 3.3.5 and the commits? edited demo

Sorry I didn't get a chance to get at it sooner.
I took a look at the commit.
I think there are a few inconsistencies. According to the moment documentation :

If the moment is earlier than the moment you are passing to moment.fn.diff, the return value will be negative.

But in here the absolute value is returned.
Another issue is that only the month difference is checked. What if the years are different? for example 2020.05.30 and 2021.05.30, the month difference would be 0 but with locale 'en' it is 12.

good points. thank you.
can you please create a PR?

Sure, I'll work on that.

I created this pull request #96
I borrowed code from the original moment diff method. The tests are passing. Hope it resolves the issue.

please check v3.3.7

I did several other tests in the browser and it looks fine.
Thanks!