{"id":15405137,"url":"https://github.com/fnando/date_interval","last_synced_at":"2025-04-16T22:50:33.339Z","repository":{"id":13696993,"uuid":"16390841","full_name":"fnando/date_interval","owner":"fnando","description":"Parse date intervals from strings.","archived":false,"fork":false,"pushed_at":"2024-10-26T20:45:47.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T03:47:58.263Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["fnando"],"custom":["https://www.paypal.me/nandovieira/🍕"]}},"created_at":"2014-01-30T21:04:56.000Z","updated_at":"2024-10-26T20:45:50.000Z","dependencies_parsed_at":"2024-12-11T16:24:58.754Z","dependency_job_id":"085319d4-2f13-4b31-8af9-c1b4993e5662","html_url":"https://github.com/fnando/date_interval","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":0.09999999999999998,"last_synced_commit":"768211915da4d8d04caac89ea570c13a3e23e231"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fdate_interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fdate_interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fdate_interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fdate_interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/date_interval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249284469,"owners_count":21243965,"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":[],"created_at":"2024-10-01T16:15:10.513Z","updated_at":"2025-04-16T22:50:33.314Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://www.paypal.me/nandovieira/🍕"],"categories":[],"sub_categories":[],"readme":"# DateInterval\n\n[![Tests](https://github.com/fnando/browser/workflows/ruby-tests/badge.svg)](https://github.com/fnando/date_interval)\n[![Gem](https://img.shields.io/gem/v/date_interval.svg)](https://rubygems.org/gems/date_interval)\n[![Gem](https://img.shields.io/gem/dt/date_interval.svg)](https://rubygems.org/gems/date_interval)\n\nParse date intervals from strings.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem \"date_interval\"\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install date_interval\n\n## Usage\n\nYou must always define at least one range at the beginning of the expression.\nThe snippet below will return three dates objects.\n\n```ruby\nrequire \"date_interval\"\n\nexpr = \"2014-01-01 - 2014-01-03\"\ndates = DateInterval.parse(expr)\n```\n\nYou can provide as many intervals as you want. The following expression returns\nsix date objects.\n\n```ruby\nrequire \"date_interval\"\n\nexpr = \"2014-01-01 - 2014-01-03, 2014-02-01 - 2014-02-03\"\ndates = DateInterval.parse(expr)\n```\n\nYou can also define filters. Filters are applied in sequence, from left to\nright. The following filters are available:\n\n- `none`: return no dates. Useful for applying specific filters afterwards.\n- `[+-]weekends`: filter weekend dates\n- `[+-]weekdays`: filter weekdays\n- `[+-]sundays`: filter sundays. You can use any weekday name\n  (sundays-saturdays)\n- `[+-]holidays`: filter holidays. You must add the holidays by yourself (see\n  below)\n- `[+-]yyy-mm-dd`: add/remove the given date.\n\nBeware that duplicated dates are removed from the final result. They're also\nsorted.\n\nSome expression examples:\n\n```text\n# Don't return weekends\n2014-01-01 - 2014-01-05, -weekends\n\n# Return only weekends\n2014-01-01 - 2014-01-05, none, +weekends\n\n# Don't return weekdays\n2014-01-01 - 2014-01-05, -weekdays\n\n# Return only weekdays\n2014-01-01 - 2014-01-05, none, +weekdays\n\n# Return mondays, wednesdays and fridays\n2014-01-01 - 2014-01-05, none, +mondays, +wednesdays, +fridays\n\n# Return the specified range, including one more date\n2014-01-01 - 2014-01-05, +2014-07-31\n\n# Return the specified range, excluding one date\n2014-01-01 - 2014-01-05, -2014-01-05\n\n# Return the specified range, excluding holidays\n2014-01-01 - 2014-01-05, -holidays\n```\n\n### Defining holidays\n\nTo define your holidays you must use the method\n`DateInterval::Filter::Holiday.add`. It accepts one or more dates.\n\n```ruby\nrequire \"date_interval\"\n\nDateInterval::Filter::Holidays.add(\n  Date.parse(\"2014-01-01\"),\n  Date.parse(\"2014-12-25\"),\n)\n\nDateInterval.parse(\"2014-01-01 - 2014-12-31, none, +holidays\")\n# =\u003e [\n#     [0] #\u003cDate: 2014-01-01\u003e,\n#     [1] #\u003cDate: 2014-12-25\u003e\n#    ]\n```\n\n### Validating expressions\n\nTo validate if an expression is valid use the `DateInterval.valid?` method.\n\n```ruby\nrequire \"date_interval\"\n\nDateInterval.valid?(\"2014-01-01 - 2014-01-05\")\n#=\u003e true\n\nDateInterval.valid?(\"invalid\")\n#=\u003e false\n```\n\n## Contributing\n\n1. Fork it ( http://github.com/fnando/date_interval/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fdate_interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fdate_interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fdate_interval/lists"}