Reputation: 606
So, I have a cal-heatmap calendar working on my website. It displays data from December 2016 to November 2017.
On the same page, I have texts which are divided into different sections.
Here is the code for a section:
<h3 class="sectiontitle" id="week1" style="clear:both;">Week 1</h3>
<div class="divider"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
There is one section for every week in December 2016 to November 2017.
What I want is onClick on cal-heatmap's day, it will scroll to the corresponding section.
For example,
According to cal-heatmap's documentation, I should use onClick(date, value) function. However, I don't know how to change the date given into the week number.
Please note that the date given is in this format: "Tue Jan 04 2000 17:00:00 GMT+0800 (China Standard Time)", not in timestamp format.
So, how can I achieve this? Thanks! I hope that I have explained it clearly.
Upvotes: 1
Views: 540
Reputation: 606
Thanks to @iMatoria , I was able to find the answer.
var week = Math.ceil(((date.getTime() / 1000 - 1480435200) / 86400 - 4) / 7 + 1);
This will give the week number since first day. Where '1480435200' is 31st of November, 2016
Working example: http://2017.igem.org/Team:Hong_Kong_UCCKE/Notebook
Upvotes: 1