# HG changeset patch # User Jaroslav Tulach # Date 1380880916 -7200 # Node ID 41046f76a76ad0338bfed93d06148449597d253e # Parent 8cc04f85a6838e22375437a20ab7909e54557346 Somehow implementing the calendar classes so they compile diff -r 8cc04f85a683 -r 41046f76a76a rt/emul/compact/src/main/java/java/util/Calendar.java --- a/rt/emul/compact/src/main/java/java/util/Calendar.java Fri Oct 04 11:07:00 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/Calendar.java Fri Oct 04 12:01:56 2013 +0200 @@ -43,19 +43,13 @@ import java.io.ObjectOutputStream; import java.io.OptionalDataException; import java.io.Serializable; -import java.security.AccessControlContext; import java.security.AccessController; -import java.security.PermissionCollection; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.security.ProtectionDomain; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import sun.util.BuddhistCalendar; -import sun.util.calendar.ZoneInfo; -import sun.util.resources.LocaleData; /** * The Calendar class is an abstract class that provides methods @@ -1025,18 +1019,18 @@ // returns a BuddhistCalendar instance. if ("th".equals(aLocale.getLanguage()) && ("TH".equals(aLocale.getCountry()))) { - cal = new BuddhistCalendar(zone, aLocale); +// cal = new BuddhistCalendar(zone, aLocale); } else { - cal = new GregorianCalendar(zone, aLocale); +// cal = new GregorianCalendar(zone, aLocale); } } else if (caltype.equals("japanese")) { - cal = new JapaneseImperialCalendar(zone, aLocale); +// cal = new JapaneseImperialCalendar(zone, aLocale); } else if (caltype.equals("buddhist")) { - cal = new BuddhistCalendar(zone, aLocale); +// cal = new BuddhistCalendar(zone, aLocale); } else { // Unsupported calendar type. // Use Gregorian calendar as a fallback. - cal = new GregorianCalendar(zone, aLocale); +// cal = new GregorianCalendar(zone, aLocale); } return cal; @@ -1130,10 +1124,10 @@ public void setTimeInMillis(long millis) { // If we don't need to recalculate the calendar field values, // do nothing. - if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet - && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) { - return; - } +// if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet +// && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) { +// return; +// } time = millis; isTimeSet = true; areFieldsSet = false; @@ -2587,10 +2581,10 @@ /* try to get the Locale data from the cache */ int[] data = cachedLocaleData.get(desiredLocale); if (data == null) { /* cache miss */ - ResourceBundle bundle = LocaleData.getCalendarData(desiredLocale); +// ResourceBundle bundle = LocaleData.getCalendarData(desiredLocale); data = new int[2]; - data[0] = Integer.parseInt(bundle.getString("firstDayOfWeek")); - data[1] = Integer.parseInt(bundle.getString("minimalDaysInFirstWeek")); +// data[0] = Integer.parseInt(bundle.getString("firstDayOfWeek")); +// data[1] = Integer.parseInt(bundle.getString("minimalDaysInFirstWeek")); cachedLocaleData.putIfAbsent(desiredLocale, data); } firstDayOfWeek = data[0]; @@ -2721,14 +2715,14 @@ // SimpleTimeZone equivalent (as a single DST schedule) for // backward compatibility. TimeZone savedZone = null; - if (zone instanceof ZoneInfo) { - SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance(); - if (stz == null) { - stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID()); - } - savedZone = zone; - zone = stz; - } +// if (zone instanceof ZoneInfo) { +// SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance(); +// if (stz == null) { +// stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID()); +// } +// savedZone = zone; +// zone = stz; +// } // Write out the 1.1 FCS object. stream.defaultWriteObject(); @@ -2742,18 +2736,6 @@ } } - private static class CalendarAccessControlContext { - private static final AccessControlContext INSTANCE; - static { - RuntimePermission perm = new RuntimePermission("accessClassInPackage.sun.util.calendar"); - PermissionCollection perms = perm.newPermissionCollection(); - perms.add(perm); - INSTANCE = new AccessControlContext(new ProtectionDomain[] { - new ProtectionDomain(null, perms) - }); - } - } - /** * Reconstitutes this object from a stream (i.e., deserialize it). */ @@ -2783,28 +2765,28 @@ serialVersionOnStream = currentSerialVersion; // If there's a ZoneInfo object, use it for zone. - ZoneInfo zi = null; - try { - zi = AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public ZoneInfo run() throws Exception { - return (ZoneInfo) input.readObject(); - } - }, - CalendarAccessControlContext.INSTANCE); - } catch (PrivilegedActionException pae) { - Exception e = pae.getException(); - if (!(e instanceof OptionalDataException)) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } else if (e instanceof IOException) { - throw (IOException) e; - } else if (e instanceof ClassNotFoundException) { - throw (ClassNotFoundException) e; - } - throw new RuntimeException(e); - } - } + TimeZone zi = null; +// try { +// zi = AccessController.doPrivileged( +// new PrivilegedExceptionAction() { +// public ZoneInfo run() throws Exception { +// return (ZoneInfo) input.readObject(); +// } +// }, +// CalendarAccessControlContext.INSTANCE); +// } catch (PrivilegedActionException pae) { +// Exception e = pae.getException(); +// if (!(e instanceof OptionalDataException)) { +// if (e instanceof RuntimeException) { +// throw (RuntimeException) e; +// } else if (e instanceof IOException) { +// throw (IOException) e; +// } else if (e instanceof ClassNotFoundException) { +// throw (ClassNotFoundException) e; +// } +// throw new RuntimeException(e); +// } +// } if (zi != null) { zone = zi; } diff -r 8cc04f85a683 -r 41046f76a76a rt/emul/compact/src/main/java/java/util/Currency.java --- a/rt/emul/compact/src/main/java/java/util/Currency.java Fri Oct 04 11:07:00 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/Currency.java Fri Oct 04 12:01:56 2013 +0200 @@ -35,14 +35,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.logging.Level; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.util.spi.CurrencyNameProvider; -import java.util.spi.LocaleServiceProvider; -import sun.util.LocaleServiceProviderPool; -import sun.util.logging.PlatformLogger; -import sun.util.resources.LocaleData; -import sun.util.resources.OpenListResourceBundle; +import java.util.logging.Logger; /** @@ -227,27 +220,27 @@ } // look for the properties file for overrides - try { +// try { File propFile = new File(homeDir + File.separator + "lib" + File.separator + "currency.properties"); - if (propFile.exists()) { - Properties props = new Properties(); - try (FileReader fr = new FileReader(propFile)) { - props.load(fr); - } - Set keys = props.stringPropertyNames(); - Pattern propertiesPattern = - Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])"); - for (String key : keys) { - replaceCurrencyData(propertiesPattern, - key.toUpperCase(Locale.ROOT), - props.getProperty(key).toUpperCase(Locale.ROOT)); - } - } - } catch (IOException e) { - info("currency.properties is ignored because of an IOException", e); - } +// if (propFile.exists()) { +// Properties props = new Properties(); +// try (FileReader fr = new FileReader(propFile)) { +// props.load(fr); +// } +// Set keys = props.stringPropertyNames(); +// Pattern propertiesPattern = +// Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])"); +// for (String key : keys) { +// replaceCurrencyData(propertiesPattern, +// key.toUpperCase(Locale.ROOT), +// props.getProperty(key).toUpperCase(Locale.ROOT)); +// } +// } +// } catch (IOException e) { +// info("currency.properties is ignored because of an IOException", e); +// } return null; } }); @@ -472,6 +465,7 @@ try { // Check whether a provider can provide an implementation that's closer // to the requested locale than what the Java runtime itself can provide. + /* LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CurrencyNameProvider.class); @@ -489,8 +483,8 @@ return symbol; } } - - ResourceBundle bundle = LocaleData.getCurrencyNames(locale); + */ + ResourceBundle bundle = null; //LocaleData.getCurrencyNames(locale); return bundle.getString(currencyCode); } catch (MissingResourceException e) { // use currency code as symbol of last resort @@ -545,31 +539,31 @@ * @since 1.7 */ public String getDisplayName(Locale locale) { - try { - OpenListResourceBundle bundle = LocaleData.getCurrencyNames(locale); - String result = null; - String bundleKey = currencyCode.toLowerCase(Locale.ROOT); - - // Check whether a provider can provide an implementation that's closer - // to the requested locale than what the Java runtime itself can provide. - LocaleServiceProviderPool pool = - LocaleServiceProviderPool.getPool(CurrencyNameProvider.class); - if (pool.hasProviders()) { - result = pool.getLocalizedObject( - CurrencyNameGetter.INSTANCE, - locale, bundleKey, bundle, currencyCode, DISPLAYNAME); - } - - if (result == null) { - result = bundle.getString(bundleKey); - } - - if (result != null) { - return result; - } - } catch (MissingResourceException e) { - // fall through - } +// try { +// OpenListResourceBundle bundle = LocaleData.getCurrencyNames(locale); +// String result = null; +// String bundleKey = currencyCode.toLowerCase(Locale.ROOT); +// +// // Check whether a provider can provide an implementation that's closer +// // to the requested locale than what the Java runtime itself can provide. +// LocaleServiceProviderPool pool = +// LocaleServiceProviderPool.getPool(CurrencyNameProvider.class); +// if (pool.hasProviders()) { +// result = pool.getLocalizedObject( +// CurrencyNameGetter.INSTANCE, +// locale, bundleKey, bundle, currencyCode, DISPLAYNAME); +// } +// +// if (result == null) { +// result = bundle.getString(bundleKey); +// } +// +// if (result != null) { +// return result; +// } +// } catch (MissingResourceException e) { +// // fall through +// } // use currency code as symbol of last resort return currencyCode; @@ -616,7 +610,6 @@ /** * Obtains a localized currency names from a CurrencyNameProvider * implementation. - */ private static class CurrencyNameGetter implements LocaleServiceProviderPool.LocalizedObjectGetter { @@ -641,6 +634,7 @@ return null; } } + */ private static int[] readIntArray(DataInputStream dis, int count) throws IOException { int[] ret = new int[count]; @@ -679,7 +673,6 @@ * and "one-digit (0,1,2, or 3) default fraction digit". * For example, "JPZ,392,0". * @throws - */ private static void replaceCurrencyData(Pattern pattern, String ctry, String curdata) { if (ctry.length() != 2) { @@ -727,12 +720,13 @@ } setMainTableEntry(ctry.charAt(0), ctry.charAt(1), entry); } + */ private static void info(String message, Throwable t) { - PlatformLogger logger = PlatformLogger.getLogger("java.util.Currency"); - if (logger.isLoggable(PlatformLogger.INFO)) { + Logger logger = Logger.getLogger("java.util.Currency"); + if (logger.isLoggable(Level.INFO)) { if (t != null) { - logger.info(message, t); + logger.log(Level.INFO, message, t); } else { logger.info(message); } diff -r 8cc04f85a683 -r 41046f76a76a rt/emul/compact/src/main/java/java/util/Date.java --- a/rt/emul/compact/src/main/java/java/util/Date.java Fri Oct 04 11:07:00 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/Date.java Fri Oct 04 12:01:56 2013 +0200 @@ -29,14 +29,6 @@ import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; -import java.lang.ref.SoftReference; -import sun.util.calendar.BaseCalendar; -import sun.util.calendar.CalendarDate; -import sun.util.calendar.CalendarSystem; -import sun.util.calendar.CalendarUtils; -import sun.util.calendar.Era; -import sun.util.calendar.Gregorian; -import sun.util.calendar.ZoneInfo; /** * The class Date represents a specific instant @@ -129,8 +121,8 @@ public class Date implements java.io.Serializable, Cloneable, Comparable { - private static final BaseCalendar gcal = - CalendarSystem.getGregorianCalendar(); + private static final BaseCalendar gcal = new BaseCalendar(); + private static BaseCalendar jcal; private transient long fastTime; @@ -141,7 +133,7 @@ * synch. Otherwise, fastTime is ignored, and cdate indicates the * time. */ - private transient BaseCalendar.Date cdate; + private transient BaseCalendar.Datum cdate; // Initialized just before the value is used. See parse(). private static int defaultCenturyStart; @@ -245,11 +237,11 @@ y += month / 12; month %= 12; } else if (month < 0) { - y += CalendarUtils.floorDivide(month, 12); - month = CalendarUtils.mod(month, 12); + y += month / 12; + month = month % 12; } BaseCalendar cal = getCalendarSystem(y); - cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef()); + cdate = (BaseCalendar.Datum) cal.newCalendarDate(TimeZone.getDefaultRef()); cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0); getTimeImpl(); cdate = null; @@ -280,7 +272,7 @@ try { d = (Date)super.clone(); if (cdate != null) { - d.cdate = (BaseCalendar.Date) cdate.clone(); + d.cdate = (BaseCalendar.Datum) cdate.clone(); } } catch (CloneNotSupportedException e) {} // Won't happen return d; @@ -320,12 +312,12 @@ y += month / 12; month %= 12; } else if (month < 0) { - y += CalendarUtils.floorDivide(month, 12); - month = CalendarUtils.mod(month, 12); + y += month / 12; + month = month % 12; } int m = month + 1; BaseCalendar cal = getCalendarSystem(y); - BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null); + BaseCalendar.Datum udate = (BaseCalendar.Datum) cal.newCalendarDate(null); udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0); // Use a Date instance to perform normalization. Its fastTime @@ -601,12 +593,12 @@ hour = 0; BaseCalendar cal = getCalendarSystem(year); if (tzoffset == -1) { // no time zone specified, have to use local - BaseCalendar.Date ldate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef()); + BaseCalendar.Datum ldate = (BaseCalendar.Datum) cal.newCalendarDate(TimeZone.getDefaultRef()); ldate.setDate(year, mon + 1, mday); ldate.setTimeOfDay(hour, min, sec, 0); return cal.getTime(ldate); } - BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null); // no time zone + BaseCalendar.Datum udate = (BaseCalendar.Datum) cal.newCalendarDate(null); // no time zone udate.setDate(year, mon + 1, mday); udate.setTimeOfDay(hour, min, sec, 0); return cal.getTime(udate) + tzoffset * (60 * 1000); @@ -706,10 +698,10 @@ y = month / 12; month %= 12; } else if (month < 0) { - y = CalendarUtils.floorDivide(month, 12); - month = CalendarUtils.mod(month, 12); + y = month / 12; + month = month % 12; } - BaseCalendar.Date d = getCalendarDate(); + BaseCalendar.Datum d = getCalendarDate(); if (y != 0) { d.setNormalizedYear(d.getNormalizedYear() + y); } @@ -770,7 +762,7 @@ */ @Deprecated public int getDay() { - return normalize().getDayOfWeek() - gcal.SUNDAY; + return normalize().getDayOfWeek() - 7;//gcal.SUNDAY; } /** @@ -956,7 +948,7 @@ if (date.cdate == null || date.cdate.isNormalized()) { return date.fastTime; } - BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone(); + BaseCalendar.Datum d = (BaseCalendar.Datum) date.cdate.clone(); return gcal.getTime(d); } @@ -1024,25 +1016,25 @@ */ public String toString() { // "EEE MMM dd HH:mm:ss zzz yyyy"; - BaseCalendar.Date date = normalize(); + BaseCalendar.Datum date = normalize(); StringBuilder sb = new StringBuilder(28); int index = date.getDayOfWeek(); - if (index == gcal.SUNDAY) { + if (index == 7) { index = 8; } convertToAbbr(sb, wtb[index]).append(' '); // EEE convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' '); // MMM - CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd - - CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH - CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm - CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss - TimeZone zi = date.getZone(); - if (zi != null) { - sb.append(zi.getDisplayName(date.isDaylightTime(), zi.SHORT, Locale.US)); // zzz - } else { - sb.append("GMT"); - } +// CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd +// +// CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH +// CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm +// CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss +// TimeZone zi = date.getZone(); +// if (zi != null) { +// sb.append(zi.getDisplayName(date.isDaylightTime(), zi.SHORT, Locale.US)); // zzz +// } else { +// sb.append("GMT"); +// } sb.append(' ').append(date.getYear()); // yyyy return sb.toString(); } @@ -1116,15 +1108,15 @@ // d MMM yyyy HH:mm:ss 'GMT' long t = getTime(); BaseCalendar cal = getCalendarSystem(t); - BaseCalendar.Date date = - (BaseCalendar.Date) cal.getCalendarDate(getTime(), (TimeZone)null); StringBuilder sb = new StringBuilder(32); - CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' '); // d - convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' '); // MMM - sb.append(date.getYear()).append(' '); // yyyy - CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH - CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm - CalendarUtils.sprintf0d(sb, date.getSeconds(), 2); // ss +// BaseCalendar.Datum date = +// (BaseCalendar.Datum) cal.getCalendarDate(getTime(), (TimeZone)null); +// CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' '); // d +// convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' '); // MMM +// sb.append(date.getYear()).append(' '); // yyyy +// CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH +// CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm +// CalendarUtils.sprintf0d(sb, date.getSeconds(), 2); // ss sb.append(" GMT"); // ' GMT' return sb.toString(); } @@ -1166,11 +1158,7 @@ int zoneOffset; if (cdate == null) { TimeZone tz = TimeZone.getDefaultRef(); - if (tz instanceof ZoneInfo) { - zoneOffset = ((ZoneInfo)tz).getOffsets(fastTime, null); - } else { - zoneOffset = tz.getOffset(fastTime); - } + zoneOffset = tz.getOffset(fastTime); } else { normalize(); zoneOffset = cdate.getZoneOffset(); @@ -1178,21 +1166,21 @@ return -zoneOffset/60000; // convert to minutes } - private final BaseCalendar.Date getCalendarDate() { + private final BaseCalendar.Datum getCalendarDate() { if (cdate == null) { - BaseCalendar cal = getCalendarSystem(fastTime); - cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime, - TimeZone.getDefaultRef()); +// BaseCalendar cal = getCalendarSystem(fastTime); +// cdate = (BaseCalendar.Datum) cal.getCalendarDate(fastTime, +// TimeZone.getDefaultRef()); } return cdate; } - private final BaseCalendar.Date normalize() { + private final BaseCalendar.Datum normalize() { if (cdate == null) { - BaseCalendar cal = getCalendarSystem(fastTime); - cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime, - TimeZone.getDefaultRef()); - return cdate; +// BaseCalendar cal = getCalendarSystem(fastTime); +// cdate = (BaseCalendar.Datum) cal.getCalendarDate(fastTime, +// TimeZone.getDefaultRef()); +// return cdate; } // Normalize cdate with the TimeZone in cdate first. This is @@ -1205,15 +1193,15 @@ // fields with the new TimeZone. TimeZone tz = TimeZone.getDefaultRef(); if (tz != cdate.getZone()) { - cdate.setZone(tz); - CalendarSystem cal = getCalendarSystem(cdate); - cal.getCalendarDate(fastTime, cdate); +// cdate.setZone(tz); +// CalendarSystem cal = getCalendarSystem(cdate); +// cal.getCalendarDate(fastTime, cdate); } return cdate; } // fastTime and the returned data are in sync upon return. - private final BaseCalendar.Date normalize(BaseCalendar.Date date) { + private final BaseCalendar.Datum normalize(BaseCalendar.Datum date) { int y = date.getNormalizedYear(); int m = date.getMonth(); int d = date.getDayOfMonth(); @@ -1231,23 +1219,23 @@ // ss and ms. Also, let GregorianCalendar handle the default // cutover year so that we don't need to worry about the // transition here. - if (y == 1582 || y > 280000000 || y < -280000000) { - if (tz == null) { - tz = TimeZone.getTimeZone("GMT"); - } - GregorianCalendar gc = new GregorianCalendar(tz); - gc.clear(); - gc.set(gc.MILLISECOND, ms); - gc.set(y, m-1, d, hh, mm, ss); - fastTime = gc.getTimeInMillis(); - BaseCalendar cal = getCalendarSystem(fastTime); - date = (BaseCalendar.Date) cal.getCalendarDate(fastTime, tz); - return date; - } +// if (y == 1582 || y > 280000000 || y < -280000000) { +// if (tz == null) { +// tz = TimeZone.getTimeZone("GMT"); +// } +// GregorianCalendar gc = new GregorianCalendar(tz); +// gc.clear(); +// gc.set(gc.MILLISECOND, ms); +// gc.set(y, m-1, d, hh, mm, ss); +// fastTime = gc.getTimeInMillis(); +// BaseCalendar cal = getCalendarSystem(fastTime); +// date = (BaseCalendar.Datum) cal.getCalendarDate(fastTime, tz); +// return date; +// } BaseCalendar cal = getCalendarSystem(y); if (cal != getCalendarSystem(date)) { - date = (BaseCalendar.Date) cal.newCalendarDate(tz); + date = (BaseCalendar.Datum) cal.newCalendarDate(tz); date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms); } // Perform the GregorianCalendar-style normalization. @@ -1257,7 +1245,7 @@ // system, we need to recalculate it using the other one. BaseCalendar ncal = getCalendarSystem(fastTime); if (ncal != cal) { - date = (BaseCalendar.Date) ncal.newCalendarDate(tz); + date = (BaseCalendar.Datum) ncal.newCalendarDate(tz); date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms); fastTime = ncal.getTime(date); } @@ -1282,15 +1270,15 @@ // Quickly check if the time stamp given by `utc' is the Epoch // or later. If it's before 1970, we convert the cutover to // local time to compare. - if (utc >= 0 - || utc >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER - - TimeZone.getDefaultRef().getOffset(utc)) { +// if (utc >= 0 +// || utc >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER +// - TimeZone.getDefaultRef().getOffset(utc)) { return gcal; - } - return getJulianCalendar(); +// } +// return getJulianCalendar(); } - private static final BaseCalendar getCalendarSystem(BaseCalendar.Date cdate) { + private static final BaseCalendar getCalendarSystem(BaseCalendar.Datum cdate) { if (jcal == null) { return gcal; } @@ -1302,7 +1290,7 @@ synchronized private static final BaseCalendar getJulianCalendar() { if (jcal == null) { - jcal = (BaseCalendar) CalendarSystem.forName("julian"); +// jcal = (BaseCalendar) CalendarSystem.forName("julian"); } return jcal; } @@ -1328,4 +1316,115 @@ { fastTime = s.readLong(); } + + static final class BaseCalendar { + Datum newCalendarDate(TimeZone t) { + return new Datum(); + } + + Datum getNthDayOfWeek(int a, int b, Datum c) { + return new Datum(); + } + + Datum getCalendarDate() { + return new Datum(); + } + + int getTime(Datum udate) { + return 0; + } + + int getMonthLength(Datum cdate) { + return 0; + } + + void getCalendarDate(long l, Datum cdate) { + } + + static class Datum implements Cloneable { + public Datum clone() { + return new Datum(); + } + + Datum setNormalizedDate(int y, int i, int date) { + return this; + } + + void setTimeOfDay(int hrs, int min, int sec, int i) { + } + + int getYear() { + return 0; + } + + void setDate(int year, int i, int mday) { + } + + void setNormalizedYear(int i) { + } + + int getMonth() { + return 0; + } + + int getNormalizedYear() { + return 0; + } + + void setMonth(int i) { + } + + int getDayOfMonth() { + return 0; + } + + void setDayOfMonth(int date) { + } + + int getDayOfWeek() { + return 0; + } + + int getHours() { + return 0; + } + + void setHours(int hours) { + } + + int getMinutes() { + return 0; + } + + void setMinutes(int minutes) { + } + + int getSeconds() { + return 0; + } + + void setSeconds(int seconds) { + } + + boolean isNormalized() { + return false; + } + + Object getEra() { + return this; + } + + int getMillis() { + return 0; + } + + TimeZone getZone() { + return TimeZone.NO_TIMEZONE; + } + + int getZoneOffset() { + return 0; + } + } + } } diff -r 8cc04f85a683 -r 41046f76a76a rt/emul/compact/src/main/java/java/util/SimpleTimeZone.java --- a/rt/emul/compact/src/main/java/java/util/SimpleTimeZone.java Fri Oct 04 11:07:00 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/SimpleTimeZone.java Fri Oct 04 12:01:56 2013 +0200 @@ -41,10 +41,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.IOException; -import sun.util.calendar.CalendarSystem; -import sun.util.calendar.CalendarUtils; -import sun.util.calendar.BaseCalendar; -import sun.util.calendar.Gregorian; +import java.util.Date.BaseCalendar; /** * SimpleTimeZone is a concrete subclass of TimeZone @@ -555,9 +552,10 @@ } } } - BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ? - gcal : (BaseCalendar) CalendarSystem.forName("julian"); - BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE); + BaseCalendar cal = gcal; +// date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ? +// gcal : (BaseCalendar) CalendarSystem.forName("julian"); + BaseCalendar.Datum cdate = (BaseCalendar.Datum) cal.newCalendarDate(TimeZone.NO_TIMEZONE); // Get the year in local time cal.getCalendarDate(date + rawOffset, cdate); int year = cdate.getNormalizedYear(); @@ -625,7 +623,7 @@ // y %= 28 also produces an equivalent year, but positive // year numbers would be convenient to use the UNIX cal // command. - y = (int) CalendarUtils.mod((long) y, 28); + y = (int) (long) y % 28; } // convert year to its 1-based month value @@ -633,7 +631,7 @@ // First, calculate time as a Gregorian date. BaseCalendar cal = gcal; - BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE); + BaseCalendar.Datum cdate = (BaseCalendar.Datum) cal.newCalendarDate(TimeZone.NO_TIMEZONE); cdate.setDate(y, m, day); long time = cal.getTime(cdate); // normalize cdate time += millis - rawOffset; // UTC time @@ -644,12 +642,12 @@ // normalized year numbering is ..., -2 (BCE 2), -1 (BCE 1), // 1, 2 ... which is different from the GregorianCalendar // style year numbering (..., -1, 0 (BCE 1), 1, 2, ...). - if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) { - cal = (BaseCalendar) CalendarSystem.forName("julian"); - cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE); - cdate.setNormalizedDate(y, m, day); - time = cal.getTime(cdate) + millis - rawOffset; - } +// if (time < GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER) { +// cal = (BaseCalendar) CalendarSystem.forName("julian"); +// cdate = (BaseCalendar.Datum) cal.newCalendarDate(TimeZone.NO_TIMEZONE); +// cdate.setNormalizedDate(y, m, day); +// time = cal.getTime(cdate) + millis - rawOffset; +// } if ((cdate.getNormalizedYear() != y) || (cdate.getMonth() != m) @@ -669,7 +667,7 @@ return getOffset(cal, cdate, y, time); } - private int getOffset(BaseCalendar cal, BaseCalendar.Date cdate, int year, long time) { + private int getOffset(BaseCalendar cal, BaseCalendar.Datum cdate, int year, long time) { synchronized (this) { if (cacheStart != 0) { if (time >= cacheStart && time < cacheEnd) { @@ -721,7 +719,7 @@ return offset; } - private long getStart(BaseCalendar cal, BaseCalendar.Date cdate, int year) { + private long getStart(BaseCalendar cal, BaseCalendar.Datum cdate, int year) { int time = startTime; if (startTimeMode != UTC_TIME) { time -= rawOffset; @@ -730,7 +728,7 @@ startDayOfWeek, time); } - private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) { + private long getEnd(BaseCalendar cal, BaseCalendar.Datum cdate, int year) { int time = endTime; if (endTimeMode != UTC_TIME) { time -= rawOffset; @@ -742,7 +740,7 @@ endDayOfWeek, time); } - private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate, + private long getTransition(BaseCalendar cal, BaseCalendar.Datum cdate, int mode, int year, int month, int dayOfMonth, int dayOfWeek, int timeOfDay) { cdate.setNormalizedYear(year); @@ -757,17 +755,17 @@ if (dayOfMonth < 0) { cdate.setDayOfMonth(cal.getMonthLength(cdate)); } - cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate); + cdate = (BaseCalendar.Datum) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate); break; case DOW_GE_DOM_MODE: cdate.setDayOfMonth(dayOfMonth); - cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate); + cdate = (BaseCalendar.Datum) cal.getNthDayOfWeek(1, dayOfWeek, cdate); break; case DOW_LE_DOM_MODE: cdate.setDayOfMonth(dayOfMonth); - cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate); + cdate = (BaseCalendar.Datum) cal.getNthDayOfWeek(-1, dayOfWeek, cdate); break; } return cal.getTime(cdate) + timeOfDay; @@ -1196,7 +1194,7 @@ */ private int dstSavings; - private static final Gregorian gcal = CalendarSystem.getGregorianCalendar(); + private static final BaseCalendar gcal = new BaseCalendar();//CalendarSystem.getGregorianCalendar(); /** * Cache values representing a single period of daylight saving @@ -1703,4 +1701,37 @@ serialVersionOnStream = currentSerialVersion; } + + static final class GregorianCalendar { + public static final int BC = 0; + + /** + * Value of the {@link #ERA} field indicating the period before the + * common era, the same value as {@link #BC}. + * + * @see #CE + */ + static final int BCE = 0; + + /** + * Value of the ERA field indicating the common era (Anno + * Domini), also known as CE. The sequence of years at the transition + * from BC to AD is ..., 2 BC, 1 BC, 1 AD, 2 + * AD,... + * + * @see #ERA + */ + public static final int AD = 1; + + // The default value of gregorianCutover. + static final long DEFAULT_GREGORIAN_CUTOVER = -12219292800000L; + /** + * Value of the {@link #ERA} field indicating + * the common era, the same value as {@link #AD}. + * + * @see #BCE + */ + static final int CE = 1; + + } } diff -r 8cc04f85a683 -r 41046f76a76a rt/emul/compact/src/main/java/java/util/TimeZone.java --- a/rt/emul/compact/src/main/java/java/util/TimeZone.java Fri Oct 04 11:07:00 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/TimeZone.java Fri Oct 04 12:01:56 2013 +0200 @@ -43,10 +43,6 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.ConcurrentHashMap; -import sun.security.action.GetPropertyAction; -import sun.util.TimeZoneNameUtility; -import sun.util.calendar.ZoneInfo; -import sun.util.calendar.ZoneInfoFile; /** * TimeZone represents a time zone offset, and also figures out daylight @@ -411,7 +407,7 @@ if (daylight) { offset += getDSTSavings(); } - return ZoneInfoFile.toCustomID(offset); + // return ZoneInfoFile.toCustomID(offset); } int index = daylight ? 3 : 1; @@ -440,7 +436,7 @@ if (names != null) { return names; } - names = TimeZoneNameUtility.retrieveDisplayNames(id, locale); + names = null; // TimeZoneNameUtility.retrieveDisplayNames(id, locale); if (names != null) { perLocale.put(locale, names); } @@ -448,7 +444,7 @@ } } - String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale); + String[] names = null; // TimeZoneNameUtility.retrieveDisplayNames(id, locale); if (names != null) { Map perLocale = new ConcurrentHashMap(); perLocale.put(locale, names); @@ -556,14 +552,15 @@ } private static TimeZone getTimeZone(String ID, boolean fallback) { - TimeZone tz = ZoneInfo.getTimeZone(ID); - if (tz == null) { - tz = parseCustomTimeZone(ID); - if (tz == null && fallback) { - tz = new ZoneInfo(GMT_ID, 0); - } - } - return tz; +// TimeZone tz = ZoneInfo.getTimeZone(ID); +// if (tz == null) { +// tz = parseCustomTimeZone(ID); +// if (tz == null && fallback) { +// tz = new ZoneInfo(GMT_ID, 0); +// } +// } +// return tz; + return TimeZone.NO_TIMEZONE; } /** @@ -576,7 +573,7 @@ * @see #getRawOffset() */ public static synchronized String[] getAvailableIDs(int rawOffset) { - return ZoneInfo.getAvailableIDs(rawOffset); + return new String[0];//ZoneInfo.getAvailableIDs(rawOffset); } /** @@ -584,7 +581,7 @@ * @return an array of IDs. */ public static synchronized String[] getAvailableIDs() { - return ZoneInfo.getAvailableIDs(); + return new String[0];//return ZoneInfo.getAvailableIDs(); } /** @@ -615,12 +612,12 @@ * method doesn't create a clone. */ static TimeZone getDefaultRef() { - TimeZone defaultZone = defaultZoneTL.get(); + TimeZone defaultZone = null;//defaultZoneTL.get(); if (defaultZone == null) { defaultZone = defaultTimeZone; if (defaultZone == null) { // Need to initialize the default time zone. - defaultZone = setDefaultZone(); + defaultZone = TimeZone.NO_TIMEZONE; assert defaultZone != null; } } @@ -628,68 +625,8 @@ return defaultZone; } - private static synchronized TimeZone setDefaultZone() { - TimeZone tz = null; - // get the time zone ID from the system properties - String zoneID = AccessController.doPrivileged( - new GetPropertyAction("user.timezone")); - - // if the time zone ID is not set (yet), perform the - // platform to Java time zone ID mapping. - if (zoneID == null || zoneID.equals("")) { - String country = AccessController.doPrivileged( - new GetPropertyAction("user.country")); - String javaHome = AccessController.doPrivileged( - new GetPropertyAction("java.home")); - try { - zoneID = getSystemTimeZoneID(javaHome, country); - if (zoneID == null) { - zoneID = GMT_ID; - } - } catch (NullPointerException e) { - zoneID = GMT_ID; - } - } - - // Get the time zone for zoneID. But not fall back to - // "GMT" here. - tz = getTimeZone(zoneID, false); - - if (tz == null) { - // If the given zone ID is unknown in Java, try to - // get the GMT-offset-based time zone ID, - // a.k.a. custom time zone ID (e.g., "GMT-08:00"). - String gmtOffsetID = getSystemGMTOffsetID(); - if (gmtOffsetID != null) { - zoneID = gmtOffsetID; - } - tz = getTimeZone(zoneID, true); - } - assert tz != null; - - final String id = zoneID; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - System.setProperty("user.timezone", id); - return null; - } - }); - - defaultTimeZone = tz; - return tz; - } - private static boolean hasPermission() { - boolean hasPermission = true; - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - try { - sm.checkPermission(new PropertyPermission - ("user.timezone", "write")); - } catch (SecurityException e) { - hasPermission = false; - } - } + boolean hasPermission = false; return hasPermission; } @@ -706,10 +643,10 @@ if (hasPermission()) { synchronized (TimeZone.class) { defaultTimeZone = zone; - defaultZoneTL.set(null); + // defaultZoneTL.set(null); } } else { - defaultZoneTL.set(zone); + //defaultZoneTL.set(zone); } } @@ -760,8 +697,6 @@ */ private String ID; private static volatile TimeZone defaultTimeZone; - private static final InheritableThreadLocal defaultZoneTL - = new InheritableThreadLocal(); static final String GMT_ID = "GMT"; private static final int GMT_ID_LENGTH = 3; @@ -775,90 +710,6 @@ * no daylight saving time, or null if the id cannot be parsed. */ private static final TimeZone parseCustomTimeZone(String id) { - int length; - - // Error if the length of id isn't long enough or id doesn't - // start with "GMT". - if ((length = id.length()) < (GMT_ID_LENGTH + 2) || - id.indexOf(GMT_ID) != 0) { - return null; - } - - ZoneInfo zi; - - // First, we try to find it in the cache with the given - // id. Even the id is not normalized, the returned ZoneInfo - // should have its normalized id. - zi = ZoneInfoFile.getZoneInfo(id); - if (zi != null) { - return zi; - } - - int index = GMT_ID_LENGTH; - boolean negative = false; - char c = id.charAt(index++); - if (c == '-') { - negative = true; - } else if (c != '+') { - return null; - } - - int hours = 0; - int num = 0; - int countDelim = 0; - int len = 0; - while (index < length) { - c = id.charAt(index++); - if (c == ':') { - if (countDelim > 0) { - return null; - } - if (len > 2) { - return null; - } - hours = num; - countDelim++; - num = 0; - len = 0; - continue; - } - if (c < '0' || c > '9') { - return null; - } - num = num * 10 + (c - '0'); - len++; - } - if (index != length) { - return null; - } - if (countDelim == 0) { - if (len <= 2) { - hours = num; - num = 0; - } else { - hours = num / 100; - num %= 100; - } - } else { - if (len != 2) { - return null; - } - } - if (hours > 23 || num > 59) { - return null; - } - int gmtOffset = (hours * 60 + num) * 60 * 1000; - - if (gmtOffset == 0) { - zi = ZoneInfoFile.getZoneInfo(GMT_ID); - if (negative) { - zi.setID("GMT-00:00"); - } else { - zi.setID("GMT+00:00"); - } - } else { - zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset); - } - return zi; + return null; } }