Skip to content

Commit f05099c

Browse files
committed
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.
1 parent 6924f97 commit f05099c

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

lib/time.rb

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -695,35 +695,36 @@ def httpdate
695695
getutc.strftime('%a, %d %b %Y %T GMT')
696696
end
697697

698-
#
699-
# Returns a string which represents the time as a dateTime defined by XML
700-
# Schema:
701-
#
702-
# CCYY-MM-DDThh:mm:ssTZD
703-
# CCYY-MM-DDThh:mm:ss.sssTZD
704-
#
705-
# where TZD is Z or [+-]hh:mm.
706-
#
707-
# If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
708-
#
709-
# +fraction_digits+ specifies a number of digits to use for fractional
710-
# seconds. Its default value is 0.
711-
#
712-
# require 'time'
713-
#
714-
# t = Time.now
715-
# t.iso8601 # => "2011-10-05T22:26:12-04:00"
716-
#
717-
# You must require 'time' to use this method.
718-
#
719-
def xmlschema(fraction_digits=0)
720-
fraction_digits = fraction_digits.to_i
721-
s = strftime("%FT%T")
722-
if fraction_digits > 0
723-
s << strftime(".%#{fraction_digits}N")
698+
unless method_defined?(:xmlschema)
699+
#
700+
# Returns a string which represents the time as a dateTime defined by XML
701+
# Schema:
702+
#
703+
# CCYY-MM-DDThh:mm:ssTZD
704+
# CCYY-MM-DDThh:mm:ss.sssTZD
705+
#
706+
# where TZD is Z or [+-]hh:mm.
707+
#
708+
# If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
709+
#
710+
# +fraction_digits+ specifies a number of digits to use for fractional
711+
# seconds. Its default value is 0.
712+
#
713+
# require 'time'
714+
#
715+
# t = Time.now
716+
# t.iso8601 # => "2011-10-05T22:26:12-04:00"
717+
#
718+
# You must require 'time' to use this method.
719+
#
720+
def xmlschema(fraction_digits=0)
721+
fraction_digits = fraction_digits.to_i
722+
s = strftime("%FT%T")
723+
if fraction_digits > 0
724+
s << strftime(".%#{fraction_digits}N")
725+
end
726+
s << (utc? ? 'Z' : strftime("%:z"))
724727
end
725-
s << (utc? ? 'Z' : strftime("%:z"))
726728
end
727-
alias iso8601 xmlschema
729+
alias iso8601 xmlschema unless method_defined?(:iso8601)
728730
end
729-

0 commit comments

Comments
 (0)