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
15 changes: 7 additions & 8 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,14 @@ public RubyTime localtime(ThreadContext context) {

@JRubyMethod(name = "localtime")
public RubyTime localtime(ThreadContext context, IRubyObject arg) {
final DateTimeZone zone = getTimeZoneFromUtcOffset(context, arg);
setIsTzRelative(false);
final DateTimeZone zone = handleUTCDateTimeZone(context, arg);

if (zone == null) {
throw invalidUTCOffset(context);
} else if (zone == DateTimeZone.UTC) {
return gmtime(context);
}

return adjustTimeZone(context, zone, true);
return adjustTimeZone(context, zone, isTzRelative);
}

private RubyTime adjustTimeZone(ThreadContext context, final DateTimeZone zone, boolean isTzRelative) {
Expand Down Expand Up @@ -2300,15 +2299,15 @@ public static RubyTime timeZoneLocal(ThreadContext context, IRubyObject off, Rub

if (zoneLocalTime(context, zone, time)) return time;

if ((dtz = getTimeZoneFromUtcOffset(context, off)) == null) {
time.setIsTzRelative(false);

if ((dtz = time.handleUTCDateTimeZone(context, off)) == null) {
zone = time.findTimezone(context, zone);
if (!zoneLocalTime(context, zone, time)) throw invalidUTCOffset(context, zone);
return time;
} else if (dtz == DateTimeZone.UTC) {
return time.gmtime(context);
}

time.adjustTimeZone(context, dtz, false);
time.adjustTimeZone(context, dtz, time.isTzRelative);

return time;
}
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/time/utc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@

it "does not treat time with +00:00 offset as UTC" do
Time.new(2022, 1, 1, 0, 0, 0, "+00:00").utc?.should == false
Time.now.localtime("+00:00").utc?.should == false
Time.at(Time.now, in: "+00:00").utc?.should == false
end

it "does not treat time with 0 offset as UTC" do
Time.new(2022, 1, 1, 0, 0, 0, 0).utc?.should == false
Time.now.localtime(0).utc?.should == false
Time.at(Time.now, in: 0).utc?.should == false
end
end

Expand Down
Loading