{"id":18068443,"url":"https://github.com/tmccarthy/intime","last_synced_at":"2025-04-05T16:13:38.868Z","repository":{"id":57715040,"uuid":"196002763","full_name":"tmccarthy/intime","owner":"tmccarthy","description":"Scala integration for the java.time classes","archived":false,"fork":false,"pushed_at":"2021-01-04T21:50:55.000Z","size":973,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-11T12:45:49.545Z","etag":null,"topics":["argonaut","cats","java-time","java8-date-time","scala","scalacheck"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmccarthy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-09T12:19:38.000Z","updated_at":"2024-12-09T19:54:15.000Z","dependencies_parsed_at":"2022-09-02T22:01:31.343Z","dependency_job_id":null,"html_url":"https://github.com/tmccarthy/intime","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Fintime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Fintime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Fintime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccarthy%2Fintime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmccarthy","download_url":"https://codeload.github.com/tmccarthy/intime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361701,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argonaut","cats","java-time","java8-date-time","scala","scalacheck"],"created_at":"2024-10-31T08:06:30.889Z","updated_at":"2025-04-05T16:13:38.816Z","avatar_url":"https://github.com/tmccarthy.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `intime`\n[![CircleCI](https://circleci.com/gh/tmccarthy/intime/tree/master.svg?style=svg)](https://circleci.com/gh/tmccarthy/intime/tree/master)\n[![Maven Central](https://img.shields.io/maven-central/v/au.id.tmm.intime/intime-core_2.13.svg)](https://repo.maven.apache.org/maven2/au/id/tmm/intime/intime-core_2.13/)\n\nLibraries for integration between the [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)\nclasses and common Scala libraries.\n\n* [`intime-core`](#intime-core) provides integration with the core Scala library\n* [`intime-cats`](#intime-cats) provides instances for the [Cats](https://github.com/typelevel/cats) FP library\n* [`intime-argonaut`](#intime-argonaut) provides encoders and decoders for the [Argonaut](https://github.com/argonaut-io/argonaut) JSON library\n* [`intime-scalacheck`](#intime-scalacheck) provides instances for the [Scalacheck](https://github.com/rickynils/scalacheck) property-based-testing library\n\nAdd the following to your `build.sbt` file:\n\n```scala\nval intimeVersion = \"2.2.0\"\n\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-core\"       % intimeVersion\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-cats\"       % intimeVersion        // Cats integration\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-argonaut\"   % intimeVersion        // Argonaut integration\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-scalacheck\" % intimeVersion % Test // Scalacheck integration\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## `intime-core`\n\n`intime-core` adds integrations with the Scala standard library. Add it to your project with:\n\n```scala\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-core\" % \"1.0.2\"\n```\n\n#### `Ordering` instances for ordered classes\n\n`intime-core` provides `Ordering` instances for all classes in the `java.time` package for which an ordering can be\ndefined. This includes the most common classes like `Instant` and `LocalDate`.\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.std.implicits._\n\nval dates: List[LocalDate] = List(\n  LocalDate.of(2003, 3, 23),\n  LocalDate.of(2015, 3, 29),\n  LocalDate.of(2007, 4, 28),\n)\n\ndates.sorted // Sorts list of dates\n```\n\n#### `PartialOrdering` instances for `Period`\n\n`Period` presents some problems when it comes to defining an `Ordering` instance, as any two instances cannot\nnecessarily be compared (is 1 month longer or shorter than 30 days?). `intime-core` provides a `PartialOrdering` for\neach, handling those cases where an ordering can be computed.\n\n#### Overloaded operators\n\n`intime-core` provides overloaded operators for arithmetic and comparison operations on `java.time` classes:\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.std.implicits._\n\nLocalDate.of(1999, 6, 20) + Period.ofDays(3) // 1999-06-23\nInstant.EPOCH - Duration.ofSeconds(5)        // 1969-12-31T23:59:55Z\nPeriod.ofDays(5) * 3                         // P15D\n- Duration.ofHours(42)                       // PT-42H\nDuration.ofDays(30) / 10                     // P3D\nInstant.MAX \u003e Instant.EPOCH                  // true\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## `intime-cats`\n\n`intime-cats` adds integrations with [Cats](https://github.com/typelevel/cats). Add it to your project with:\n\n```scala\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-cats\" % \"1.0.2\"\n```\n\nAll instances are tested with [discipline](https://github.com/typelevel/discipline).\n\n#### `Hash` and `Show` instances\n\n`intime-cats` provides `Hash` and `Show` instances for all classes in `java.time`.\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.cats.implicits._\n\nimport cats.syntax.show._\nimport cats.syntax.eq._\n\nLocalDate.of(1999, 6, 20).show  // 1999-06-20\nInstant.EPOCH === Instant.EPOCH // true\n```\n\n#### `Order` and `PartialOrder` instances\n\n`intime-cats` uses the orderings in `intime-core` to define Cats `Order` instances (`PartialOrder` for `Period`).\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.cats.implicits._\n\nimport cats.syntax.partialOrder._\n\nLocalDate.of(2003, 3, 23) \u003c LocalDate.of(2015, 3, 29) // true\n\nPeriod.ofYears(1) \u003c Period.ofMonths(13)               // true\nPeriod.ofDays(30) partialCompare Period.ofMonths(1)   // NaN\n```\n\n#### `CommutativeGroup` instances for `Period` and `Duration`\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.cats.implicits._\n\nimport cats.syntax.group._\n\nDuration.ofDays(1) |+| Duration.ofHours(2) // P1DT2H\nDuration.ofDays(1) |-| Duration.ofHours(2) // PT22H\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## `intime-scalacheck`\n\n`intime-scalacheck` adds integrations with [Scalacheck](https://github.com/rickynils/scalacheck). Add it to your project\nwith:\n\n```scala\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-scalacheck\" % \"1.0.2\" % \"test\"\n```\n\n#### `Arbitrary` instances\n\n`intime-scalacheck` provides instances of `Arbitrary` for all classes in `java.time`. These can be used to generate\narbitrary instances for property-based testing.\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.scalacheck._\n\nimport org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks._\n\nforAll { localDate: LocalDate =\u003e\n  assert(localDate.plusDays(1) isAfter localDate)\n}\n```\n\n#### Generators for \"sensible\" datetime values\n\n`intime-scalacheck` provides generators for \"sensible\" values of `java.time` classes. The generated values are all\nbetween 1900 and 2100, allowing property-based-tests that don't have to worry about peculiarities like\n[year zero](https://en.wikipedia.org/wiki/Year_zero) or durations that overflow.\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.scalacheck._\n\nimport org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks._\n\nforAll(genSensibleLocalDate) { localDate: LocalDate =\u003e\n  assert(localDate.getYear \u003e= 1900)\n}\n```\n\n#### `Choose` instances\n\n`intime-scalacheck` provides instances of `Choose`, which let you define your own generators that produce values within\na range.\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.scalacheck._\n\nimport org.scalacheck.Gen\nimport org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks._\n\nval rangeGenerator: Gen[LocalDate] = Gen.choose(\n  min = LocalDate.of(2019, 5, 30),\n  max = LocalDate.of(2019, 7, 14),\n)\n\nforAll(rangeGenerator) { localDate: LocalDate =\u003e\n  assert(localDate.getYear == 2019)\n}\n```\n\n#### `Shrink` instances\n\n`intime-scalacheck` provides instances for `Shrink`, which Scalacheck will use to try to identify the smallest value for\nwhich a test fails. These are used automatically as long as you have the import:\n\n```scala\nimport au.id.tmm.intime.scalacheck._\n```\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## `intime-argonaut`\n\n`intime-argonaut` provides integration with the [Argonaut](https://github.com/argonaut-io/argonaut) library for JSON\nhandling. Add it to your project with:\n\n```scala\nlibraryDependencies += \"au.id.tmm.intime\" %% \"intime-argonaut\" % \"1.0.2\"\n```\n\n#### Standard encoders and decoders\n\n`intime-argonaut` defines `EncodeJson` and `DecodeJson` instances for all classes in the `java.time` package. They are\nencoded and decoded to JSON strings according to the most obvious format (see\n[`StandardCodecs`](argonaut/src/main/scala/au/id/tmm/intime/argonaut/StandardCodecs.scala).\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.argonaut._\n\nimport argonaut.Argonaut._\n\nLocalDate.of(2019, 7, 14).asJson    // jString(\"2019-07-14\")\njString(\"2019-07-14\").as[LocalDate] // DecodeResult.ok(LocalDate.of(2019, 7, 14))\n```\n\n#### Custom encoders and decoders\n\n`intime-argonaut` allows for the definition of custom `EncodeJson` and `DecodeJson` instances using instances of\n[`DateTimeFormatter`](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html).\n\n```scala\nimport java.time._\nimport au.id.tmm.intime.argonaut._\n\nimport argonaut.Argonaut._\n\nval formatter = DateTimeFormatter.ofPattern(\"MM-dd-uuuu\")\nimplicit val customCodec = DateTimeFormatterCodecs.localDateCodecFrom(formatter)\n\nLocalDate.of(2019, 7, 14).asJson    // jString(\"07-14-2019\")\njString(\"07-14-2019\").as[LocalDate] // DecodeResult.ok(LocalDate.of(2019, 7, 14))\n```\n\n#### Known issues\n\n* In Java 8, the standard codec for `ZonedDateTime` will fail to decode when the zone is `GMT`. This is fixed in Java 11.\n* In Java 8, the standard codec for `Duration` will drop the negative sign for durations between 0 and -1 seconds. This\n  is fixed in Java 11.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccarthy%2Fintime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmccarthy%2Fintime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccarthy%2Fintime/lists"}