提交 dd339bb0 编写于 作者: A Andrew White

Make ActiveSupport::TimeWithZone#xmlschema consistent

Both Time#xmlschema and DateTime#xmlschema can accept nil values for the
fraction_digits parameter. This commit makes this so for TimeWithZone
values as well.
上级 c0965004
......@@ -132,8 +132,8 @@ def inspect
end
def xmlschema(fraction_digits = 0)
fraction = if fraction_digits > 0
(".%06i" % time.usec)[0, fraction_digits + 1]
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')}"
......
......@@ -111,6 +111,10 @@ def test_xmlschema_with_fractional_seconds_lower_than_hundred_thousand
assert_equal "1999-12-31T19:00:00.001234-05:00", @twz.xmlschema(12)
end
def test_xmlschema_with_nil_fractional_seconds
assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema(nil)
end
def test_to_yaml
assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册