jalaali / moment-jalaali

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

add(1, day) returns the same day, on the first day of any year. #256

Open s11eta1yek opened 1 year ago

s11eta1yek commented 1 year ago

Hello

moment('1401/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1402/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1403/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1404/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1405/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1406/1/1', 'jYYYY/jMM/jDD').add(1, 'day'); moment('1407/1/1', 'jYYYY/jMM/jDD').add(1, 'day');

expected outcome is '140x/1/2', but returns '140x/1/1';

any of these add functions return the same date. it only happens on the first day of the year.

s11eta1yek commented 1 year ago

Screenshot from 2023-11-25 12-45-54 Screenshot from 2023-11-25 12-45-58

I checked the timestamps of the dates. first one is 1402/1/1, and the second one is the result of adding one day to this date.

From what i see, this function adds 23 hours to the first day of the year, instead of adding 24 hours. I don't know the issue that's causing this.

s11eta1yek commented 1 year ago

I looked into the library and it seems that the add function refers to the moment library itself when the unit of addition is in 'day's.

I think the moment library adds the one day, based on its own timezone, and not based on jalali's timezone.

The problem is that, this function should not refer to other timezones because it corrupts the calculations. this is jalali calendar, and it should refer to its own timezone for calculations.

behrang commented 10 months ago

moment is considering timezone when adding days. The date that you said is the day that Daylight Saving Time is activated in Iran (until last year). The calculation is correct if you consider hours and timezone changes.

If you only want to work with dates, you may use jalaali-js.