cats-time
Instances for Cats Typeclasses for Java 8 Time. Similar to the encoding that are offered in Circe and Cormorant.
Time is a pain to deal with reasonably. So tread with caution.
Quick Start
To use cats-time in an existing SBT project with Scala 2.11 or a later version, add the following dependencies to your
build.sbt
depending on your needs:
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-time" % "0.5.1"
)
Examples
First lets start with some imports.
import org.typelevel.cats.time._
import cats.syntax.all._
import java.time._
Then we can display the Show
instances.
DayOfWeek.MONDAY.show
// res0: String = "Monday"
Duration.ofDays(3).show
// res1: String = "PT72H"
Instant.now.show
// res2: String = "2024-12-15T09:54:30.587608Z"
LocalDate.now.show
// res3: String = "2024-12-15"
LocalDateTime.now.show
// res4: String = "2024-12-15T09:54:30.588886"
LocalTime.now.show
// res5: String = "09:54:30.589545"
MonthDay.now.show
// res6: String = "12-15"
OffsetDateTime.now.show
// res7: String = "2024-12-15T09:54:30.590887Z"
OffsetTime.now.show
// res8: String = "09:54:30.592596Z"
Period.ofWeeks(6).show
// res9: String = "P42D"
Year.now.show
// res10: String = "2024"
YearMonth.now.show
// res11: String = "2024-12"
ZoneId.systemDefault.show
// res12: String = "Etc/UTC"
ZonedDateTime.now.show
// res13: String = "2024-12-15T09:54:30.594862Z[Etc/UTC]"