{"id":13507771,"url":"https://github.com/hopsor/open_hours","last_synced_at":"2025-10-21T17:39:55.981Z","repository":{"id":62430179,"uuid":"164609596","full_name":"hopsor/open_hours","owner":"hopsor","description":"Time calculations using business hours","archived":false,"fork":false,"pushed_at":"2025-03-06T11:50:13.000Z","size":41,"stargazers_count":50,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-06T12:25:09.435Z","etag":null,"topics":["business-hours","datetime","elixir","holidays","time"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hopsor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2019-01-08T09:10:24.000Z","updated_at":"2025-03-06T11:50:19.000Z","dependencies_parsed_at":"2024-01-05T21:54:27.336Z","dependency_job_id":"a8cc3cc8-0ffd-4178-924a-03797663f5bf","html_url":"https://github.com/hopsor/open_hours","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hopsor%2Fopen_hours","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hopsor%2Fopen_hours/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hopsor%2Fopen_hours/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hopsor%2Fopen_hours/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hopsor","download_url":"https://codeload.github.com/hopsor/open_hours/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301963,"owners_count":20755512,"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":["business-hours","datetime","elixir","holidays","time"],"created_at":"2024-08-01T02:00:38.822Z","updated_at":"2025-10-21T17:39:55.632Z","avatar_url":"https://github.com/hopsor.png","language":"Elixir","funding_links":[],"categories":["Date and Time"],"sub_categories":[],"readme":"\n# OpenHours\n[![Build Status](https://github.com/hopsor/open_hours/actions/workflows/ci.yml/badge.svg)](https://github.com/hopsor/open_hours/actions?query=workflow%3A%22CI%22) [![Package Version](https://img.shields.io/hexpm/v/open_hours.svg?color=purple)](https://hex.pm/packages/open_hours)\n\nOpenHours is an Elixir package aimed to help with time calculations using business hours.\n\nIt's inspired by the amazing ruby gem [biz](https://github.com/zendesk/biz) developed by Zendesk.\n\n## Installation\n\nThe package can be installed by adding `open_hours` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:open_hours, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\n\nIn order to use OpenHours functions you first need a `Schedule` config:\n\n```elixir\nschedule = %OpenHours.Schedule{\n  hours: %{\n    mon: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],\n    tue: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],\n    wed: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}],\n    thu: [{~T[09:00:00], ~T[14:00:00]}, {~T[15:00:00], ~T[20:00:00]}]\n  },\n  holidays: [\n    ~D[2019-01-14]\n  ],\n  shifts: [\n    {~D[2019-01-15], [{~T[10:00:00], ~T[15:00:00]}]}\n  ],\n  breaks: [\n    {~D[2019-01-16], [{~T[17:00:00], ~T[20:00:00]}]}\n  ],\n  time_zone: \"Europe/Madrid\"\n}\n```\n\nThere are five settings to configure in a schedule:\n\n- `hours`: Map containing all the open hours intervals for a regular week.\n- `holidays`: List of dates in which the business is closed.\n- `shifts`: Special dates where the business has a different hour schedule.\n- `breaks`: Special dates where the business has interruption intervals.\n- `time_zone`: Time zone of the schedule.\n\nOpenHours offers two main functionalities.\n\n### Checking a DateTime is within open hours\n\n```elixir\n\u003e at = DateTime.from_naive!(~N[2019-01-15 14:00:00], \"Europe/Madrid\", Tzdata.TimeZoneDatabase)\n#DateTime\u003c2019-01-15 14:00:00+01:00 CET Europe/Madrid\u003e\n\n\u003e OpenHours.Schedule.in_hours?(schedule, at)\ntrue\n\n\u003e at = DateTime.from_naive!(~N[2019-01-14 12:00:00], \"Europe/Madrid\", Tzdata.TimeZoneDatabase)\n#DateTime\u003c2019-01-14 12:00:00+01:00 CET Europe/Madrid\u003e\n\n\u003e OpenHours.Schedule.in_hours?(schedule, at)\nfalse\n```\n\n### Calculate all TimeSlot between two dates\n\n```elixir\n\u003e starts_at = DateTime.from_naive!(~N[2019-01-14 12:00:00], \"Europe/Madrid\", Tzdata.TimeZoneDatabase)\n#DateTime\u003c2019-01-14 12:00:00+01:00 CET Europe/Madrid\u003e\n\n\u003e ends_at = DateTime.from_naive!(~N[2019-01-16 22:00:00], \"Europe/Madrid\", Tzdata.TimeZoneDatabase)\n#DateTime\u003c2019-01-16 22:00:00+01:00 CET Europe/Madrid\u003e\n\n\u003e OpenHours.TimeSlot.between(schedule, starts_at, ends_at)\n[\n  %OpenHours.TimeSlot{\n    ends_at: #DateTime\u003c2019-01-15 15:00:00+01:00 CET Europe/Madrid\u003e,\n    starts_at: #DateTime\u003c2019-01-15 10:00:00+01:00 CET Europe/Madrid\u003e\n  },\n  %OpenHours.TimeSlot{\n    ends_at: #DateTime\u003c2019-01-16 14:00:00+01:00 CET Europe/Madrid\u003e,\n    starts_at: #DateTime\u003c2019-01-16 09:00:00+01:00 CET Europe/Madrid\u003e\n  },\n  %OpenHours.TimeSlot{\n    ends_at: #DateTime\u003c2019-01-16 17:00:00+01:00 CET Europe/Madrid\u003e,\n    starts_at: #DateTime\u003c2019-01-16 15:00:00+01:00 CET Europe/Madrid\u003e\n  }\n]\n```\n\n## License\n\nThis software is licensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopsor%2Fopen_hours","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhopsor%2Fopen_hours","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopsor%2Fopen_hours/lists"}