[ruby/time] Do not redefine Time#xmlschema if it already exists
[Feature #20707] Ruby 3.4 will define this method natively, so the time gem shouldn't redefine it with a slower version. https://github.com/ruby/time/commit/f05099ce38
This commit is contained in:
parent
f250296efa
commit
72acd1c8b1
59
lib/time.rb
59
lib/time.rb
@ -695,35 +695,36 @@ class Time
|
|||||||
getutc.strftime('%a, %d %b %Y %T GMT')
|
getutc.strftime('%a, %d %b %Y %T GMT')
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
unless method_defined?(:xmlschema)
|
||||||
# Returns a string which represents the time as a dateTime defined by XML
|
#
|
||||||
# Schema:
|
# Returns a string which represents the time as a dateTime defined by XML
|
||||||
#
|
# Schema:
|
||||||
# CCYY-MM-DDThh:mm:ssTZD
|
#
|
||||||
# CCYY-MM-DDThh:mm:ss.sssTZD
|
# CCYY-MM-DDThh:mm:ssTZD
|
||||||
#
|
# CCYY-MM-DDThh:mm:ss.sssTZD
|
||||||
# where TZD is Z or [+-]hh:mm.
|
#
|
||||||
#
|
# where TZD is Z or [+-]hh:mm.
|
||||||
# If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
|
#
|
||||||
#
|
# If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
|
||||||
# +fraction_digits+ specifies a number of digits to use for fractional
|
#
|
||||||
# seconds. Its default value is 0.
|
# +fraction_digits+ specifies a number of digits to use for fractional
|
||||||
#
|
# seconds. Its default value is 0.
|
||||||
# require 'time'
|
#
|
||||||
#
|
# require 'time'
|
||||||
# t = Time.now
|
#
|
||||||
# t.iso8601 # => "2011-10-05T22:26:12-04:00"
|
# t = Time.now
|
||||||
#
|
# t.iso8601 # => "2011-10-05T22:26:12-04:00"
|
||||||
# You must require 'time' to use this method.
|
#
|
||||||
#
|
# You must require 'time' to use this method.
|
||||||
def xmlschema(fraction_digits=0)
|
#
|
||||||
fraction_digits = fraction_digits.to_i
|
def xmlschema(fraction_digits=0)
|
||||||
s = strftime("%FT%T")
|
fraction_digits = fraction_digits.to_i
|
||||||
if fraction_digits > 0
|
s = strftime("%FT%T")
|
||||||
s << strftime(".%#{fraction_digits}N")
|
if fraction_digits > 0
|
||||||
|
s << strftime(".%#{fraction_digits}N")
|
||||||
|
end
|
||||||
|
s << (utc? ? 'Z' : strftime("%:z"))
|
||||||
end
|
end
|
||||||
s << (utc? ? 'Z' : strftime("%:z"))
|
|
||||||
end
|
end
|
||||||
alias iso8601 xmlschema
|
alias iso8601 xmlschema unless method_defined?(:iso8601)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user