Fix an issue that TypeError occurs by cast to Date from undefined

Fixes #2272.