{"id":31796860,"url":"https://github.com/kevinstuffandthings/timeboss","last_synced_at":"2025-10-10T20:53:26.241Z","repository":{"id":44937862,"uuid":"279642899","full_name":"kevinstuffandthings/timeboss","owner":"kevinstuffandthings","description":"Broadcast Calendar navigation in Ruby made simple","archived":false,"fork":false,"pushed_at":"2023-08-09T17:07:40.000Z","size":336,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T23:31:21.626Z","etag":null,"topics":["broadcast-calendar","gregorian-calendars","ruby","rubygems"],"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/kevinstuffandthings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-14T16:52:16.000Z","updated_at":"2025-05-21T09:33:42.000Z","dependencies_parsed_at":"2022-07-20T09:34:00.332Z","dependency_job_id":null,"html_url":"https://github.com/kevinstuffandthings/timeboss","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/kevinstuffandthings/timeboss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinstuffandthings%2Ftimeboss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinstuffandthings%2Ftimeboss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinstuffandthings%2Ftimeboss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinstuffandthings%2Ftimeboss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinstuffandthings","download_url":"https://codeload.github.com/kevinstuffandthings/timeboss/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinstuffandthings%2Ftimeboss/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005255,"owners_count":26083864,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["broadcast-calendar","gregorian-calendars","ruby","rubygems"],"created_at":"2025-10-10T20:52:55.606Z","updated_at":"2025-10-10T20:53:26.234Z","avatar_url":"https://github.com/kevinstuffandthings.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TimeBoss ![Build Status](https://github.com/kevinstuffandthings/timeboss/actions/workflows/ruby.yml/badge.svg) [![Gem Version](https://badge.fury.io/rb/timeboss.svg)](https://badge.fury.io/rb/timeboss)\n\nA gem providing convenient navigation of the [Broadcast Calendar](https://en.wikipedia.org/wiki/Broadcast_calendar), the standard Gregorian calendar, and is easily extensible to support multiple financial calendars.\n\nOriginally developed for [Simulmedia](https://simulmedia.com).\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\n# update with the version of your choice\ngem 'timeboss'\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install timeboss\n```\n\n## Usage\nSupports `year`, `half`, `quarter`, `month`, `week`, and `day`.\n\nPrepare your calendar for use:\n\n```ruby\nrequire 'timeboss/calendars/broadcast'\n\ncalendar = TimeBoss::Calendars::Broadcast.new\n# =\u003e #\u003cTimeBoss::Calendars::Broadcast:0x007f82d50f0af0 @basis=TimeBoss::Calendars::Broadcast::Basis\u003e\n```\n\nYou can ask simple questions of the calendar:\n\n```ruby\nperiod = calendar.parse('2019Q4') # or '2018', or '2019-12-21', or '2020W32', or '2020M3W2'\n# =\u003e #\u003cTimeBoss::Calendar::Quarter start_date=2019-09-30, end_date=2019-12-29\u003e\nperiod.to_s\n# =\u003e \"2019Q4: 2019-09-30 thru 2019-12-29\"\nperiod.next.start_date.to_s # try previous, too!\n# =\u003e \"2019-12-30\"\n(period + 3).start_date.to_s # try subtraction, too!\n# =\u003e \"2020-06-29\"\nperiod.offset(3).start_date.to_s # works with negatives, too!\n# =\u003e \"2020-06-29\"\nperiod.current? # does today fall within this period?\n# =\u003e false\n\ncalendar.year_for(Date.parse('2018-12-31')).to_s\n# =\u003e \"2019: 2018-12-31 thru 2019-12-29\"\n\ncalendar.this_month.to_s # your results may vary\n# =\u003e \"2019M12: 2019-11-25 thru 2019-12-29\"\n\ncalendar.years_back(2).map { |y| y.start_date.to_s } # run in 2020\n# =\u003e [\"2018-12-31\", \"2019-12-30\"]\n\ncalendar.months_ago(3).name # run in 2020M7\n# =\u003e \"2020M4\"\n\ncalendar.weeks_ahead(3).name # run in 2020W29\n# =\u003e \"2020W32\"\n```\n\nThe resulting periods can be formatted a variety of (parsable) ways:\n\n```ruby\nentry = calendar.parse('2020W24')\nentry.format\n# =\u003e \"2020H1Q2M3W2\"\n\nentry.format(:quarter)\n# =\u003e \"2020Q2W11\"\n\nentry.format(:quarter, :month)\n# =\u003e \"2020Q2M3W2\"\n```\n\n_Note: all parsable descriptors should be ordered by chronological specificity (from least to most)_\n\nEach type of period can give you information about its constituent periods:\n\n```ruby\ncalendar.this_month.weeks.map(\u0026:to_s)\n# =\u003e [\"2020M1W1: 2019-12-30 thru 2020-01-05\", \"2020M1W2: 2020-01-06 thru 2020-01-12\", \"2020M1W3: 2020-01-13 thru 2020-01-19\", \"2020M1W4: 2020-01-20 thru 2020-01-26\"]\n\ncalendar.this_year.weeks.last.to_s\n# =\u003e \"2020W52: 2020-12-21 thru 2020-12-27\"\n\ncalendar.last_month.quarter.title # today is 2020-07-15\n# =\u003e \"Q2 2020\"\n\ncalendar.parse('2020Q1').months.map(\u0026:name)\n# =\u003e [\"2020M1\", \"2020M2\", \"2020M3\"]\n```\n\nPeriod shifting is easy. Note that the shifts are relative to today, not the base date. A shift examines the base period to find its offset into the shifting period size, and project it relative to now.\n\n```ruby\ncalendar.parse('Q3').years_ago(5).title\n# =\u003e \"Q3 2015\"\n\nweek = calendar.this_week # run 2020W29\n\"#{week.name}: #{week.in_quarter} of #{week.quarter.name}; #{week.in_year} of #{week.year.name}\"\n# =\u003e \"2020W29: 3 of 2020Q3; 29 of 2020\"\n\n# run 2020W29, this generates the same as above, because shifts are relative to date run!\nweek = calendar.parse('2014W29').this_week\n\"#{week.name}: #{week.in_quarter} of #{week.quarter.name}; #{week.in_year} of #{week.year.name}\"\n# =\u003e \"2020W29: 3 of 2020Q3; 29 of 2020\"\n\ncalendar.this_week.next_year.to_s # run 2020W29\n# =\u003e \"2021W29: 2021-07-12 thru 2021-07-18\"\n\ncalendar.week(2016, this_week.in_year) # run 2020-07-22\n# =\u003e #\u003cTimeBoss::Calendar::Week start_date=2016-07-18, end_date=2016-07-24\u003e\n```\n\nComplicated range expressions can be parsed using the `..` range operator, or evaluated with `thru`:\n\n```ruby\ncalendar.parse('2020M1 .. 2020M2').weeks.map(\u0026:title)\n# =\u003e [\"Week of December 30, 2019\", \"Week of January 6, 2020\", \"Week of January 13, 2020\", \"Week of January 20, 2020\", \"Week of January 27, 2020\", \"Week of February 3, 2020\", \"Week of February 10, 2020\", \"Week of February 17, 2020\"]\n\ncalendar.this_quarter.thru(calendar.this_quarter+2).months.map(\u0026:name) # run in 2020Q3\n# =\u003e [\"2020M7\", \"2020M8\", \"2020M9\", \"2020M10\", \"2020M11\", \"2020M12\", \"2021M1\", \"2021M2\", \"2021M3\"]\n\nperiod = calendar.parse('2020W3..2020Q1')\n\"#{period.name}: from #{period.start_date} thru #{period.end_date} (current=#{period.current?})\"\n# =\u003e \"2020W3 .. 2020Q1: from 2020-01-13 thru 2020-03-29 (current=false)\"\n```\n\nThe examples above are just samples. Try different periods, operators, etc. All of the non-week-based operations will work similarly on the `TimeBoss::Calendars::Gregorian` calendar.\n\n### REPL\nTo open a [REPL](https://repl.it/github/kevinstuffandthings/timeboss) locally for the broadcast calendar, use the `tbsh` executable, or the `timeboss:calendars:broadcast:repl` rake task.\n\nFor the Gregorian calendar (or any other implemented calendars), supply the name on the command line.\n- `tbsh gregorian`\n- `rake timeboss:calendars:gregorian:repl`\n\nYou will find yourself in the context of an instantiated `TimeBoss::Calendar` object:\n\n```bash\n$ tbsh\n2.4.1 :001 \u003e next_quarter\n =\u003e #\u003cTimeBoss::Calendar::Quarter start_date=2020-09-28, end_date=2020-12-27\u003e\n2.4.1 :002 \u003e last_year\n =\u003e #\u003cTimeBoss::Calendar::Year start_date=2018-12-31, end_date=2019-12-29\u003e\n2.4.1 :003 \u003e parse('this_quarter .. this_quarter+4').months.map(\u0026:name)\n =\u003e [\"2020M7\", \"2020M8\", \"2020M9\", \"2020M10\", \"2020M11\", \"2020M12\", \"2021M1\", \"2021M2\", \"2021M3\", \"2021M4\", \"2021M5\", \"2021M6\", \"2021M7\", \"2021M8\", \"2021M9\"]\n```\n\nIf you want to try things out locally without installing the gem or updating your ruby environment, you can use [Docker](https://docker.com):\n\n```bash\n$ docker run --rm -it ruby:3.0-slim /bin/bash -c \"gem install timeboss shellable \u003e/dev/null \u0026\u0026 tbsh\"\n```\n\n_Having trouble with the REPL? If you are using the examples from the [Usage](#Usage) section, keep in mind that the REPL is already in the context of the calendar -- so you don't need to specify the receiver!_\n\n## Creating new calendars\nTo create a custom calendar, simply extend the `TimeBoss::Calendar` class, and implement a new `TimeBoss::Calendar::Support::MonthBasis` for it.\n\n```ruby\nrequire 'timeboss/calendar'\nrequire 'timeboss/calendar/support/has_fiscal_weeks'\n\nmodule MyCalendars\n  class AugustFiscal \u003c TimeBoss::Calendar\n    # The calendar we wish to implement has \"fiscal weeks\", meaning that the weeks start on\n    # the day of the containing period.\n    include TimeBoss::Calendar::Support::HasFiscalWeeks\n\n    def initialize\n      # For each calendar, operation, the class will be instantiated with an ordinal value\n      # for `year` and `month`. It is the instance's job to translate those ordinals into\n      # `start_date` and `end_date` values, based on the desired behavior of the calendar.\n      # With month rules defined, TimeBoss will be able to navigate all the relative periods\n      # within the calendar.\n      super(basis: Basis)\n    end\n\n    private\n\n    class Basis \u003c TimeBoss::Calendar::Support::MonthBasis\n      # In this example, August is the first month of the fiscal year. So an incoming 2020/1\n      # value would translate to a gregorian 2019/8.\n      START_MONTH = 8\n\n      def start_date\n        @_start_date ||= begin\n                           date = Date.civil(year_index, month_index, 1)\n                           date - (date.wday + 7) % 7 # In this calendar, months start Sunday.\n                         end\n      end\n\n      def end_date\n        @_end_date ||= begin\n                         date = Date.civil(year_index, month_index, -1)\n                         date - (date.wday + 1)\n                       end\n      end\n\n      private\n\n      def month_index\n        ((month + START_MONTH - 2) % 12) + 1\n      end\n\n      def year_index\n        month \u003e= START_MONTH ? year : year - 1\n      end\n    end\n  end\nend\n```\n\nWith the new calendar implemented, it can be accessed in one of 2 ways:\n\n- via traditional instantiation:\n\n    ```ruby\n    calendar = MyCalendars::AugustFiscal.new\n    calendar.this_year\n    ```\n\n- via `TimeBoss::Calendars`:\n\n    ```ruby\n    require 'timeboss/calendars'\n    TimeBoss::Calendars.register(:august_fiscal, MyCalendars::AugustFiscal)\n\n    # You'll get a cached instance of your calendar here.\n    # Handy when switching back and forth between different calendar implementations.\n    calendar = TimeBoss::Calendars[:august_fiscal]\n    calendar.this_year\n    ```\n\n# Problems?\nPlease submit an [issue](https://github.com/kevinstuffandthings/timeboss/issues).\nWe'll figure out how to get you up and running with TimeBoss as smoothly as possible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinstuffandthings%2Ftimeboss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinstuffandthings%2Ftimeboss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinstuffandthings%2Ftimeboss/lists"}