From e4ad16b77c0e16b14150999d8a26b9cfa6478b4f Mon Sep 17 00:00:00 2001 From: wildchild Date: Tue, 21 Jul 2009 09:31:18 +0600 Subject: [PATCH] Use Time#mktime_with_offset --- lib/couchrest/more/property.rb | 4 +++- spec/couchrest/more/property_spec.rb | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/couchrest/more/property.rb b/lib/couchrest/more/property.rb index 7b8a5fe..7fb903b 100644 --- a/lib/couchrest/more/property.rb +++ b/lib/couchrest/more/property.rb @@ -138,10 +138,12 @@ module CouchRest if value.is_a?(Hash) typecast_hash_to_time(value) else - Time.parse(value.to_s) + Time.mktime_with_offset(value.to_s) end rescue ArgumentError value + rescue TypeError + value end # Creates a DateTime instance from a Hash with keys :year, :month, :day, diff --git a/spec/couchrest/more/property_spec.rb b/spec/couchrest/more/property_spec.rb index bf22aba..5bd5275 100644 --- a/spec/couchrest/more/property_spec.rb +++ b/spec/couchrest/more/property_spec.rb @@ -509,15 +509,19 @@ describe "ExtendedDocument properties" do describe 'and value is a string' do it 'parses the string' do - @course.ends_at = '22:24' - @course['ends_at'].hour.should eql(22) - @course['ends_at'].min.should eql(24) + t = Time.now + @course.ends_at = t.strftime('%Y/%m/%d %H:%M:%S %z') + @course['ends_at'].year.should eql(t.year) + @course['ends_at'].month.should eql(t.month) + @course['ends_at'].day.should eql(t.day) + @course['ends_at'].hour.should eql(t.hour) + @course['ends_at'].min.should eql(t.min) + @course['ends_at'].sec.should eql(t.sec) end end it 'does not typecast non-time values' do - pending 'Time#parse is too permissive' - @course.started_on = 'not-time' + @course.ends_at = 'not-time' @course['ends_at'].should eql('not-time') end end