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)
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue