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) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -