# HG changeset patch # User Jaroslav Tulach # Date 1463716964 -7200 # Node ID 4b7ef2a05eb73fc3a85ac5c56b7f8744cea9400c # Parent 9d46ae9d4a2ed3ecd6eba48174b0f44812c22a07 Trivial implementation of TimeZone.getDefault() - doesn't count with daylightsavings diff -r 9d46ae9d4a2e -r 4b7ef2a05eb7 rt/emul/brwsrtest/src/test/java/org/apidesign/bck2brwsr/brwsrtest/TimeZoneTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/brwsrtest/src/test/java/org/apidesign/bck2brwsr/brwsrtest/TimeZoneTest.java Fri May 20 06:02:44 2016 +0200 @@ -0,0 +1,55 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.brwsrtest; + +import java.util.TimeZone; +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** + * + * @author Jaroslav Tulach + */ +public class TimeZoneTest { + boolean started; + int miss; + int exec; + + public TimeZoneTest() { + } + + @Compare + public int defaultTimeZoneRawOffset() throws Exception { + TimeZone zone = TimeZone.getDefault(); + assert zone != null : "TimeZone.getDefault shouldn't be null"; + int offset = zone.getRawOffset(); + if (offset > 0) { + return 1; + } else if (offset < 0) { + return -1; + } else { + return 0; + } + } + + @Factory public static Object[] create() { + return VMTest.create(TimeZoneTest.class); + } + +} diff -r 9d46ae9d4a2e -r 4b7ef2a05eb7 rt/emul/compact/src/main/java/java/util/TimeZone.java --- a/rt/emul/compact/src/main/java/java/util/TimeZone.java Tue May 10 04:52:05 2016 +0200 +++ b/rt/emul/compact/src/main/java/java/util/TimeZone.java Fri May 20 06:02:44 2016 +0200 @@ -40,9 +40,8 @@ import java.io.Serializable; import java.lang.ref.SoftReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.ConcurrentHashMap; +import org.apidesign.bck2brwsr.core.JavaScriptBody; /** * TimeZone represents a time zone offset, and also figures out daylight @@ -617,8 +616,35 @@ defaultZone = defaultTimeZone; if (defaultZone == null) { // Need to initialize the default time zone. - defaultZone = TimeZone.NO_TIMEZONE; - assert defaultZone != null; + defaultZone = new TimeZone() { + @Override + public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) { + return getRawOffset(); + } + + @Override + public void setRawOffset(int offsetMillis) { + } + + @Override + public int getRawOffset() { + int minutesOff = dateTimezoneOffset(); + return -60 * 1000 * minutesOff; + } + + @JavaScriptBody(args = { }, body = "return new Date().getTimezoneOffset();") + private native int dateTimezoneOffset(); + + @Override + public boolean useDaylightTime() { + return false; + } + + @Override + public boolean inDaylightTime(Date date) { + return false; + } + }; } } // Don't clone here.