Browse files

Improve code

  • Loading branch information...
1 parent 218e15e commit 8aadf5786b651af8777d85ea786aaabdeb294644 @brutuscat brutuscat committed Dec 6, 2012
View
1 .gitignore
@@ -34,6 +34,5 @@ measurements
.bundle
Gemfile.lock
bin/
-vendor/
## PROJECT::SPECIFIC
View
6 lib/virtus/coercion/float.rb
@@ -22,10 +22,10 @@ def self.to_float(value)
# Coerce given value to a DateTime
#
# @example
- # date = Virtus::Coercion::Float.to_datetime(1000000000.999) # => Sun, 09 Sep 2001 01:46:40 +0000
- # date.to_f # => 1000000000.999
+ # datetime = Virtus::Coercion::Float.to_datetime(1000000000.999) # => Sun, 09 Sep 2001 01:46:40 +0000
+ # datetime.to_f # => 1000000000.999
#
- # @param [Fixnum] value
+ # @param [Float] value
#
# @return [DateTime]
#
View
9 lib/virtus/coercion/integer.rb
@@ -60,14 +60,17 @@ def self.to_boolean(value)
# @example
# Virtus::Coercion::Fixnum.to_datetime(0) # => Thu, 01 Jan 1970 00:00:00 +0000
#
- # @param [Fixnum] value
+ # @param [Integer] value
#
# @return [DateTime]
#
# @api public
def self.to_datetime(value)
- # OPTIMIZE: We should use "%s"(seconds) but there is a bug in rubinius: see issue #2082
- ::DateTime.strptime((value * 10**3).to_s, "%Q")
+ # FIXME: Remove after Rubinius 2.0 is released
+ datetime_format = RUBY_ENGINE == 'rbx' ? '%Q' : '%s'
+ value = RUBY_ENGINE == 'rbx' ? "#{value * 10**3}" : "#{value}"
+
+ ::DateTime.strptime(value, datetime_format)
end
end # class Fixnum
View
2 spec/unit/virtus/attribute/date_time/coerce_spec.rb
@@ -64,14 +64,12 @@
let(:value) { 1302139609 }
it_should_behave_like 'a correct date time'
- it { should == ::DateTime.strptime((value * 10**3).to_s, "%Q") }
end
context 'with a float with the seconds and milliseconds since the Unix Epoch' do
let(:value) { 1302139609.664 }
it_should_behave_like 'a correct date time'
- it { should == ::DateTime.strptime((value * 10**3).to_s, "%Q") }
end
context 'with a on-date value' do

0 comments on commit 8aadf57

Please sign in to comment.