{"id":21564616,"url":"https://github.com/tudborg/elixir_interval","last_synced_at":"2026-02-18T16:30:53.779Z","repository":{"id":61052122,"uuid":"547925897","full_name":"tudborg/elixir_interval","owner":"tudborg","description":"Elixir Interval / range operations over any data type. Discrete + continuous, bounded \u0026 unbounded.","archived":false,"fork":false,"pushed_at":"2025-10-15T10:45:03.000Z","size":286,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-13T02:01:53.129Z","etag":null,"topics":["elixir","interval","library","range"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/interval","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tudborg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-08T15:23:00.000Z","updated_at":"2025-10-15T10:44:54.000Z","dependencies_parsed_at":"2025-06-10T15:06:53.200Z","dependency_job_id":"8d539aa4-dcb6-4f6a-8870-0526304c9cde","html_url":"https://github.com/tudborg/elixir_interval","commit_stats":null,"previous_names":["tbug/elixir_interval"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/tudborg/elixir_interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudborg%2Felixir_interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudborg%2Felixir_interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudborg%2Felixir_interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudborg%2Felixir_interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tudborg","download_url":"https://codeload.github.com/tudborg/elixir_interval/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tudborg%2Felixir_interval/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29585538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T13:56:48.962Z","status":"ssl_error","status_checked_at":"2026-02-18T13:54:34.145Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["elixir","interval","library","range"],"created_at":"2024-11-24T10:16:34.758Z","updated_at":"2026-02-18T16:30:53.760Z","avatar_url":"https://github.com/tudborg.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![Interval](assets/banner.png \"Interval\")\n\n[![CI](https://github.com/tbug/elixir_interval/actions/workflows/ci.yml/badge.svg)](https://github.com/tbug/elixir_interval/actions/workflows/ci.yml)\n[![Hex.pm](https://img.shields.io/hexpm/v/interval.svg)](https://hex.pm/packages/interval)\n[![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/interval/)\n\nDatatype and operations for both discrete and continuous intervals,\nInspired by [PostgreSQL's range types](https://www.postgresql.org/docs/current/rangetypes.html).\n\nFind the documentation at https://hexdocs.pm/interval/\n\n\n## Installation\n\nThe package can be installed by adding `interval` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:interval, \"~\u003e 2.0.0\"}\n  ]\nend\n```\n\n## Ecto \u0026 Postgres support\n\nThe builtin types (Like `Interval.DateTimeInterval`) can be used as an `Ecto.Type`\nwhich will convert to Postgres' range types.\n\n```elixir\n# ...\n  schema \"reservations\" do\n    field :period, Interval.DateTimeInterval\n    # ...\n  end\n# ...\n```\n\n\n## Built-in Interval Types\n\n- `Interval.IntegerInterval` A discrete interval between two integers.\n- `Interval.FloatInterval` A continuous interval between two floats.\n- `Interval.DecimalInterval` A continuous interval between two `Decimal` structs.\n- `Interval.DateInterval` A discrete interval between two `Date` structs.\n- `Interval.DateTimeInterval` A continuous interval between two `DateTime` structs.\n- `Interval.NaiveDateTimeInterval` A continuous interval between two `NaiveDateTime` structs.\n\nSee `Interval` for reference documentation on the available API functions.\n\n\nNote though, that this feature only works with `Postgrex`, as the\nintervals are converted to a `Postgrex.Range` struct which maps to the correct\nrange type in the database (like `tstzrange` etc.)\n\n## Defining your own interval type\n\nThe library contains a `use` macro that does most of the work for you.\n\nYou must implement the `Interval.Behaviour`, which contains a handful of functions.\n\nThis is the full definition of the built-in `Interval.DecimalInterval`:\n\n```elixir\ndefmodule Interval.DecimalInterval do\n  use Interval, type: Decimal, discrete: false\n\n  if Interval.Support.EctoType.supported?() do\n    use Interval.Support.EctoType, ecto_type: :numrange\n  end\n\n  @impl true\n  @spec point_normalize(any()) :: {:ok, Decimal.t()} | :error\n  def point_normalize(a) when is_struct(a, Decimal), do: {:ok, a}\n  def point_normalize(_), do: :error\n\n  @impl true\n  @spec point_compare(Decimal.t(), Decimal.t()) :: :lt | :eq | :gt\n  def point_compare(a, b) when is_struct(a, Decimal) and is_struct(b, Decimal) do\n    Decimal.compare(a, b)\n  end\nend\n```\n\n## More Examples\n\n### Integer intervals\n\nInteger intervals are discrete intervals (just like the `int4range` in Postgres).\n\n```elixir\nalias Interval.IntegerInterval\n# ...\na = IntegerInterval.new(1, 4, \"[]\")\n# [1, 5)\nb = IntegerInterval.new(2, 5, \"[]\")\n# [2, 6)\n\nassert IntegerInterval.contains?(a, b)\nassert IntegerInterval.overlaps?(a, b)\n\nc = IntegerInterval.intersection(a, b) # [2, 5)\nd = IntegerInterval.union(a, b) # [1, 6)\ne = IntegerInterval.difference(a, b) # [1, 2)\n```\n\nDiscrete intervals are always normalized to the bound form `[)` (just like in Postgres).\n\n\n### DateTime intervals\n\nDateTime intervals are continuous intervals (just like `tstzrange` in Postgres).\n\n```elixir\nalias Interval.DateTimeInterval\n# ...\n# default bound is  \"[)\"\na = DateTimeInterval.new(~U[2022-01-01 00:00:00Z], ~U[2023-01-01 00:00:00Z])\nb = DateTimeInterval.new(~U[2018-07-01 00:00:00Z], ~U[2022-03-01 00:00:00Z])\n\nDateTimeInterval.intersection(a, b)\n\n# %DateTimeInterval{\n#   left: {:inclusive, ~U[2022-01-01 00:00:00Z]},\n#   right: {:exclusive, ~U[2022-03-01 00:00:00Z]}\n# }\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftudborg%2Felixir_interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftudborg%2Felixir_interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftudborg%2Felixir_interval/lists"}