From fcdcc0a229a9d8fd20e0c4e47e83c52741c79ce8 Mon Sep 17 00:00:00 2001 From: Eric Mader Date: Wed, 27 Oct 2004 21:10:08 +0000 Subject: [PATCH] ICU-3927 remove fromDouble(), toDouble() X-SVN-Rev: 16643 --- .../dev/test/timescale/TimeScaleAPITest.java | 114 ------------------ .../com/ibm/icu/util/UniversalTimeScale.java | 87 ------------- 2 files changed, 201 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/timescale/TimeScaleAPITest.java b/icu4j/src/com/ibm/icu/dev/test/timescale/TimeScaleAPITest.java index 1b10ac56796..7e96ef940d7 100644 --- a/icu4j/src/com/ibm/icu/dev/test/timescale/TimeScaleAPITest.java +++ b/icu4j/src/com/ibm/icu/dev/test/timescale/TimeScaleAPITest.java @@ -104,64 +104,6 @@ public class TimeScaleAPITest extends TestFmwk } } - public void TestFromDouble() - { - long result; - - try { - result = UniversalTimeScale.from(0.0, -1); - errln("from(0.0, -1) did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - - for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) { - double fromMin = (double) UniversalTimeScale.getTimeScaleValue(scale, UniversalTimeScale.FROM_MIN_VALUE); - double fromMax = (double) UniversalTimeScale.getTimeScaleValue(scale, UniversalTimeScale.FROM_MAX_VALUE); - - try { - result = UniversalTimeScale.from(0.0, scale); - } catch (IllegalArgumentException iae) { - errln("from(0.0, " + scale + ") threw IllegalArgumentException."); - } - - try { - result = UniversalTimeScale.from(fromMin, scale); - } catch (IllegalArgumentException iae) { - errln("from(fromMin, " + scale + ") threw IllegalArgumentException."); - } - - // Only do this test if we can exactly represent fromMin - 1 - if (fromMin - 1 > fromMin) { - try { - result = UniversalTimeScale.from(fromMin - 1, scale); - errln("from(fromMin - 1, " + scale + ") did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - } - - try { - result = UniversalTimeScale.from(fromMax, scale); - } catch (IllegalArgumentException iae) { - errln("from(fromMax, " + scale + ") threw IllegalArgumentException."); - } - - // Only do this test if we can exactly represent fromMax + 1 - if (fromMax < fromMax + 1) { - try { - result = UniversalTimeScale.from(fromMax + 1, scale); - errln("from(fromMax + 1, " + scale + ") did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - } - } - - try { - result = UniversalTimeScale.from(0.0, UniversalTimeScale.MAX_SCALE); - errln("from(0.0, MAX_SCALE) did not throw IllegalArgumetException."); - } catch (IllegalArgumentException iae) { - } - } - public void TestFromLong() { long result; @@ -306,62 +248,6 @@ public class TimeScaleAPITest extends TestFmwk } } - public void TestToDouble() - { - double result; - - try { - result = UniversalTimeScale.toDouble(0L, -1); - errln("toDouble(0L, -1) did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - - for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) { - long toMin = UniversalTimeScale.getTimeScaleValue(scale, UniversalTimeScale.TO_MIN_VALUE); - long toMax = UniversalTimeScale.getTimeScaleValue(scale, UniversalTimeScale.TO_MAX_VALUE); - - try { - result = UniversalTimeScale.toDouble(0L, scale); - } catch (IllegalArgumentException iae) { - errln("toDouble(0L, " + scale + ") threw IllegalArgumentException."); - } - - try { - result = UniversalTimeScale.toDouble(toMin, scale); - } catch (IllegalArgumentException iae) { - errln("toDouble(toMin, " + scale + ") threw IllegalArgumentException."); - } - - if (toMin > Long.MIN_VALUE) { - try { - result = UniversalTimeScale.toDouble(toMin - 1, scale); - errln("toDouble(toMin - 1, " + scale + ") did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - } - - try { - result = UniversalTimeScale.toDouble(toMax, scale); - } catch (IllegalArgumentException iae) { - errln("toDouble(toMax, " + scale + ") threw IllegalArgumentException."); - } - - if (toMax < Long.MAX_VALUE) { - try { - result = UniversalTimeScale.toDouble(toMax + 1, scale); - errln("toDouble(toMax + 1, " + scale + ") did not throw IllegalArgumentException."); - } catch (IllegalArgumentException iae) { - } - } - } - - try { - result = UniversalTimeScale.toDouble(0L, UniversalTimeScale.MAX_SCALE); - errln("toDouble(0L, MAX_SCALE) did not throw IllegalArgumetException."); - } catch (IllegalArgumentException iae) { - } - } - public void TestToLong() { long result; diff --git a/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java b/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java index 319192506db..8d9ad41102c 100644 --- a/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java +++ b/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java @@ -519,23 +519,6 @@ public final class UniversalTimeScale new TimeScaleData(days, 599266944000000000L, -9223372036854775808L, 9223372036854775807L, -11368795L, 9981603L) // DB2_TIME }; - /** - * Convert a double datetime from the given time scale to the universal time scale. - * - * @param otherTime The double datetime - * @param timeScale The time scale to convert from - * - * @return The datetime converted to the universal time scale - * - * @draft ICU 3.2 - */ - public static long from(double otherTime, int timeScale) - { - TimeScaleData data = fromRangeCheck(otherTime, timeScale); - - return ((long)otherTime + data.epochOffset) * data.units; - } - /** * Convert a long datetime from the given time scale to the universal time scale. * @@ -619,65 +602,6 @@ public final class UniversalTimeScale return otherTime.add(epochOffset).multiply(units); } - /** - * Convert a datetime from the universal time scale to a double in the given - * time scale. - * - * Since this calculation requires a divide, we must round. The straight forward - * way to round by adding half of the divisor will push the sum out of range for values - * within half the divisor of the limits of the precision of a long. To get around this, we do - * the rounding like this: - * - *

- * (universalTime - units + units/2) / units + 1 - * - * - *

- * (i.e. we subtract units first to guarantee that we'll still be in range when we - * add units/2. We then need to add one to the quotent to make up for the extra subtraction. - * This simplifies to: - * - *

- * (universalTime - units/2) / units - 1 - * - * - *

- * For negative values to round away from zero, we need to flip the signs: - * - *

- * (universalTime + units/2) / units + 1 - * - * - *

- * Since we also need to subtract the epochOffset, we fold the +/- 1 - * into the offset value. (i.e. epochOffsetP1, epochOffsetM1.) - * - * @param universal The datetime in the universal time scale - * @param timeScale The time scale to convert to - * - * @return The datetime converted to the given time scale - * - * @draft ICU 3.2 - */ - public static double toDouble(long universalTime, int timeScale) - { - TimeScaleData data = toRangeCheck(universalTime, timeScale); - - if (universalTime < 0) { - if (universalTime < data.minRound) { - return (universalTime + data.unitsRound) / data.units - data.epochOffsetP1; - } - - return (universalTime - data.unitsRound) / data.units - data.epochOffset; - } - - if (universalTime > data.maxRound) { - return (universalTime - data.unitsRound) / data.units - data.epochOffsetM1; - } - - return (universalTime + data.unitsRound) / data.units - data.epochOffset; - } - /** * Convert a datetime from the universal time scale stored as a BigDecimal to a * long in the given time scale. @@ -871,17 +795,6 @@ public final class UniversalTimeScale throw new IllegalArgumentException("otherTime out of range:" + otherTime); } - private static TimeScaleData fromRangeCheck(double otherTime, int scale) - { - TimeScaleData data = getTimeScaleData(scale); - - if (otherTime >= data.fromMin && otherTime <= data.fromMax) { - return data; - } - - throw new IllegalArgumentException("otherTime out of range:" + otherTime); - } - /** * Convert a time in the Universal Time Scale into another time * scale. The division used to do the conversion rounds down.