adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.87k stars 1.12k forks source link

Gregorian -> Persian Calendar date conversion is occasionally inaccurate #3757

Closed LFDanLu closed 6 months ago

LFDanLu commented 1 year ago

Discussed in https://github.com/adobe/react-spectrum/discussions/3702

Originally posted by **farboood** November 2, 2022 When I convert the "Gregorian Date" to "Persian Date", it converts all the days between (include) 22 and 30 into the 30th of the "Persian Calendar" month. ex. { year: 2022, month: 12, day: 20 } --> { year: 1401, month: 9, day: 29 } { year: 2022, month: 12, day: 21 } --> { year: 1401, month: 9, day: 30 } { year: 2022, month: 12, day: 22 } --> { year: 1401, month: 9, day: 30 } ... { year: 2022, month: 12, day: 30 } --> { year: 1401, month: 9, day: 30 } { year: 2022, month: 12, day: 31 } --> { year: 1401, month: 10, day: 10 }
amirhhashemi commented 1 year ago

I'm experiencing the same bug. isSameDay returns a wrong result when I compare a Gregorian date with a Persian date:

const persian = new CalendarDate(new PersianCalendar(), 1401, 12, 8);
const gregorian = new CalendarDate(new GregorianCalendar(), 2023, 2, 27);

// This returns `true` which is correct:
isSameDay(gregorian, persian);

// But this returns `false` because under the hood it converts the Gregorian date to Persian:
isSameDay(persian, gregorian),

Hope it gets resolved soon

ImanAkrami commented 9 months ago

I think I am facing an issue that is related to this one. when using a PersianCalender for the date picker ( or providing the locale), the first 6 months seem okay. but from the 7th month on, you can't choose the first days of the month ( the onChange value sends back an incorrect date). and it goes like this:

7th month, can't choose the first date 8th month, can't choose the first and second days

etc.

B-Esmaili commented 8 months ago

This is exactly what is happening to me. I created a playground that demonstrates the issue. The playground produces mapping for last Persian year of related Gregorian date and it only works correct for first six months. this is the link for playground.

B-Esmaili commented 8 months ago

Actually this issue being open for more than a year without a single comment from the maintainers worries me a lot. I would appreciate if you let us know about your agenda for this bug. After all it is a vital bug which makes the library almost useless for the user not a feature request. Thank you.

Edit: I see that the issue is related to DatePicker component but i am not using react component i am using another library which uses the @internationalized\date package.

@matthewdeutsch @LFDanLu

LFDanLu commented 8 months ago

Hi @B-Esmaili, apologies but the team hasn't been able to pick this up due to conflicting priorities. I'll see if we can try to get it into an upcoming sprint but we'd gladly welcome any help looking into this issue!

B-Esmaili commented 8 months ago

@LFDanLu Thanks for your response , frankly i am not good at calendars this is why i am using a library :smile: , but i know a library which implemented Persian Calendar currectly. You can take a look and get point. This is the best i can help for now. but maybe in the future i would do some contributions after enough study.

enigma0098 commented 7 months ago

Hi. I fixed the issue and created a pull request #5946. could you check the possibility of merging? thanks for your time.