Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Timefix for both 1.9.3 and REE using iso8601 instead of round.
  • Loading branch information
leifcr committed Sep 24, 2012
1 parent 26f1df3 commit a70195f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/mongo_mapper/extensions/time.rb
Expand Up @@ -8,12 +8,7 @@ def to_mongo(value)
else
time_class = ::Time.try(:zone).present? ? ::Time.zone : ::Time
time = value.is_a?(::Time) ? value : time_class.parse(value.to_s)
# for ree (1.8.7) versions
if RUBY_VERSION < "1.9"
at(Float((time.to_f*1000).to_i)/Float(1000)).utc if time # ensure milliseconds are preserved with to_f (issue #308)
else
at(time.to_f).utc.round(3) if time # ensure milliseconds are preserved with to_f (issue #308)
end
iso8601(time.utc.iso8601(3)).utc if time # keep time with milliseconds. (Same as BSON time)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_time_zones.rb
Expand Up @@ -11,7 +11,7 @@ class TimeZonesTest < Test::Unit::TestCase

should "preserve milliseconds" do
doc = @document.new(:created_at => '2011-02-12 16:01:02.543Z')
doc.created_at.should be_close(Time.parse('2011-02-12 16:01:02.543Z'), 0.0000001)
doc.created_at.should be_close(Time.parse('2011-02-12 16:01:02.543Z'), 0.0001)
end

should "work without Time.zone" do
Expand Down

0 comments on commit a70195f

Please sign in to comment.