Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private[time] trait LocalTimeCompanionPlatform {

/** JVM platform only method */
def fromJava(x: JLocalTime): LocalTime =
LocalTime(x.getSecond(), x.getNano())
LocalTime.apply(x.getHour, x.getMinute, x.getSecond, x.getNano)

def now(): LocalTime = fromJava(JLocalTime.now())
}
9 changes: 7 additions & 2 deletions modules/core/src-jvm/smithy4s/time/LocalTimePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import java.time.{LocalTime => JLocalTime}
private[time] trait LocalTimePlatform { self: LocalTime =>

/** JVM platform only method */
def toJava: JLocalTime =
JLocalTime.ofSecondOfDay(seconds.toLong).plusNanos(nano.toLong)
def toJava: JLocalTime = {
val minutesOfDay = seconds / 60
val hour = minutesOfDay / 60
val minute = minutesOfDay - hour * 60
val second = seconds - minutesOfDay * 60
JLocalTime.of(hour, minute, second, nano)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ private[time] trait OffsetDateTimeCompanionPlatform {

/** JVM platform only method */
def toJava(x: OffsetDateTime): JOffsetDateTime = {
val instant = java.time.Instant
.ofEpochSecond(x.timestamp.epochSecond, x.timestamp.nano.toLong)
val offset = java.time.ZoneOffset.ofTotalSeconds(x.offset.seconds)
java.time.OffsetDateTime.ofInstant(instant, offset)
val offsetSeconds = x.offset.seconds
val timestamp = x.timestamp
val instant = java.time.Instant.ofEpochSecond(
timestamp.epochSecond - offsetSeconds,
timestamp.nano.toLong
)
JOffsetDateTime.ofInstant(
instant,
java.time.ZoneOffset.ofTotalSeconds(offsetSeconds)
)
}

def now(): OffsetDateTime = fromJava(JOffsetDateTime.now())
Expand Down
Loading