Skip to content

Commit 68b2607

Browse files
authored
Merge pull request #1851 from yisraelU/OffsetDateTimeMinor
[Core/JvmOnly] add fromJava method for OffsetDateTime type
2 parents 3a8a408 + 2bea333 commit 68b2607

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/core/src-jvm/smithy4s/time/OffsetDateTimeCompanionPlatform.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,13 @@ private[time] trait OffsetDateTimeCompanionPlatform {
3434
)
3535
}
3636

37+
/** JVM platform only method */
38+
def toJava(x: OffsetDateTime): JOffsetDateTime = {
39+
val instant = java.time.Instant
40+
.ofEpochSecond(x.timestamp.epochSecond, x.timestamp.nano.toLong)
41+
val offset = java.time.ZoneOffset.ofTotalSeconds(x.offset.seconds)
42+
java.time.OffsetDateTime.ofInstant(instant, offset)
43+
}
44+
3745
def now(): OffsetDateTime = fromJava(JOffsetDateTime.now())
3846
}

0 commit comments

Comments
 (0)