Fix bug when setting a date field with undefined value

This pull request is a simple fix for a bug that occurs when setting a date field with an undefined value.

Only change is to add a defensive check against an undefined value to the condition before invoking function calls on the value.