timeboss 1.1.2 → 1.1.4
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 +4 -4
- data/PERIOD_SPECIFIERS.md +70 -0
- data/README.md +1 -1
- data/lib/tasks/calendars.rake +1 -0
- data/lib/timeboss/calendar/support/unit.rb +9 -0
- data/lib/timeboss/calendar/waypoints/absolute.rb +1 -0
- data/lib/timeboss/version.rb +1 -1
- data/lib/timeboss.rb +1 -0
- data/spec/lib/timeboss/calendar/support/unit_spec.rb +51 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c22a99ae9b02ecc3f435e99622a075c0a26af2d15f87070aefb1e6c0deb1c4
|
4
|
+
data.tar.gz: 774b9250575112756f30f9522bd98b36ed017a010cace574407a88b4f3316f98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 949de3a932fe24a8c34e8bf9ba89eed605ff6f8148ab5763600a6fb6ec00b822cfc2425b4aebce6982ecc62be43fb037723a264a6543539e626755dc39f1ec04
|
7
|
+
data.tar.gz: ac0312302c3e89d193bf16354ccf3593e3bed79e6e569b1580d78f82ad40bf663765f950078c86572d3e245f265047b947dbe70c1948b82bb958b205a73542af
|
@@ -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
data/lib/tasks/calendars.rake
CHANGED
@@ -84,6 +84,15 @@ module TimeBoss
|
|
84
84
|
@_to_range ||= start_date..end_date
|
85
85
|
end
|
86
86
|
|
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
|
+
|
87
96
|
def inspect
|
88
97
|
"#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>"
|
89
98
|
end
|
data/lib/timeboss/version.rb
CHANGED
data/lib/timeboss.rb
CHANGED
@@ -28,6 +28,57 @@ module TimeBoss
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe "#clamp" do
|
32
|
+
let(:clamp_start_date) { Date.parse("2018-06-21") }
|
33
|
+
let(:clamp_end_date) { Date.parse("2018-08-30") }
|
34
|
+
let(:result) { subject.clamp(described_class.new(calendar, clamp_start_date, clamp_end_date)) }
|
35
|
+
let(:period) { double }
|
36
|
+
|
37
|
+
context "open" do
|
38
|
+
it "does not restrict the returned period" do
|
39
|
+
expect(calendar).to receive(:parse).with("#{start_date}..#{end_date}").and_return period
|
40
|
+
expect(result).to eq period
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "left clamped" do
|
45
|
+
let(:clamp_start_date) { Date.parse("2018-06-30") }
|
46
|
+
|
47
|
+
it "brings the beginning date inward" do
|
48
|
+
expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{end_date}").and_return period
|
49
|
+
expect(result).to eq period
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "right clamped" do
|
54
|
+
let(:clamp_end_date) { Date.parse("2018-07-30") }
|
55
|
+
|
56
|
+
it "brings the beginning date inward" do
|
57
|
+
expect(calendar).to receive(:parse).with("#{start_date}..#{clamp_end_date}").and_return period
|
58
|
+
expect(result).to eq period
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "fully clamped" do
|
63
|
+
let(:clamp_start_date) { Date.parse("2018-06-30") }
|
64
|
+
let(:clamp_end_date) { Date.parse("2018-07-30") }
|
65
|
+
|
66
|
+
it "brings the beginning date inward" do
|
67
|
+
expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{clamp_end_date}").and_return period
|
68
|
+
expect(result).to eq period
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "obliterated" do
|
73
|
+
let(:clamp_start_date) { Date.parse("2018-09-01") }
|
74
|
+
let(:clamp_end_date) { Date.parse("2018-09-06") }
|
75
|
+
|
76
|
+
it "returns nil" do
|
77
|
+
expect(result).to be_nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
31
82
|
context "periods" do
|
32
83
|
before(:each) do
|
33
84
|
allow(calendar).to receive(:days_for).with(subject).and_return %w[D1 D2 D3 D4 D5 D6 D7 D8]
|
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.
|
4
|
+
version: 1.1.4
|
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-
|
11
|
+
date: 2022-10-13 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
|