cats-effect-time - Java Time from Cats-Effect Maven Central

Quick Start

To use cats-effect-time in an existing SBT project with Scala 2.12 or a later version, add the following dependencies to your build.sbt depending on your needs:

libraryDependencies ++= Seq(
  "io.chrisdavenport" %% "cats-effect-time" % "<version>"
)

Example

import cats.effect._
import io.chrisdavenport.cats.effect.time.JavaTime

// For Display Purposes Only
// Do Not Use In Production Code
import cats.effect.unsafe.implicits.global

// Works with a valid Functor and Clock in scope
val currentTimeOp = JavaTime[IO].getInstant
// currentTimeOp: IO[Instant] = Map(
//   ioe = IO(...),
//   f = io.chrisdavenport.cats.effect.time.JavaTime$ClockJavaTime$$Lambda$11302/1897482168@550d4893,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )

currentTimeOp.unsafeRunSync()
// res0: Instant = 2023-04-18T23:56:13.088Z

// Or you can use it implicitly
import io.chrisdavenport.cats.effect.time.implicits._

val currentTime = Clock[IO].getZonedDateTimeUTC
// currentTime: IO[ZonedDateTime] = Map(
//   ioe = Map(
//     ioe = IO(...),
//     f = io.chrisdavenport.cats.effect.time.JavaTime$ClockJavaTime$$Lambda$11302/1897482168@1039edbd,
//     event = cats.effect.tracing.TracingEvent$StackTrace
//   ),
//   f = io.chrisdavenport.cats.effect.time.JavaTime$ClockJavaTime$$Lambda$11354/992280455@25ab948e,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )
currentTime.unsafeRunSync()
// res1: ZonedDateTime = 2023-04-18T23:56:13.093Z