TypeError: can't convert nil into String with DateTime ruby -
i have method returns date utc format
datetime.strptime(json_doc["assetfields"]["originalairdate"], "%y-%m-%d").iso8601
but return error above if json_doc["assetfields"]["originalairdate"] nil
.
i need use .try() method in ruby not throw exception.
i not sure how can achieved datetime.
please help.
maybe setting default date when nil
works you:
default_date = "2014-01-01" datetime.strptime(json_doc["assetfields"]["originalairdate"] || default_date, "%y-%m-%d").iso8601
Comments
Post a Comment