use of android.icu.math.BigDecimal in project j2objc by google.
the class UniversalTimeScale method toBigDecimal.
/**
* Convert a datetime from the universal time scale to a <code>BigDecimal</code> in the given time scale.
*
* @param universalTime The datetime in the universal time scale
* @param timeScale The time scale to convert to
*
* @return The datetime converted to the given time scale
*/
public static BigDecimal toBigDecimal(long universalTime, int timeScale) {
TimeScaleData data = getTimeScaleData(timeScale);
BigDecimal universal = new BigDecimal(universalTime);
BigDecimal units = new BigDecimal(data.units);
BigDecimal epochOffset = new BigDecimal(data.epochOffset);
return universal.divide(units, BigDecimal.ROUND_HALF_UP).subtract(epochOffset);
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class UniversalTimeScale method toBigDecimalTrunc.
/**
* Convert a time in the Universal Time Scale into another time
* scale. The division used to do the conversion rounds down.
*
* NOTE: This is an internal routine used by the tool that
* generates the to and from limits. Use it at your own risk.
*
* @param universalTime the time in the Universal Time scale
* @param timeScale the time scale to convert to
* @return the time in the given time scale
*
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public static BigDecimal toBigDecimalTrunc(BigDecimal universalTime, int timeScale) {
TimeScaleData data = getTimeScaleData(timeScale);
BigDecimal units = new BigDecimal(data.units);
BigDecimal epochOffset = new BigDecimal(data.epochOffset);
return universalTime.divide(units, BigDecimal.ROUND_DOWN).subtract(epochOffset);
}
use of android.icu.math.BigDecimal in project j2objc by google.
the class UniversalTimeScale method bigDecimalFrom.
/**
* Convert a <code>long</code> datetime from the given time scale to the universal time scale.
* All calculations are done using <code>BigDecimal</code> to guarantee that the value
* does not go out of range.
*
* @param otherTime The <code>long</code> datetime
* @param timeScale The time scale to convert from
*
* @return The datetime converted to the universal time scale
*/
public static BigDecimal bigDecimalFrom(long otherTime, int timeScale) {
TimeScaleData data = getTimeScaleData(timeScale);
BigDecimal other = new BigDecimal(otherTime);
BigDecimal units = new BigDecimal(data.units);
BigDecimal epochOffset = new BigDecimal(data.epochOffset);
return other.add(epochOffset).multiply(units);
}
Aggregations