Just did a bit of debug and realised that sometimes `d` is not a date object, but a string.

We could be defensive and do something like:

`if (typeof d === 'string') { d = new Date(d); }`

wdyt?