Use Time#mktime_with_offset
This commit is contained in:
parent
f65d8bbbcc
commit
e4ad16b77c
|
@ -138,10 +138,12 @@ module CouchRest
|
||||||
if value.is_a?(Hash)
|
if value.is_a?(Hash)
|
||||||
typecast_hash_to_time(value)
|
typecast_hash_to_time(value)
|
||||||
else
|
else
|
||||||
Time.parse(value.to_s)
|
Time.mktime_with_offset(value.to_s)
|
||||||
end
|
end
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
value
|
value
|
||||||
|
rescue TypeError
|
||||||
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a DateTime instance from a Hash with keys :year, :month, :day,
|
# Creates a DateTime instance from a Hash with keys :year, :month, :day,
|
||||||
|
|
|
@ -509,15 +509,19 @@ describe "ExtendedDocument properties" do
|
||||||
|
|
||||||
describe 'and value is a string' do
|
describe 'and value is a string' do
|
||||||
it 'parses the string' do
|
it 'parses the string' do
|
||||||
@course.ends_at = '22:24'
|
t = Time.now
|
||||||
@course['ends_at'].hour.should eql(22)
|
@course.ends_at = t.strftime('%Y/%m/%d %H:%M:%S %z')
|
||||||
@course['ends_at'].min.should eql(24)
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not typecast non-time values' do
|
it 'does not typecast non-time values' do
|
||||||
pending 'Time#parse is too permissive'
|
@course.ends_at = 'not-time'
|
||||||
@course.started_on = 'not-time'
|
|
||||||
@course['ends_at'].should eql('not-time')
|
@course['ends_at'].should eql('not-time')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue