Skip to content

Commit

Permalink
Zone handling tweaks
Browse files Browse the repository at this point in the history
* Handle a null DateTimeZone as we did before, by propagating the
  null. This is used to indicate an invalid zone in our Ruby Time
  logic.
* Provide a map of zone aliases to pick up the old three-letter
  zones. This helps but is not sufficient to handle all
  three-letter formats tested by specs and tests (e.g. "PDT").
* For fixed-offset zones, use the offset rather than the ID. This
  causes those zones to lose their ID, so "AST-3:00:00" becomes
  an unnamed ZoneOffset of "3:00:00". This leads to other failures
  when the ID and offset are both expected to propagate into Time.
  • Loading branch information
headius committed Nov 3, 2022
1 parent a7b197b commit c08c89b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static ZoneId getZoneIdFromTZString(Ruby runtime, String zone) {
ZoneId cachedZone = runtime.getZoneIdCache().get(zone);
if (cachedZone != null) return cachedZone;

ZoneId dtz = JodaConverters.jodaToJavaTimeZone(parseTZString(runtime, zone));
ZoneId dtz = JodaConverters.jodaToJavaTimeZone(getTimeZoneFromTZString(runtime, zone));
runtime.getZoneIdCache().put(zone, dtz);
return dtz;
}
Expand Down Expand Up @@ -359,7 +359,11 @@ public static ZoneId getZoneIdFromUtcOffset(ThreadContext context, IRubyObject a
ZoneId cachedZone = runtime.getZoneIdCache().get(strOffset);
if (cachedZone != null) return cachedZone;

ZoneId zone = JodaConverters.jodaToJavaTimeZone(getTimeZoneFromUtcOffset(context, arg));
DateTimeZone dtz = getTimeZoneFromUtcOffset(context, arg);

if (dtz == null) return null;

ZoneId zone = JodaConverters.jodaToJavaTimeZone(dtz);

runtime.getZoneIdCache().put(strOffset, zone);

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/util/time/JodaConverters.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.jruby.util.time;

import org.joda.time.tz.FixedDateTimeZone;

import java.time.ZoneId;

/**
* The JodaConverters class contains static methods for org.joda.time.* and java.time.* conversion.
*
Expand Down Expand Up @@ -194,7 +198,9 @@ public static org.joda.time.Instant javaToJodaInstant( java.time.Instant instant
* @return Java 8 ZoneId
*/
public static java.time.ZoneId jodaToJavaTimeZone( org.joda.time.DateTimeZone timeZone ) {
return java.time.ZoneId.of( timeZone.getID() );
return timeZone.isFixed() ?
java.time.ZoneOffset.ofTotalSeconds(timeZone.toTimeZone().getRawOffset() / 1000) :
java.time.ZoneId.of( timeZone.getID(), ZoneId.SHORT_IDS );
}

/**
Expand Down

0 comments on commit c08c89b

Please sign in to comment.