timeboss 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65f9e2cd955a728e0efd00e99f530f1ff6dbb7ee0c8cee7e25499466fb10edc9
4
- data.tar.gz: 9523e2983ffff0d5d33cf9b07e7fd4cd1b26b54c68e8a3f77d8996aaa7ad991d
3
+ metadata.gz: 3299b203ac582ad852fb3411015fb1c8d53ab9b59fbae51f133e79e4750ba912
4
+ data.tar.gz: ae84c4d98f8996519c30b05700f359faca2f66492c78e46f2eda0cf9e2fcc60c
5
5
  SHA512:
6
- metadata.gz: 1f850961e4659cee0b07e59d4421f1444c39e3882338f5189cd5821e5d4ec00228c4043aef7c001df8a2181cf4161671943653e7e0c843f419f4f7d91b6bb99d
7
- data.tar.gz: 24a8f28844c20caf7f0294a5e5db155ff809f46ad76e421e97d807b929ceca37035d9b89539a5600713d9420ba8f799fa1668c61e47b040a8728c41df12a67df
6
+ metadata.gz: d2c3e30df4a6256bab1428fb470cbc21f7d44c89747ebd08b390d7b324b010980c2592fbbab3e503c0a21dc20705c03036cd9e68d6c67b844bf372ee19ad9bc0
7
+ data.tar.gz: 79994538d0477b935d1b17887f9e2748f73e59511d84e0dfffb236e0798bc39d1416cecc3e452965a7e96b0ddce156f92771cdeaf73080ca9b6892b1b5ace896
@@ -14,10 +14,10 @@ jobs:
14
14
 
15
15
  steps:
16
16
  - uses: actions/checkout@v2
17
- - name: Set up Ruby 2.6
18
- uses: actions/setup-ruby@v1
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
19
  with:
20
- ruby-version: 2.6.x
20
+ ruby-version: 3.1
21
21
 
22
22
  - name: Publish to RubyGems
23
23
  run: |
@@ -19,15 +19,12 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.7', '3.0']
22
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
26
26
  - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
27
+ uses: ruby/setup-ruby@v1
31
28
  with:
32
29
  ruby-version: ${{ matrix.ruby-version }}
