Index: src/org/jruby/RubyTime.java =================================================================== --- src/org/jruby/RubyTime.java (revision 3106) +++ src/org/jruby/RubyTime.java (working copy) @@ -40,6 +40,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; +import java.util.Map; import java.util.TimeZone; import org.jruby.runtime.Block; @@ -58,6 +59,18 @@ private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("-", Locale.US); + public static TimeZone getLocalTimeZone(Ruby runtime) { + // TODO: cache the RubyString "TZ" so it doesn't need to be recreated for each call? + RubyString tzVar = runtime.newString("TZ"); + Map h = ((RubyHash)runtime.getObject().getConstant("ENV")).getValueMap(); + IRubyObject tz = (IRubyObject)h.get(tzVar); + if (tz == null || ! (tz instanceof RubyString)) { + return TimeZone.getDefault(); + } else { + return TimeZone.getTimeZone(tz.toString()); + } + } + public RubyTime(Ruby runtime, RubyClass rubyClass) { super(runtime, rubyClass); } @@ -121,8 +134,7 @@ public RubyTime localtime() { long dump = cal.getTimeInMillis(); - cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getDefault()); + cal = Calendar.getInstance(getLocalTimeZone(getRuntime())); cal.setTimeInMillis(dump); return this; } @@ -139,7 +151,7 @@ public RubyTime getlocal() { Calendar newCal = (Calendar)cal.clone(); - newCal.setTimeZone(TimeZone.getDefault()); + newCal.setTimeZone(getLocalTimeZone(getRuntime())); return newTime(getRuntime(), newCal); } Index: src/org/jruby/runtime/builtin/meta/TimeMetaClass.java =================================================================== --- src/org/jruby/runtime/builtin/meta/TimeMetaClass.java (revision 3106) +++ src/org/jruby/runtime/builtin/meta/TimeMetaClass.java (working copy) @@ -300,8 +300,12 @@ if (year < 100) year += 2000; - Calendar cal = gmt ? Calendar.getInstance(TimeZone.getTimeZone(RubyTime.UTC)) : - Calendar.getInstance(); + Calendar cal; + if (gmt) { + cal = Calendar.getInstance(TimeZone.getTimeZone(RubyTime.UTC)); + } else { + cal = Calendar.getInstance(RubyTime.getLocalTimeZone(getRuntime())); + } cal.set(year, month, int_args[0], int_args[1], int_args[2], int_args[3]); cal.set(Calendar.MILLISECOND, int_args[4] / 1000); if (cal.getTimeInMillis() / 1000 < -0x80000000) {