tidepool-org/tideline — pull request #18 by nicolashery (2014-02-21 11:29:44+00:00)
Title: Fix error when two week given end date outside range

How to reproduce (off of `master`):

- Change the oneday initialization in `example.js` to `oneDay.initialize(data).locate();` (line 74), so that it goes to the very end of the data set
- `make example`, load the example in browser, do *not* move the oneday view, click immediately on two week
- Notice the error

@jebeck You know the inner workings of this function better than I, so let me know if you want to change/move this fix, but hopefully this PR gives you an idea of what was going on.

Commit message:

Problem: If two week was given a `viewEndDate` in its `data()` method
that was outside of the "days" array it constructs, it would then error
when rendering because `viewIndex` (which is set according to
`viewEndDate`'s position in the "days" array) would be -1.

Fix: After constructing the "days" array, check that `viewEndDate` is in
range. If it's not, default to the last day.