diff options
author | Jason Frey (Fryguy) <fryguy9@yahoo.com> | 2009-06-05 13:46:42 -0400 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2009-06-07 20:16:08 -0500 |
commit | 1d9346428b3f12a42f717a7b1313cd4375d23e23 (patch) | |
tree | 34eb2a4f2fc6f62e3ec54a534ec174e164077fbc /activesupport/lib/active_support/core_ext/string | |
parent | 04eb2b72b400384fe49e31b95c11c68cab2aca8e (diff) | |
download | rails-1d9346428b3f12a42f717a7b1313cd4375d23e23.tar.gz rails-1d9346428b3f12a42f717a7b1313cd4375d23e23.tar.bz2 rails-1d9346428b3f12a42f717a7b1313cd4375d23e23.zip |
String #to_time and #to_datetime: handle fractional seconds [#864 state:resolved]
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 2b9f8c70f6..331416b3a9 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -9,7 +9,9 @@ class String # Form can be either :utc (default) or :local. def to_time(form = :utc) - ::Time.send("#{form}_time", *::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) + d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction).map { |arg| arg || 0 } + d[6] *= 1000000 + ::Time.send("#{form}_time", *d) end def to_date @@ -17,6 +19,8 @@ class String end def to_datetime - ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) + d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :sec_fraction).map { |arg| arg || 0 } + d[5] += d.pop + ::DateTime.civil(*d) end end |