diff options
author | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2015-06-17 20:01:18 +0900 |
---|---|---|
committer | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2015-09-30 20:10:55 +0900 |
commit | 602ffe2a63a455bf4a8177552226db955b59e493 (patch) | |
tree | 4e81ab8e59c11a2c138e5053a7cf7b69a5c7c9ad /activesupport/lib/active_support/time_with_zone.rb | |
parent | 591a0bb87fff7583e01156696fbbf929d48d3e54 (diff) | |
download | rails-602ffe2a63a455bf4a8177552226db955b59e493.tar.gz rails-602ffe2a63a455bf4a8177552226db955b59e493.tar.bz2 rails-602ffe2a63a455bf4a8177552226db955b59e493.zip |
TimeWithZone#xmlschema should be able to display more than 6 digits
Diffstat (limited to 'activesupport/lib/active_support/time_with_zone.rb')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index a82a7dfea0..3592dcba39 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -41,6 +41,9 @@ module ActiveSupport 'Time' end + PRECISIONS = Hash.new { |h, n| h[n] = "%FT%T.%#{n}N".freeze } + PRECISIONS[0] = '%FT%T'.freeze + include Comparable attr_reader :time_zone @@ -142,11 +145,7 @@ module ActiveSupport # # Time.zone.now.xmlschema # => "2014-12-04T11:02:37-05:00" def xmlschema(fraction_digits = 0) - fraction = if fraction_digits.to_i > 0 - (".%06i" % time.usec)[0, fraction_digits.to_i + 1] - end - - "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}" + "#{time.strftime(PRECISIONS[fraction_digits.to_i])}#{formatted_offset(true, 'Z'.freeze)}" end alias_method :iso8601, :xmlschema |