mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
TimeWithZone#xmlschema accepts optional fraction_digits argument [#1725 state:resolved]
This commit is contained in:
parent
f1fff0a480
commit
296ca4da17
3 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
*2.3.0 [Edge]*
|
*2.3.0 [Edge]*
|
||||||
|
|
||||||
|
* TimeWithZone#xmlschema accepts optional fraction_digits argument [#1725 state:resolved] [Nicholas Dainty]
|
||||||
|
|
||||||
* Object#tap shim for Ruby < 1.8.7. Similar to Object#returning, tap yields self then returns self. [Jeremy Kemper]
|
* Object#tap shim for Ruby < 1.8.7. Similar to Object#returning, tap yields self then returns self. [Jeremy Kemper]
|
||||||
array.select { ... }.tap(&:inspect).map { ... }
|
array.select { ... }.tap(&:inspect).map { ... }
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,12 @@ module ActiveSupport
|
||||||
"#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
|
"#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def xmlschema
|
def xmlschema(fraction_digits = 0)
|
||||||
"#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{formatted_offset(true, 'Z')}"
|
fraction = if fraction_digits > 0
|
||||||
|
".%i" % time.usec.to_s[0, fraction_digits]
|
||||||
|
end
|
||||||
|
|
||||||
|
"#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}"
|
||||||
end
|
end
|
||||||
alias_method :iso8601, :xmlschema
|
alias_method :iso8601, :xmlschema
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,15 @@ class TimeWithZoneTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_xmlschema_with_fractional_seconds
|
||||||
|
silence_warnings do # silence warnings raised by tzinfo gem
|
||||||
|
@twz += 0.123456 # advance the time by a fraction of a second
|
||||||
|
assert_equal "1999-12-31T19:00:00.123-05:00", @twz.xmlschema(3)
|
||||||
|
assert_equal "1999-12-31T19:00:00.123456-05:00", @twz.xmlschema(6)
|
||||||
|
assert_equal "1999-12-31T19:00:00.123456-05:00", @twz.xmlschema(12)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_to_yaml
|
def test_to_yaml
|
||||||
silence_warnings do # silence warnings raised by tzinfo gem
|
silence_warnings do # silence warnings raised by tzinfo gem
|
||||||
assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml
|
assert_equal "--- 1999-12-31 19:00:00 -05:00\n", @twz.to_yaml
|
||||||
|
|
Loading…
Reference in a new issue