Skip to content

Commit

Permalink
Centis.roundSeconds: Seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 31, 2024
1 parent f23472e commit 08ba841
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/src/main/scala/Centis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package chess

import alleycats.Zero
import cats.kernel.Monoid

import scala.concurrent.duration.*
import scalalib.model.Seconds

// maximum centis = Int.MaxValue / 100 / 60 / 60 / 24 = 248 days
opaque type Centis = Int
Expand All @@ -15,12 +15,11 @@ object Centis extends RichOpaqueInt[Centis]:

inline def *(inline o: Int): Centis = centis * o

def roundTenths: Int = (if centis > 0 then centis + 5 else centis - 4) / 10
def roundSeconds: Int = Math.round(centis * 0.01f)
def roundTenths: Int = (if centis > 0 then centis + 5 else centis - 4) / 10
def roundSeconds: Seconds = Seconds(Math.round(centis * 0.01f))

inline def toSeconds: BigDecimal = java.math.BigDecimal.valueOf(centis, 2)
inline def millis: Long = centis * 10L
def toDuration: FiniteDuration = FiniteDuration(millis, MILLISECONDS)
inline def millis: Long = centis * 10L
def toDuration: FiniteDuration = FiniteDuration(millis, MILLISECONDS)

def *~(scalar: Float): Centis = ofFloat(scalar * centis)
def /(div: Int): Option[Centis] = (div != 0).option(centis / div)
Expand Down

0 comments on commit 08ba841

Please sign in to comment.