Fix date calculations

See for instance http://jsfiddle.net/yKJ59/
Merge pull request #92 from mlocati/fix-end-date-calculation

Fix date calculations