-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For BigInteger and BigDecimal conversions, ensuring that temporal cla…
…sses that handle nanos, the nanos are retained. For BigDecimal, the decimal portion of the number is decimal milliseconds - the whole portion of the BigDecimal is milliseconds "dot" fractional milliseconds (up to 6 decimal places = 1 billionth of a second, or a millionth of a microsecond). For BigInteger, the conversion is always in BigInteger nanoseconds, period. BigInteger has many of these conversions completed, but not all. After that, BigDecimal is next. There are a few more to add for Long, but when using Long it is always working with milliseconds only.
- Loading branch information
Showing
8 changed files
with
225 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
|
@@ -21,6 +24,8 @@ | |
* limitations under the License. | ||
*/ | ||
final class TimestampConversions { | ||
private static final BigInteger MILLION = BigInteger.valueOf(1_000_000); | ||
|
||
private TimestampConversions() {} | ||
|
||
static double toDouble(Object from, Converter converter) { | ||
|
@@ -42,4 +47,16 @@ static BigDecimal toBigDecimal(Object from, Converter converter) { | |
// Convert time to fractional milliseconds | ||
return BigDecimal.valueOf(epochMillis).add(BigDecimal.valueOf(nanoPart, 6)); // Dividing by 1_000_000 with scale 6 | ||
} | ||
|
||
static BigInteger toBigInteger(Object from, Converter converter) { | ||
Duration duration = toDuration(from, converter); | ||
return DurationConversions.toBigInteger(duration, converter); | ||
} | ||
|
||
static Duration toDuration(Object from, Converter converter) { | ||
Timestamp timestamp = (Timestamp) from; | ||
Instant epoch = Instant.EPOCH; | ||
Instant timestampInstant = timestamp.toInstant(); | ||
return Duration.between(epoch, timestampInstant); | ||
} | ||
} |
Oops, something went wrong.