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

The dates on the heatmap are off by one #112

Open
jyang81 opened this issue Jul 3, 2019 · 11 comments · May be fixed by #128
Open

The dates on the heatmap are off by one #112

jyang81 opened this issue Jul 3, 2019 · 11 comments · May be fixed by #128

Comments

@jyang81
Copy link

jyang81 commented Jul 3, 2019

The day of the week is not rendering correctly. For example, my start date is '2019-03-11', which is a Monday and my end date is '2019-06-21' which is a Friday. But the calendar renders from "Monday 2019-03-12" to "Thursday 2019-06-21", which in incorrect.

My data point for 03-11 does not show up, and my data point for 03-12 shows up on the box where Monday 03-11 is supposed to be. The calendar renders boxes up to 06-21, but it is on Thursday instead of Friday. I'm not sure where the mixup is, but I cannot get it to render correctly.

screenshot-localhost-3000-2019 07 02-18-07-41

screenshot-localhost-3000-2019 07 02-18-08-03

@kevinsqi
Copy link
Owner

I'll be happy to look into it. Can you fork this CodeSandbox and pass in the exact data that you're using to see this behavior? https://codesandbox.io/s/73mk9wlyx

@jyang81
Copy link
Author

jyang81 commented Jul 18, 2019 via email

@kevinsqi
Copy link
Owner

Hi @jyang81. Took a look and there's an issue with how dates are indexed. I'd like to fix this but it'll likely involve some pretty large changes to the component, and I can't guarantee when I'll be able to work on that. Sorry about that!

@jyang81
Copy link
Author

jyang81 commented Jul 24, 2019

Thanks for getting back to me Kevin! I understand this probably isn't your highest priority at the moment. I'll continue to use the package as is, until you are able to fix the issue. Just curious, are there any workarounds I can do to get it to show up correctly for now? If not, it's fine. I can wait until it's fixed. Thanks again, I appreciate it!

@kevinsqi
Copy link
Owner

There isn't a great workaround I can think of right now. I'll let you know if I can come up with something, or when this gets fixed for real.

@oottinger
Copy link

I just ran into this issue as well. For a workaround I just went through my data list and added 1 to the date for each entry. Also use a custom tooltip which accounts for the shift.

@kevinsqi does this library factor in a leap year for the index? Haven't had much time to look at the code to see how things are implemented.

@alelevinas
Copy link

Hi there! I see this PR is merged already but there haven't been any new releases since August 2019.
@kevinsqi wondering if you are still maintaining this project or if it is now deprecated? thanks!

@juliomilani
Copy link

Found a solution:

  • You should replace getDay() by getUTCDay() for string date input and you should add 1 to getNumEmptyDaysAtStart since you added 1 in getStartDate.

Your 67-73 lines should look like this:

getNumEmptyDaysAtStart() {
return this.getStartDate().getUTCDay()+1;
}

getNumEmptyDaysAtEnd() {
return DAYS_IN_WEEK - 1 - this.getEndDate().getUTCDay();
}

@gillkyle
Copy link

I got around this by shifting my weekday labels by 1 🤷 not perfect, but got the job done for me for the time being:

Ie:

<CalendarHeatmap
  weekdayLabels={["M", "T", "W", "Th", "F", "S", "S"]}
/>

ssteele added a commit to ssteele/journal that referenced this issue Jul 27, 2022
@Stophface
Copy link

I think it might be this function.

https://github.com/kevinsqi/react-calendar-heatmap/blob/master/src/index.js, line 55 following
getStartDate() { return shiftDate(this.getEndDate(), -this.getDateDifferenceInDays() + 1); // +1 because endDate is inclusive }

When I remove the + 1, it works. But then again, my timezone is + 1 and I am not sure if that plays into it as well..

@SkylineDev2
Copy link

I figured out 1-line code change at my backend to address "1 day off" issue.

It seems working for me. :)

Instead of assigning date field with the string "2022-12-19",
you will need to use this format "Mon 2022-12-19".


Can't believe how I dig the internet to find this.
If you are interested in how this solution was born. See more references here:

  1. Inspired by others, I set the direction to use a workaround strategy by manipulating the data by +1.
    //Really like this component. I will not give up.
  2. Searching internet, i found this stackoverflow thread

    https://stackoverflow.com/questions/17545708/parse-date-without-timezone-javascript
  3. Watching this youtube, now gain more understanding on JS handling date.

    https://www.youtube.com/watch?v=oKFb2Us9kmg

Now, with 1 line code change to ensure I store heatmap data with above format.
Now, heatmap component works as expected. Yeah!!


Will do more testing with remote team on different timezones.

Let me know whether that works for you. :)

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

Successfully merging a pull request may close this issue.

8 participants