TypeError occurs by cast to Date from undefined

Fixes #2272.