Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
s11eta1yek opened this issue Nov 25, 2023 · 3 comments
Open

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

s11eta1yek opened this issue Nov 25, 2023 · 3 comments

Comments

@s11eta1yek
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Member

behrang commented Jan 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants