Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ private static DateTimeZone parseZoneString(ThreadContext context, String zone)

// MRI: utc_offset_arg
public static DateTimeZone getTimeZoneFromUtcOffset(ThreadContext context, IRubyObject arg) {
String strOffset = arg.toString();
DateTimeZone cachedZone = context.runtime.getTimezoneCache().get(strOffset);
if (cachedZone != null) return cachedZone;

// No lookup by arg.toString() in the runtime's timezone cache: it also holds TZ values (TZ "UTC" is
// Etc/UTC there) and 3600 and "3600" would share a key. getTimeZoneWithOffset caches the zone.
DateTimeZone dtz;
IRubyObject tmp;

Expand Down Expand Up @@ -345,8 +343,6 @@ public static DateTimeZone getTimeZoneFromUtcOffset(ThreadContext context, IRuby
dtz = getTimeZoneWithOffset(context, "", newOffset);
}

context.runtime.getTimezoneCache().put(strOffset, dtz);

return dtz;
}

Expand Down
13 changes: 13 additions & 0 deletions spec/ruby/core/time/utc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
Time.now(in: "UTC").utc?.should == true
end

it "does treat time with 'UTC' offset as UTC when the local time zone is UTC" do
with_timezone("UTC") do
Time.now.utc?.should == false

Time.new(2022, 1, 1, 0, 0, 0, "UTC").utc?.should == true
Time.now.localtime("UTC").utc?.should == true
Time.at(Time.now, in: 'UTC').utc?.should == true

Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").utc?.should == true
Time.now(in: "UTC").utc?.should == true
end
end

it "does treat time with Z offset as UTC" do
Time.new(2022, 1, 1, 0, 0, 0, "Z").utc?.should == true
Time.now.localtime("Z").utc?.should == true
Expand Down
1 change: 0 additions & 1 deletion spec/tags/ruby/core/time/getlocal_tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fails:Time#getlocal returns a Time with a UTC offset of the specified number of Rational seconds
fails:Time#getlocal raises ArgumentError if the String argument is not in an ASCII-compatible encoding
fails:Time#getlocal with an argument that responds to #to_r coerces using #to_r
fails(not implemented, jruby/jruby#6161):Time#getlocal raises ArgumentError if the String argument is not of the form (+|-)HH:MM
fails:Time#getlocal raises ArgumentError if String argument and seconds greater than 59
2 changes: 0 additions & 2 deletions spec/tags/ruby/core/time/localtime_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
fails:Time#localtime returns a Time with a UTC offset of the specified number of Rational seconds
fails:Time#localtime raises ArgumentError if the String argument is not in an ASCII-compatible encoding
fails:Time#localtime with an argument that responds to #to_r coerces using #to_r
fails:Time#localtime does nothing if already in a local time zone
fails(not implemented, jruby/jruby#6161):Time#localtime raises ArgumentError if the String argument is not of the form (+|-)HH:MM
fails:Time#localtime raises ArgumentError if String argument and minutes greater than 59
fails:Time#localtime raises ArgumentError if String argument and seconds greater than 59
fails:Time#localtime with an argument that responds to #utc_to_local coerces using #utc_to_local
1 change: 0 additions & 1 deletion spec/tags/ruby/core/time/new_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ fails(not implemented, jruby/jruby#6161):Time.new with a timezone argument Time-
fails(not implemented, jruby/jruby#6161):Time.new with a timezone argument #name method uses the optional #name method for marshaling
fails(not implemented, jruby/jruby#6161):Time.new with a timezone argument #name method cannot marshal Time if #name method isn't implemented
fails(not implemented, jruby/jruby#6161):Time.new with a timezone argument subject's class implements .find_timezone method calls .find_timezone to build a time object at loading marshaled data
fails(only during full spec run):Time.new with a utc_offset argument raises ArgumentError if the String argument is not of the form (+|-)HH:MM
fails:Time.new with a timezone argument returned value by #utc_to_local and #local_to_utc methods cannot have arbitrary #utc_offset if it is an instance of Time
fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument accepts precision keyword argument and truncates specified digits of sub-second part
fails(https://github.com/jruby/jruby/issues/8736):Time.new with a timezone argument Time.new with a String argument raises ArgumentError if date/time parts values are not valid
Expand Down
Loading