Hi,
The application is deployed on Heroku, is based on Ruby 3.2.1 and
Rails
1.9.2. Sometimes a function of my props starts throwing this error "
StringUtils:dateTimeFromString, str , can’t dup NilClass" and I don’t
understand the cause. it’s my function:
require ‘time’
module StringUtils
DATE_FORMAT_YYYY_MM_DD=’%Y-%m-%d’
DATE_FORMAT_HH_MM_SS=’%H:%M:%S’
DATE_FORMAT_YYYY_MM_DD_HH_MM_SS=’%Y-%m-%d %H:%M:%S’
DATE_FORMAT_YYYY_MM_DD_T_HH_MM_SS=’%Y-%m-%dT%H:%M:%S’
DATE_FORMAT_YYYYMMDDHHMMSS=’%Y%m%d%H%M%S’
DATE_FORMAT_DAY_OF_WEEK="%A"
def stringFormatDate(strDate,format)
if strDate!=nil
begin
return Time.parse(strDate).strftime(format)
rescue
Rails.logger.error(“StringUtils:stringFormatDate, str
#{strDate},
#{$!}”)
end
end
return strDate
end
- def dateTimeFromString(strDate) *
begin
return Time.parse(strDate)
rescue
Rails.logger.error(“StringUtils:dateTimeFromString, str
#{strDate},
#{$!}”)
return nil
end
end
end
I hope your comments, Thanks
On 21 May 2012, at 17:07, johan rincon [email protected] wrote:
DATE_FORMAT_DAY_OF_WEEK=“%A”
return strDate
end
Can you provide a stack trace from your logs please.
Hi,
This is:
" str , can’t dup NilClass,
[“C:/Ruby192/lib/ruby/1.9.1/date/format.rb:1031:in `dup’”,
“C:/Ruby192/lib/ruby/1.9.1/date/format.rb:1031:in `_parse’”,
“C:/Ruby192/lib/ruby/1.9.1/time.rb:261:in `parse’”, “g.rb:29:in
`dateTimeFromString’”, “g.rb:40:in `initialize’”, “g.rb:45:in `new’”,
“g.rb:45:in `'”]"
I reproduced the error and I detected that when the parameter that
was
sent to the function is nil. But I keep trying because the field is
database and should not be null according to business rules.
I was confused because I found forums where suggested using the
statement ’ unloadable ’ but was inconclusive.
If you have another point of view will be welcome,
thanks
2012/5/21 Jeremy W. [email protected]
require ‘time’
if strDate!=nil
- def dateTimeFromString(strDate) *
“Ruby on Rails: Talk” group.
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Johan Rincn
Ing. en Informtica
UNET