-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more date-time conversions, improved nano resolutions on Double…
…. Many more tests added.
- Loading branch information
Showing
6 changed files
with
126 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
|
||
/** | ||
* @author John DeRegnaucourt ([email protected]) | ||
|
@@ -24,8 +27,6 @@ | |
* 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) { | ||
|
@@ -59,4 +60,16 @@ static Duration toDuration(Object from, Converter converter) { | |
Instant timestampInstant = timestamp.toInstant(); | ||
return Duration.between(epoch, timestampInstant); | ||
} | ||
|
||
static OffsetDateTime toOffsetDateTime(Object from, Converter converter) { | ||
Timestamp timestamp = (Timestamp) from; | ||
|
||
// Get the current date-time in the options ZoneId timezone | ||
ZonedDateTime zonedDateTime = ZonedDateTime.now(converter.getOptions().getZoneId()); | ||
|
||
// Extract the ZoneOffset | ||
ZoneOffset zoneOffset = zonedDateTime.getOffset(); | ||
|
||
return timestamp.toInstant().atOffset(zoneOffset); | ||
} | ||
} |
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