From 811ebbee0f92e5ffe1eccf534c1d2fad7aaeb52e Mon Sep 17 00:00:00 2001 From: Eric Mader Date: Wed, 27 Oct 2004 21:28:38 +0000 Subject: [PATCH] ICU-3927 remove utmscale_fromDouble(), utmscale_toDouble() X-SVN-Rev: 16646 --- icu4c/source/i18n/unicode/utmscale.h | 28 ------ icu4c/source/i18n/utmscale.c | 68 -------------- icu4c/source/test/cintltst/utmstest.c | 129 -------------------------- 3 files changed, 225 deletions(-) diff --git a/icu4c/source/i18n/unicode/utmscale.h b/icu4c/source/i18n/unicode/utmscale.h index a2f8c6d9c7d..2ea3802108e 100644 --- a/icu4c/source/i18n/unicode/utmscale.h +++ b/icu4c/source/i18n/unicode/utmscale.h @@ -426,20 +426,6 @@ U_DRAFT int64_t U_EXPORT2 /* Conversion to 'universal time scale' */ -/** - * 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 - * @param status The status code. Set to U_ILLEGAL_ARGUMENT_ERROR if the conversion is out of range. - * - * @return The datetime converted to the universal time scale - * - * @draft ICU 3.2 - */ -U_DRAFT int64_t U_EXPORT2 - utmscale_fromDouble(double otherTime, UDateTimeScale timeScale, UErrorCode *status); - /** * Convert a int64_t datetime from the given time scale to the universal time scale. * @@ -456,20 +442,6 @@ U_DRAFT int64_t U_EXPORT2 /* Conversion from 'universal time scale' */ -/** - * Convert a datetime from the universal time scale to a double in the given time scale. - * - * @param universal The datetime in the universal time scale - * @param timeScale The time scale to convert to - * @param status The status code. Set to U_ILLEGAL_ARGUMENT_ERROR if the conversion is out of range. - * - * @return The datetime converted to the given time scale - * - * @draft ICU 3.2 - */ -U_DRAFT double U_EXPORT2 - utmscale_toDouble(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status); - /** * Convert a datetime from the universal time scale to a int64_t in the given time scale. * diff --git a/icu4c/source/i18n/utmscale.c b/icu4c/source/i18n/utmscale.c index 1602f27eb0c..12ff579491d 100644 --- a/icu4c/source/i18n/utmscale.c +++ b/icu4c/source/i18n/utmscale.c @@ -112,38 +112,6 @@ utmscale_getTimeScaleValue(UDateTimeScale timeScale, UTimeScaleValue value, UErr } } -U_CAPI int64_t U_EXPORT2 -utmscale_fromDouble(double otherTime, UDateTimeScale timeScale, UErrorCode *status) -{ - /* - * NOTE: fromMin and fromMax are marked "volatile" because the - * with the gcc compiler, the code which compares otherTime to - * fromMin and fromMax seems to fail if data->fromMax is U_INT64_MAX. - */ - const InternalTimeScaleData *data; - volatile double fromMin, fromMax; - - if (status == NULL || U_FAILURE(*status)) { - return 0; - } - - if (timeScale < 0 || timeScale >= UDTS_MAX_SCALE) { - *status = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - data = &timeScaleTable[timeScale]; - fromMin = (double) data->fromMin; - fromMax = (double) data->fromMax; - - if (!(otherTime >= fromMin && otherTime <= fromMax)) { - *status = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - return ((int64_t)otherTime + data->epochOffset) * data->units; -} - U_CAPI int64_t U_EXPORT2 utmscale_fromInt64(int64_t otherTime, UDateTimeScale timeScale, UErrorCode *status) { @@ -168,42 +136,6 @@ utmscale_fromInt64(int64_t otherTime, UDateTimeScale timeScale, UErrorCode *stat return (otherTime + data->epochOffset) * data->units; } -U_CAPI double U_EXPORT2 -utmscale_toDouble(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status) -{ - const InternalTimeScaleData *data; - - if (status == NULL || U_FAILURE(*status)) { - return 0; - } - - if (timeScale < 0 || timeScale >= UDTS_MAX_SCALE) { - *status = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - data = &timeScaleTable[timeScale]; - - if (universalTime < data->toMin || universalTime > data->toMax) { - *status = U_ILLEGAL_ARGUMENT_ERROR; - return 0; - } - - if (universalTime < 0) { - if (universalTime < data->minRound) { - return (double) (universalTime + data->unitsRound) / data->units - data->epochOffsetP1; - } - - return (double) (universalTime - data->unitsRound) / data->units - data->epochOffset; - } - - if (universalTime > data->maxRound) { - return (double) (universalTime - data->unitsRound) / data->units - data->epochOffsetM1; - } - - return (double) (universalTime + data->unitsRound) / data->units - data->epochOffset; -} - U_CAPI int64_t U_EXPORT2 utmscale_toInt64(int64_t universalTime, UDateTimeScale timeScale, UErrorCode *status) { diff --git a/icu4c/source/test/cintltst/utmstest.c b/icu4c/source/test/cintltst/utmstest.c index 99ea4d3ee77..f68b5bdd461 100644 --- a/icu4c/source/test/cintltst/utmstest.c +++ b/icu4c/source/test/cintltst/utmstest.c @@ -142,16 +142,6 @@ static void epochOffsetTest(int64_t epochOffset, int64_t units, int32_t scale) } } -static double valueLessThan(double value) -{ - return value - 100000.0; -} - -static double valueGreaterThan(double value) -{ - return value + 100000.0; -} - static void TestEpochOffsets(void) { UErrorCode status = U_ZERO_ERROR; @@ -195,62 +185,6 @@ static void TestToLimits(void) } } -static void TestFromDouble(void) -{ - int32_t scale; - int64_t result; - UErrorCode status = U_ZERO_ERROR; - - result = utmscale_fromDouble(0, -1, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(0, -1, status) did not set status to U_ILLEGAL_ARGUMENT_ERROR.\n"); - } - - for (scale = 0; scale < UDTS_MAX_SCALE; scale += 1) { - double fromMin, fromMax; - - status = U_ZERO_ERROR; - fromMin = (double) utmscale_getTimeScaleValue(scale, UTSV_FROM_MIN_VALUE, &status); - fromMax = (double) utmscale_getTimeScaleValue(scale, UTSV_FROM_MAX_VALUE, &status); - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(0, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(0, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(fromMin, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(fromMin, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(valueLessThan(fromMin), scale, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(fromMin - 1, %d, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(fromMax, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(fromMax, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(valueGreaterThan(fromMax), scale, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(fromMax + 1, %d, &status) didn't generate U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - } - - status = U_ZERO_ERROR; - result = utmscale_fromDouble(0, UDTS_MAX_SCALE, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_fromDouble(0, UDTS_MAX_SCALE, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n"); - } -} - static void TestFromInt64(void) { int32_t scale; @@ -311,67 +245,6 @@ static void TestFromInt64(void) } } -static void TestToDouble(void) -{ - int32_t scale; - double result; - UErrorCode status = U_ZERO_ERROR; - - result = utmscale_toDouble(0, -1, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(0, -1, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n"); - } - - for (scale = 0; scale < UDTS_MAX_SCALE; scale += 1) { - int64_t toMin, toMax; - - status = U_ZERO_ERROR; - toMin = utmscale_getTimeScaleValue(scale, UTSV_TO_MIN_VALUE, &status); - toMax = utmscale_getTimeScaleValue(scale, UTSV_TO_MAX_VALUE, &status); - - status = U_ZERO_ERROR; - result = utmscale_toDouble(0, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(0, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - status = U_ZERO_ERROR; - result = utmscale_toDouble(toMin, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(toMin, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - if (toMin > U_INT64_MIN) { - status = U_ZERO_ERROR; - result = utmscale_toDouble(toMin - 1, scale, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(toMin - 1, %d, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - } - - - status = U_ZERO_ERROR; - result = utmscale_toDouble(toMax, scale, &status); - if (status == U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(toMax, %d, &status) generated U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - - if (toMax < U_INT64_MAX) { - status = U_ZERO_ERROR; - result = utmscale_toDouble(toMax + 1, scale, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(toMax + 1, %d, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n", scale); - } - } - } - - status = U_ZERO_ERROR; - result = utmscale_toDouble(0, UDTS_MAX_SCALE, &status); - if (status != U_ILLEGAL_ARGUMENT_ERROR) { - log_err("utmscale_toDouble(0, UDTS_MAX_SCALE, &status) did not generate U_ILLEGAL_ARGUMENT_ERROR.\n"); - } -} - static void TestToInt64(void) { int32_t scale; @@ -435,9 +308,7 @@ static void TestToInt64(void) static void TestAPI(void) { - TestFromDouble(); TestFromInt64(); - TestToDouble(); TestToInt64(); }