{"id":13507777,"url":"https://github.com/atabary/timex-interval","last_synced_at":"2026-02-21T06:32:34.552Z","repository":{"id":20892210,"uuid":"24179634","full_name":"atabary/timex-interval","owner":"atabary","description":"A date/time interval library for Elixir projects, based on Timex.","archived":false,"fork":false,"pushed_at":"2015-10-10T20:23:13.000Z","size":362,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-21T14:54:09.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/atabary.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-09-18T08:09:27.000Z","updated_at":"2024-07-25T23:11:28.000Z","dependencies_parsed_at":"2022-09-02T18:10:34.771Z","dependency_job_id":null,"html_url":"https://github.com/atabary/timex-interval","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/atabary/timex-interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atabary%2Ftimex-interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atabary%2Ftimex-interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atabary%2Ftimex-interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atabary%2Ftimex-interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atabary","download_url":"https://codeload.github.com/atabary/timex-interval/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atabary%2Ftimex-interval/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29675470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2024-08-01T02:00:38.944Z","updated_at":"2026-02-21T06:32:34.524Z","avatar_url":"https://github.com/atabary.png","language":"Elixir","funding_links":[],"categories":["Date and Time"],"sub_categories":[],"readme":"# Timex Interval\n\n**NOTE:** This project has been merged into Timex, as `Timex.Interval`, as of `1.0.0-pre`. If you are\non that version of Timex or higher, it is recommended you use that instead. However for prior releases\nof Timex, this project is still actively maintained :)\n\n[![hex.pm version](https://img.shields.io/hexpm/v/timex_interval.svg)](https://hex.pm/packages/timex_interval) [![travis.ci build status](http://img.shields.io/travis/atabary/timex-interval/master.svg)](https://travis-ci.org/atabary/timex-interval)\n\nTimex Interval is an extension of [Timex](https://github.com/bitwalker/timex) that deals with date/time intervals.\n\nIntervals are enumerable, making them useful to iterate over time intervals, for instance every day between two dates.\n\n\n## Constructors\n\nThe `DateTimeInterval` module provides a helper function to make new intervals.\n\nValid keywords:\n\n  - `from`: the date the interval starts at (defaults to `Date.now()`)\n  - `until`: either the date the interval ends at, or a time shift that will be applied to the \"from\" date (defaults to `[days: 7]`)\n  - `left_open`: whether the interval is left open, defaults to #{@default_left_open}\n  - `right_open`: whether the interval is right open, defaults to #{@default_right_open}\n  - `step`: the iteration step for enumerations, defaults to `[days: 1]`\n\nTime shifts should be keyword lists valid for use with `Timex.Date.shift`.\n\n```elixir\nuse Timex\nalias TimexInterval.DateTimeInterval, as: Interval\n\nInterval.new(from: Date.from({2014, 9, 22}), until: Date.from({2014, 9, 29}))\n|\u003e Interval.format!(\"%Y-%m-%d\")\n#=\u003e \"[2014-09-22, 2014-09-29)\"\n\nInterval.new(from: Date.from({2014, 9, 22}), until: [months: 5])\n|\u003e Interval.format!(\"%Y-%m-%d\")\n#=\u003e \"[2014-09-22, 2015-02-22)\"\n\nInterval.new(from: Date.from({{2014, 9, 22}, {15, 30, 0}}), until: [mins: 20], right_open: false)\n|\u003e Interval.format!(\"%H:%M\")\n#=\u003e \"[15:30, 15:50]\"\n\n```\n\nNote that by default intervals are right open.\n\n\n## Iterators\n\n`DateTimeInterval` implements the `Enumerable` protocol.\n\n```elixir\nuse Timex\nalias TimexInterval.DateTimeInterval, as: Interval\n\nInterval.new(from: Date.from({2014, 9, 22}), until: [days: 3])\n|\u003e Enum.map(fn(dt) -\u003e DateFormat.format!(dt, \"%Y-%m-%d\", :strftime) end)\n#=\u003e [\"2014-09-22\", \"2014-09-23\", \"2014-09-24\"]\n```\n\nYou can easily specify whether to exclude the first and last dates:\n\n```elixir\nInterval.new(from: Date.from({2014, 9, 22}), until: [days: 3], right_open: false)\n|\u003e Enum.map(fn(dt) -\u003e DateFormat.format!(dt, \"%Y-%m-%d\", :strftime) end)\n#=\u003e [\"2014-09-22\", \"2014-09-23\", \"2014-09-24\", \"2014-09-25\"]\n```\n\nYou can of course iterate over anything else, for instance by chunks of 10 minutes:\n\n```elixir\nInterval.new(from: Date.from({{2014, 9, 22}, {15, 0, 0}}), until: [hours: 1])\n|\u003e Interval.with_step(mins: 10)\n|\u003e Enum.map(fn(dt) -\u003e DateFormat.format!(dt, \"%H:%M\", :strftime) end)\n#=\u003e [\"15:00\", \"15:10\", \"15:20\", \"15:30\", \"15:40\", \"15:50\"]\n```\n\n## Duration\n\nYou can query an interval to know its duration, given a time unit.\n\nWhen the unit is one of `:secs`, `:mins`, `:hours`, `:days`, `:weeks`, `:months`, `:years`, the result is an `integer`.\n\nWhen the unit is `:timestamp`, the result is a tuple representing a valid `Timex.Time`.\n\n```elixir\nuse Timex\nalias TimexInterval.DateTimeInterval, as: Interval\n\nInterval.new(from: Date.from({2014, 9, 22}), until: [months: 5])\n|\u003e Interval.duration(:months)\n#=\u003e 5\n\nInterval.new(from: Date.from({{2014, 9, 22}, {15, 30, 0}}), until: [mins: 20])\n|\u003e Interval.duration(:timestamp)\n#=\u003e {0, 0, 1200}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatabary%2Ftimex-interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatabary%2Ftimex-interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatabary%2Ftimex-interval/lists"}