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

duplicate days. #29

Open
m-reda1996 opened this issue Apr 16, 2024 · 13 comments
Open

duplicate days. #29

m-reda1996 opened this issue Apr 16, 2024 · 13 comments

Comments

@m-reda1996
Copy link

m-reda1996 commented Apr 16, 2024

sometimes we get duplicate days, it's not consistent but it happens quit often, we're not using anything advanced.

  const [selectedDate, setSelectedDate] = React.useState(() => toDateId(new Date()));
  
<Calendar
  calendarMonthId={currentMonth}
  onCalendarDayPress={(toDateId) => {
    console.log(toDateId);
  }}
  theme={process.env.EXPO_PUBLIC_PRIMARY_DEFAULT === "#EEEEDE" ? linearThemeDark : linearThemeLight}
  />                 
Screenshot 2024-04-16 at 10 35 19 PM Screenshot 2024-04-16 at 10 38 44 PM
@AlirezaHadjar
Copy link
Contributor

This happens to me as well.
Here is the scenario that creates the duplicate key warning:

Set the default date to now. Then set the year to 2020, and subtract 1 month from that date.

@MarceloPrado let me know if this didn't reproduce the bug, and then I will create a repro.

@a-eid
Copy link

a-eid commented Apr 17, 2024

we're also facing this duplicate day issue.

@MarceloPrado
Copy link
Owner

Hi folks! Could you share a snippet that helps reproing the issue? Something like this would be really helpful for me

@AlirezaHadjar
Copy link
Contributor

AlirezaHadjar commented Apr 21, 2024

Sure thing, I'll try to create one in the next week 👍

@AlirezaHadjar
Copy link
Contributor

Hi @MarceloPrado, Here is the link to the minimal bug reproducer. Here are the steps to follow to get to the warning:

  1. Clone the repo
  2. Install deps
  3. run the project
  4. Click on the Set Year to 2020
  5. Click on the Reduce Month by 1
  6. Warning shows up

Here is the video of it:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-04-26.at.13.33.12.mp4

If you press Reduce Month by 1 a few times more, you will see that the styles of days break.
Screenshot 2024-04-26 at 1 34 48 PM

Let me know if you needed any more information 😉

@MarceloPrado
Copy link
Owner

@AlirezaHadjar thanks for taking the time with the repro. Interestingly, I can't repro the duplicate key error:

CleanShot.2024-04-26.at.10.13.13.mp4

I tried running with both bun and yarn, just to rule out any dependency issues. Are you able to repro it consistently?

@AlirezaHadjar
Copy link
Contributor

@MarceloPrado I'm using yarn and yarn ios for building the project on Expo Go. and yes this happens to me consistently.

2024-04-26_17-06-27.mp4

@AlirezaHadjar
Copy link
Contributor

@a-eid @m-reda1996 could any of you guys try out the repro I shared please and see if the issue happens to you or not? If not, we can reproduce it in another way

@MarceloPrado
Copy link
Owner

@AlirezaHadjar I tried again from a different computer and unfortunately it also didn't repro it 😔
It could be easier if you jump into the source code on your side to debug it

@AlirezaHadjar
Copy link
Contributor

Yeah sure, I'll do it when I find some free time 🙂

@AlirezaHadjar
Copy link
Contributor

AlirezaHadjar commented May 7, 2024

@MarceloPrado I dug deeper and found out that sometimes two dates get the same id and label. And the reason you don't face this is because of our timezone difference.

For example 2020-03-19T20:30:00.000Z and 2020-03-20T19:30:00.000Z will be displayed as 2020 3 20. And that's why I get two 20s on the calendar

Screenshot 2024-05-07 at 9 04 32 PM

I changed

export function toDateId(date: Date) {
  const year = date.getFullYear();
  const month = date.getMonth() + 1; // getMonth() returns 0-11
  const day = date.getDate();

  // Pad single digit month and day with leading zeros
  const monthFormatted = month < 10 ? `0${month}` : month;
  const dayFormatted = day < 10 ? `0${day}` : day;

  return `${year}-${monthFormatted}-${dayFormatted}`;
}

to:

export function toDateId(date: Date) {
  const year = date.getUTCFullYear();
  const month = date.getUTCMonth() + 1; // getMonth() returns 0-11
  const day = date.getUTCDate();

  // Pad single digit month and day with leading zeros
  const monthFormatted = month < 10 ? `0${month}` : month;
  const dayFormatted = day < 10 ? `0${day}` : day;

  return `${year}-${monthFormatted}-${dayFormatted}`;
}

This fixed the id issue but the display function getBaseCalendarDayFormat still displays both of them as 2020 3 20. And I don't think my method is the best option.

BTW, my timezone is Asia/Tehran. I think if you change your timezone to mine, you can reproduce the issue.

@MarceloPrado
Copy link
Owner

@AlirezaHadjar nice find! thanks!
I'll work on a fix soon and let you know 🙏

@MarceloPrado
Copy link
Owner

I was able to repro locally but don't have a good fix yet. Turns out Tehran abolished DST timezones couple of years ago and I'm not entirely sure the best way to handle that lol

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

4 participants