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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -