View Rahoul Baruah's profile on LinkedIn Basecamp project management and collaboration

The blog of Rahoul Baruah from 3hv Ltd

What's going on?

My name is Rahoul Baruah (aka Baz) and I'm a software developer in Leeds (England).

This is a log of things I've discovered while writing software in Ruby on Rails. In other words, geek stuff.

However, I've decided to put this blog on ice - I would ask you to check out my business blog here (or subscribe here).

07 July, 2006

ActionWebService and dates

As I mentioned before, I have been having a few problems passing dates, date/times and times over ActionWebService.

I'm not too sure where the fault occurs but it seems to manifest itself in ActionWebService/casting.rb. Each field from your model is passed through as a value along with a type identifier. The areas where I am having problems are where that type is :date, :datetime or :time. In each case, casting.rb examines the type parameter and chooses to treat the value as a Date, DateTime or Time object respectively. Sounds sensible no?

But, somewhere along the line the type and the actual object do not match. If you call DateTime.parse(t.to_s) when t.is_a? Time you get an error. The call to parse only works if t.is_a? DateTime. The same applies for Date.parse and Time.parse.

I have amended casting.rb to get around this problem (starting at line 98):


when :time
value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash)
if value.is_a? Time
return value
else
return Time.parse(value.to_s)
end
when :date
value = "#{value['2']}/#{value['3']}/#{value['1']}" if value.kind_of?(Hash)
if value.is_a? Time
return value
else
return Date.parse(value.to_s)
end
when :datetime
value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash)
if value.is_a? Time
return value
else
DateTime.parse(value.to_s)
end


However, this is just a bandage on the symptom and does not solve the underlying cause. I'm still hunting for that one.

PS: Of course, if you want to deploy your application to a different server you're as well to freeze Rails into your application's vendor folder to make sure your amendments aren't forgotten.

No comments:

eXTReMe Tracker