Changed the set_metadata function to safely check for the date key.

This is a fix for issue #1106.