cats-time Build Status Maven Central

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(
  "io.chrisdavenport" %% "cats-time"     % "<version>"
)

Examples

First lets start with some imports.

import io.chrisdavenport.cats.time._
import cats._
import cats.implicits._
import java.time._

Then we can display the Show instances.

Duration.ofDays(3).show
// res0: String = PT72H

Instant.now.show
// res1: String = 2019-08-28T10:17:15.810921Z

LocalDate.now.show
// res2: String = 2019-08-28

LocalDateTime.now.show
// res3: String = 2019-08-28T10:17:16.995532

LocalTime.now.show
// res4: String = 10:17:17.849944

MonthDay.now.show
// res5: String = 8-28

OffsetDateTime.now.show
// res6: String = 2019-08-28T10:17:18.767586Z

OffsetTime.now.show
// res7: String = 10:17:19.173852Z

Period.ofWeeks(6).show
// res8: String = P42D

Year.now.show
// res9: String = 2019

YearMonth.now.show
// res10: String = 2019-08

ZoneId.systemDefault.show
// res11: String = UTC

ZonedDateTime.now.show
// res12: String = 2019-08-28T10:17:21.193577Z[UTC]