mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-3927 remove fromDouble(), toDouble()
X-SVN-Rev: 16643
This commit is contained in:
parent
0a3710fa7a
commit
fcdcc0a229
2 changed files with 0 additions and 201 deletions
|
@ -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;
|
||||
|
|
|
@ -519,23 +519,6 @@ public final class UniversalTimeScale
|
|||
new TimeScaleData(days, 599266944000000000L, -9223372036854775808L, 9223372036854775807L, -11368795L, 9981603L) // DB2_TIME
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a <code>double</code> datetime from the given time scale to the universal time scale.
|
||||
*
|
||||
* @param otherTime The <code>double</code> 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 <code>long</code> 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 <code>double</code> 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 <code>long</code>. To get around this, we do
|
||||
* the rounding like this:
|
||||
*
|
||||
* <p><code>
|
||||
* (universalTime - units + units/2) / units + 1
|
||||
* </code>
|
||||
*
|
||||
* <p>
|
||||
* (i.e. we subtract units first to guarantee that we'll still be in range when we
|
||||
* add <code>units/2</code>. We then need to add one to the quotent to make up for the extra subtraction.
|
||||
* This simplifies to:
|
||||
*
|
||||
* <p><code>
|
||||
* (universalTime - units/2) / units - 1
|
||||
* </code>
|
||||
*
|
||||
* <p>
|
||||
* For negative values to round away from zero, we need to flip the signs:
|
||||
*
|
||||
* <p><code>
|
||||
* (universalTime + units/2) / units + 1
|
||||
* </code>
|
||||
*
|
||||
* <p>
|
||||
* Since we also need to subtract the epochOffset, we fold the <code>+/- 1</code>
|
||||
* into the offset value. (i.e. <code>epochOffsetP1</code>, <code>epochOffsetM1</code>.)
|
||||
*
|
||||
* @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 <code>BigDecimal</code> to a
|
||||
* <code>long</code> 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.
|
||||
|
|
Loading…
Add table
Reference in a new issue