jalaali / moment-jalaali

A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system plugin for moment.js.
MIT License
940 stars 162 forks source link

wrong day when adding a year #221

Closed mdbaniani closed 3 years ago

mdbaniani commented 3 years ago
var start = moment('1370/1/1', 'jYYYY/jM/jD').add(1, 'jYear');
console.log(start.format('jYYYY/jM/jD'))

will result in : 1370/12/30

I expected : 1371/1/1.

Is this expected behavior? please correct me if I am wrong

also:

moment('1370/12/30', 'jYYYY/jM/jD').jMonth() should result in 12 but returns 11.

mdbaniani commented 3 years ago

apparently, setting noon time (12:00) for date object before manipulating, solved the problem:

start.set("hour", 12).set("minute", 0);

behrang commented 3 years ago

This must be the daylight saving time interfering. It's better to set a time in this case. Also, months are zero-based in moment.