almende / chap-links-library

a web based visualization library for displaying graphs, networks, and timelines
http://almende.github.com/chap-links-library
Apache License 2.0
599 stars 167 forks source link

Display DB Dates #293

Open neoneddie opened 10 years ago

neoneddie commented 10 years ago

Date is off by one month

I know this has been covered and that JS is zero based (or something like this). But I am still confused by the date that I want to be displayed is not displayed.

IE: 'start': new Date(2014,4,2), ...does not show a milestone on 4/2/2014

My timeline deals with business days of the week. I am pulling the dates from a MySQL database that I want to be displayed on the timeline. So if the MySQL date is Wednesday 4-2-2014, and I want a point to display as 4-2-2014 on the timeline, wouldn't I have to subtract a month from that date to display it correctly on the timeline? Once I do that, the days of the week will always be messed up.

Bottom line is:

  1. I am trying to display the dates that are pulled from a DB to be the same on the timeline.
  2. And, subsequent points on the timeline is to be plus (+) 3 business days (for example).

I already know how to calculate the business days and format them into the Y,m,d format. But what I can't do is enter this number into the timeline script because the date is a month off.

I hope I am clear.

josdejong commented 10 years ago

Well, you just need to convert your MySQL date in a correct way to a JavaScript date. There are plenty of ways do do that. Lets say we want to convert April 15th, 2014 into a JavaScript date:

So depending on what date fromat you get from your MySQL data, you have to run a for loop over the data to convert the start and end properties in valid JavaScript dates, and then feed that to the Timeline.