The Problem
I'm using nvd3
to render some date-specific data. However, if there was no data for a particular date, no record exists for it, and nvd3 does not render that data point, instead interpolating between the data points that do exist. I therefore need to generate the missing dates so that nvd3 displays dates which had no data associated with them.
What I want to do
I need to generate an array that looks like this:
[ {year: 2015, month: 1, day: 1},
{year: 2015, month: 1, day: 2},
...
]
The function generating this array will take a starting date and an ending date, and generate all days between those two dates.
I will then merge it with my data array. That way dates that have data will have data, and dates that don't have data will still show up on the graph, without skipping over any missing dates.
Is there an easy way to do this with the Date
object? I.e. when generating this array I need to know which months have 30 or 31 days, that February is special, leap years, etc, etc... I could brute-force it by specifying the number of days for each month, but I'd like to know if there's any easier way to do this.