33
30
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
@@ -0,0 +1,70 @@
1
+ # TimeBoss Period Specifiers
2
+ Below is a list of examples for TimeBoss period specifiers. This list is by no means comprehensive, but hopefully serves as a guide to help
3
+ you understand how to communicate with TimeBoss.
4
+
5
+ All specifiers are resolved within the context of the utilized calendar (Gregorian, Broadcast, etc).
6
+
7
+ ## Absolute Periods
8
+ An "absolute" period is one that never changes, regardless of the current date. "December of 2019" always references the same time period,
9
+ regardless of what today is.
10
+
11
+ _Assuming the Broadcast calendar is in use:_
12
+ | Specifier | Description | Resolution |
13
+ | -------------------------- | ----------------------------------- | ----------------------- |
14
+ | `2020Q3` | 3rd quarter of 2020 | 6/29/2020 - 9/27/2020 |
15
+ | `2022M1` | 1st month of 2022 | 12/27/2021 - 1/30/2022 |
16
+ | `2021H1M2` | 2nd month of the first half of 2021 | 2/1/2021 - 2/28/2021 |
17
+ | `2020W40` | 40th week of 2020 | 9/28/2020 - 10/4/2020 |
18
+ | `2027` | 2027 | 12/28/2026 - 12/26/2027 |
19
+ | `1999-07-31` or `19990731` | July 31, 1999 | 7/31/1999 - 7/31/1999 |
20
+
21
+ The sub-identifiers for period granularities are:
22
+ - `D`: day
23
+ - `W`: week
24
+ - `M`: month
25
+ - `Q`: quarter
26
+ - `H`: half
27
+
28
+ ## Relative Periods
29
+ A "relative" period is one that changes based on the current date. "Last week" means something different today than it will a month from now.
30
+
31
+ _Assuming today is April 29, 2022, in the Gregorian calendar:_
32
+ | Specifier | Description | Resolution |
33
+ | --------------- | ----------------------------------- | --------------------- |
34
+ | `last_month` | March 2022 | 3/1/2022 - 3/31/2022 |
35
+ | `this_month-2` | February 2022 | 2/1/2022 - 2/28/2022 |
36
+ | `this_week` | Week of April 25, 2022 | 4/25/2022 - 5/1/2022 |
37
+ | `yesterday` | April 28, 2022 | 4/28/2022 - 4/28/2022 |
38
+ | `today+4` | May 3, 2022 | 5/3/2022 - 5/3/2022 |
39
+ | `next_year` | 2023 | 1/1/2023 - 12/31/2023 |
40
+
41
+ The relative prefixes can be used in conjuction with any period granularity. The terms here should be joined with the underscore (`_`) character as in the examples above.
42
+
43
+ Relative prefixes are:
44
+ - `last`
45
+ - `this`
46
+ - `next`
47
+
48
+ Period granularities are:
49
+ - `day`
50
+ - `week`
51
+ - `month`
52
+ - `quarter`
53
+ - `half`
54
+ - `year`
55
+
56
+ Accepted single-day specifiers:
57
+ - `yesterday`
58
+ - `today`
59
+ - `tomorrow`
60
+
61
+ ## Compound Periods
62
+ Absolute and/or relative periods can be combined together to build "compound" periods by utilizing TimeBoss' "range" operator (`..`):
63
+
64
+ _Assuming today is April 29, 2022, in the Gregorian calendar:_
65
+ | Specifier | Description | Resolution |
66
+ | -------------------------- | ------------------------------------------------------------------------ | --------------------- |
67
+ | `yesterday..today` | Yesterday and Today | 4/28/2022 - 4/29/2022 |
68
+ | `last_quarter..this_month` | From the first day of last quarter, through the end of the current month | 1/1/2022 - 4/30/2022 |
69
+ | `this_week-2..next_week` | From the first day of 2 weeks ago, through the last day of next week | 4/11/2022 - 5/8/2022 |
70
+ | `2022M2..this_year` | From the first day of February, through the last day of this year | 2/1/2022 - 12/31/2022 |
data/README.md CHANGED
@@ -25,7 +25,7 @@ $ gem install timeboss
25
25
  ```
26
26
 
27
27
  ## Usage
28
- Supports `year`, `half`, `quarter`, `month`, `week` (non-gregorian calendars only), and `day`.
28
+ Supports `year`, `half`, `quarter`, `month`, `week`, and `day`.
29
29
 
30
30
  Prepare your calendar for use:
31
31
 
@@ -1,3 +1,4 @@
1
+ require "./lib/timeboss"
1
2
  require "./lib/timeboss/calendars"
2
3
 
3
4
  namespace :timeboss do
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "./support/clampable"
4
+
3
5
  module TimeBoss
4
6
  class Calendar
5
7
  class Period
8
+ include Calendar::Support::Clampable
6
9
  attr_reader :begin, :end
7
10
 
8
11
  # @!method start_date
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimeBoss
4
+ class Calendar
5
+ module Support
6
+ module Clampable
7
+ # Clamp this unit to the range of the provided unit.
8
+ # @return [Period]
9
+ def clamp(unit)
10
+ new_start_date = start_date.clamp(unit.start_date, unit.end_date)
11
+ new_end_date = end_date.clamp(unit.start_date, unit.end_date)
12
+ return unless new_start_date.between?(start_date, end_date) && new_end_date.between?(start_date, end_date)
13
+ calendar.parse("#{new_start_date}..#{new_end_date}")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -3,6 +3,7 @@
3
3
  require_relative "./navigable"
4
4
  require_relative "./translatable"
5
5
  require_relative "./shiftable"
6
+ require_relative "./clampable"
6
7
  require_relative "./formatter"
7
8
 
8
9
  module TimeBoss
@@ -12,6 +13,7 @@ module TimeBoss
12
13
  include Navigable
13
14
  include Translatable
14
15
  include Shiftable
16
+ include Clampable
15
17
  attr_reader :calendar, :start_date, :end_date
16
18
 
17
19
  UnsupportedUnitError = Class.new(StandardError)
@@ -84,15 +86,6 @@ module TimeBoss
84
86
  @_to_range ||= start_date..end_date
85
87
  end
86
88
 
87
- # Clamp this unit to the range of the provided unit.
88
- # @return [Period]
89
- def clamp(unit)
90
- new_start_date = start_date.clamp(unit.start_date, unit.end_date)
91
- new_end_date = end_date.clamp(unit.start_date, unit.end_date)
92
- return unless new_start_date.between?(start_date, end_date) && new_end_date.between?(start_date, end_date)
93
- calendar.parse("#{new_start_date}..#{new_end_date}")
94
- end
95
-
96
89
  def inspect
97
90
  "#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>"
98
91
  end
@@ -15,6 +15,7 @@ module TimeBoss
15
15
  end
16
16
 
17
17
  define_method "#{type}_for" do |date|
18
+ date = date.to_date
18
19
  window = public_send(type, date.year - 1, 1)
19
20
  loop do
20
21
  break window if window.to_range.include?(date)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimeBoss
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.5"
5
5
  end
data/lib/timeboss.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
+ require "active_support/all"
4
5
  require "timeboss/version"
5
6
 
6
7
  # TimeBoss
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McDonald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -184,6 +184,7 @@ files:
184
184
  - CODE_OF_CONDUCT.md
185
185
  - Gemfile
186
186
  - LICENSE.txt
187
+ - PERIOD_SPECIFIERS.md
187
188
  - README.md
188
189
  - Rakefile
189
190
  - bin/tbsh
@@ -197,6 +198,7 @@ files:
197
198
  - lib/timeboss/calendar/parser.rb
198
199
  - lib/timeboss/calendar/period.rb
199
200
  - lib/timeboss/calendar/quarter.rb
201
+ - lib/timeboss/calendar/support/clampable.rb
200
202
  - lib/timeboss/calendar/support/formatter.rb
201
203
  - lib/timeboss/calendar/support/has_fiscal_weeks.rb
202
204
  - lib/timeboss/calendar/support/has_iso_weeks.rb
@@ -244,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
246
  - !ruby/object:Gem::Version
245
247
  version: '0'
246
248
  requirements: []
247
- rubygems_version: 3.0.3.1
249
+ rubygems_version: 3.3.26
248
250
  signing_key:
249
251
  specification_version: 4
250
252
  summary: Broadcast Calendar navigation in Ruby made simple