Fix undefined method year for empty string (resolves #18609).