Skip to content

Commit a065064

Browse files
committed
Copy iso8601/xmlschema impl from time gem
This is a temporary move until we can follow CRuby and implement a native version of this function. See jruby#8476
1 parent 2a3b623 commit a065064

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,6 @@ private Ruby(RubyInstanceConfig config) {
562562
getLoadService().require("subspawn/replace-builtin");
563563
}
564564
}
565-
566-
// FIXME: How should this be loaded as it is not really stdlib but depends on stdlib to be loaded.
567-
try {
568-
getLoadService().require("time");
569-
} catch (LoadError e) {} // work-around failed classpath only test (which must be omitting stdlib somehow)
570565
}
571566

572567
private void initProfiling() {

core/src/main/ruby/jruby/kernel.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ module JRuby
2929
load 'jruby/kernel/thread.rb'
3030
load 'jruby/kernel/data.rb'
3131
load 'jruby/kernel/integer.rb'
32+
load 'jruby/kernel/time.rb'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Time
2+
# From stdlib time library, see https://github.com/jruby/jruby/issues/8476
3+
unless method_defined?(:xmlschema)
4+
#
5+
# Returns a string which represents the time as a dateTime defined by XML
6+
# Schema:
7+
#
8+
# CCYY-MM-DDThh:mm:ssTZD
9+
# CCYY-MM-DDThh:mm:ss.sssTZD
10+
#
11+
# where TZD is Z or [+-]hh:mm.
12+
#
13+
# If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
14+
#
15+
# +fraction_digits+ specifies a number of digits to use for fractional
16+
# seconds. Its default value is 0.
17+
#
18+
# require 'time'
19+
#
20+
# t = Time.now
21+
# t.iso8601 # => "2011-10-05T22:26:12-04:00"
22+
#
23+
# You must require 'time' to use this method.
24+
#
25+
def xmlschema(fraction_digits=0)
26+
fraction_digits = fraction_digits.to_i
27+
s = strftime("%FT%T")
28+
if fraction_digits > 0
29+
s << strftime(".%#{fraction_digits}N")
30+
end
31+
s << (utc? ? 'Z' : strftime("%:z"))
32+
end
33+
end
34+
alias iso8601 xmlschema unless method_defined?(:iso8601)
35+
end

0 commit comments

Comments
 (0)