aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time/conversions.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-06-13 12:01:12 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-06-13 12:01:12 +0100
commit17f5d8e062909f1fcae25351834d8e89967b645e (patch)
treef0be19ac442bf39a41bc8b0b2a7231d7459802c6 /activesupport/lib/active_support/core_ext/date_time/conversions.rb
parentb3bc3aa5cbe7540de21ae4eb566886e3b8efe6e3 (diff)
downloadrails-17f5d8e062909f1fcae25351834d8e89967b645e.tar.gz
rails-17f5d8e062909f1fcae25351834d8e89967b645e.tar.bz2
rails-17f5d8e062909f1fcae25351834d8e89967b645e.zip
Keep sub-second resolution when wrapping a DateTime value
Add `DateTime#usec` and `DateTime#nsec` so that `ActiveSupport::TimeWithZone` keeps sub-second resolution when wrapping a `DateTime` value. Fixes #10855
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index df07917d19..c44626aed9 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -80,6 +80,16 @@ class DateTime
seconds_since_unix_epoch.to_i
end
+ # Returns the fraction of a second as microseconds
+ def usec
+ (sec_fraction * 1_000_000).to_i
+ end
+
+ # Returns the fraction of a second as nanoseconds
+ def nsec
+ (sec_fraction * 1_000_000_000).to_i
+ end
+
private
def offset_in_seconds