timeboss 0.3.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +31 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.travis.yml +3 -2
- data/Gemfile +2 -1
- data/README.md +22 -7
- data/Rakefile +3 -1
- data/bin/tbsh +2 -2
- data/lib/tasks/calendars.rake +5 -5
- data/lib/tasks/timeboss.rake +2 -2
- data/lib/timeboss/calendar/day.rb +3 -2
- data/lib/timeboss/calendar/half.rb +2 -1
- data/lib/timeboss/calendar/month.rb +2 -1
- data/lib/timeboss/calendar/parser.rb +9 -8
- data/lib/timeboss/calendar/period.rb +13 -6
- data/lib/timeboss/calendar/quarter.rb +2 -1
- data/lib/timeboss/calendar/support/formatter.rb +5 -4
- data/lib/timeboss/calendar/support/has_fiscal_weeks.rb +17 -0
- data/lib/timeboss/calendar/support/has_iso_weeks.rb +30 -0
- data/lib/timeboss/calendar/support/month_basis.rb +1 -1
- data/lib/timeboss/calendar/support/monthly_unit.rb +8 -8
- data/lib/timeboss/calendar/support/navigable.rb +2 -1
- data/lib/timeboss/calendar/support/shiftable.rb +12 -11
- data/lib/timeboss/calendar/support/translatable.rb +3 -2
- data/lib/timeboss/calendar/support/unit.rb +24 -13
- data/lib/timeboss/calendar/waypoints/absolute.rb +4 -3
- data/lib/timeboss/calendar/waypoints/relative.rb +14 -13
- data/lib/timeboss/calendar/week.rb +3 -2
- data/lib/timeboss/calendar/year.rb +2 -1
- data/lib/timeboss/calendar.rb +8 -7
- data/lib/timeboss/calendars/broadcast.rb +10 -7
- data/lib/timeboss/calendars/gregorian.rb +4 -5
- data/lib/timeboss/calendars.rb +3 -2
- data/lib/timeboss/version.rb +2 -1
- data/lib/timeboss.rb +2 -0
- data/spec/calendar/day_spec.rb +14 -14
- data/spec/calendar/quarter_spec.rb +9 -9
- data/spec/calendar/support/monthly_unit_spec.rb +50 -44
- data/spec/calendar/support/unit_spec.rb +23 -22
- data/spec/calendar/week_spec.rb +20 -20
- data/spec/calendars/broadcast_spec.rb +310 -310
- data/spec/calendars/gregorian_spec.rb +376 -267
- data/spec/calendars_spec.rb +19 -19
- data/spec/spec_helper.rb +2 -2
- data/timeboss.gemspec +16 -14
- metadata +35 -4
- data/lib/timeboss/support/shellable.rb +0 -17
@@ -1,33 +1,34 @@
|
|
1
1
|
module TimeBoss
|
2
2
|
class Calendar
|
3
3
|
module Support
|
4
|
+
class TestChunkUnit < Unit
|
5
|
+
end
|
6
|
+
|
4
7
|
describe Unit do
|
5
|
-
|
6
|
-
end
|
7
|
-
let(:described_class) { ChunkUnit }
|
8
|
+
let(:described_class) { TestChunkUnit }
|
8
9
|
let(:calendar) { double }
|
9
|
-
let(:start_date) { Date.parse(
|
10
|
-
let(:end_date) { Date.parse(
|
10
|
+
let(:start_date) { Date.parse("2018-06-25") }
|
11
|
+
let(:end_date) { Date.parse("2018-08-26") }
|
11
12
|
let(:subject) { described_class.new(calendar, start_date, end_date) }
|
12
13
|
|
13
|
-
it
|
14
|
+
it "knows its stuff" do
|
14
15
|
expect(subject.start_date).to eq start_date
|
15
16
|
expect(subject.end_date).to eq end_date
|
16
17
|
expect(subject.to_range).to eq start_date..end_date
|
17
18
|
end
|
18
19
|
|
19
|
-
describe
|
20
|
-
it
|
20
|
+
describe "#current?" do
|
21
|
+
it "is not current right now" do
|
21
22
|
expect(subject).not_to be_current
|
22
23
|
end
|
23
24
|
|
24
|
-
it
|
25
|
+
it "is current when today falls in the middle" do
|
25
26
|
allow(Date).to receive(:today).and_return start_date + 3.days
|
26
27
|
expect(subject).to be_current
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
context
|
31
|
+
context "periods" do
|
31
32
|
before(:each) do
|
32
33
|
allow(calendar).to receive(:days_for).with(subject).and_return %w[D1 D2 D3 D4 D5 D6 D7 D8]
|
33
34
|
allow(calendar).to receive(:weeks_for).with(subject).and_return %w[W1 W2 W3 W4]
|
@@ -37,49 +38,49 @@ module TimeBoss
|
|
37
38
|
allow(calendar).to receive(:years_for).with(subject).and_return %w[Y1]
|
38
39
|
end
|
39
40
|
|
40
|
-
it
|
41
|
+
it "knows about its days" do
|
41
42
|
expect(subject.days).to eq %w[D1 D2 D3 D4 D5 D6 D7 D8]
|
42
43
|
expect(subject.day).to be nil
|
43
44
|
end
|
44
45
|
|
45
|
-
it
|
46
|
+
it "knows about its weeks" do
|
46
47
|
expect(subject.weeks).to eq %w[W1 W2 W3 W4]
|
47
48
|
expect(subject.week).to be nil
|
48
49
|
end
|
49
50
|
|
50
|
-
it
|
51
|
+
it "knows about its months" do
|
51
52
|
expect(subject.months).to eq %w[M1 M2 M3]
|
52
53
|
expect(subject.month).to be nil
|
53
54
|
end
|
54
55
|
|
55
|
-
it
|
56
|
+
it "knows about its quarters" do
|
56
57
|
expect(subject.quarters).to eq %w[Q1 Q2]
|
57
58
|
expect(subject.quarter).to be nil
|
58
59
|
end
|
59
60
|
|
60
|
-
it
|
61
|
+
it "knows about its halves" do
|
61
62
|
expect(subject.halves).to eq %w[H1]
|
62
|
-
expect(subject.half).to eq
|
63
|
+
expect(subject.half).to eq "H1"
|
63
64
|
end
|
64
65
|
|
65
|
-
it
|
66
|
+
it "knows about its years" do
|
66
67
|
expect(subject.years).to eq %w[Y1]
|
67
|
-
expect(subject.year).to eq
|
68
|
+
expect(subject.year).to eq "Y1"
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
|
-
context
|
72
|
+
context "navigation" do
|
72
73
|
let(:result) { double }
|
73
74
|
|
74
|
-
describe
|
75
|
+
describe "#offset" do
|
75
76
|
end
|
76
77
|
|
77
|
-
it
|
78
|
+
it "can increment" do
|
78
79
|
expect(subject).to receive(:offset).with(7).and_return result
|
79
80
|
expect(subject + 7).to eq result
|
80
81
|
end
|
81
82
|
|
82
|
-
it
|
83
|
+
it "can decrement" do
|
83
84
|
expect(subject).to receive(:offset).with(-23).and_return result
|
84
85
|
expect(subject - 23).to eq result
|
85
86
|
end
|
data/spec/calendar/week_spec.rb
CHANGED
@@ -2,8 +2,8 @@ module TimeBoss
|
|
2
2
|
class Calendar
|
3
3
|
describe Week do
|
4
4
|
let(:calendar) { instance_double(TimeBoss::Calendar, supports_weeks?: true) }
|
5
|
-
let(:start_date) { Date.parse(
|
6
|
-
let(:end_date) { Date.parse(
|
5
|
+
let(:start_date) { Date.parse("2048-04-06") }
|
6
|
+
let(:end_date) { Date.parse("2048-04-12") }
|
7
7
|
let(:subject) { described_class.new(calendar, start_date, end_date) }
|
8
8
|
|
9
9
|
it "doesn't even exist if its calendar doesn't support weeks" do
|
@@ -11,65 +11,65 @@ module TimeBoss
|
|
11
11
|
expect { subject }.to raise_error TimeBoss::Calendar::Support::Unit::UnsupportedUnitError
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it "knows its stuff" do
|
15
15
|
expect(subject.start_date).to eq start_date
|
16
16
|
expect(subject.end_date).to eq end_date
|
17
17
|
expect(subject.to_range).to eq start_date..end_date
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "knows its title" do
|
21
21
|
expect(subject.title).to eq "Week of April 6, 2048"
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
25
|
-
it
|
24
|
+
describe "#current?" do
|
25
|
+
it "knows when it is" do
|
26
26
|
allow(Date).to receive(:today).and_return start_date
|
27
27
|
expect(subject).to be_current
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "knows when it is not" do
|
31
31
|
expect(subject).not_to be_current
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context
|
35
|
+
context "navigation" do
|
36
36
|
let(:calendar) { TimeBoss::Calendars::Broadcast.new }
|
37
37
|
|
38
|
-
describe
|
39
|
-
it
|
38
|
+
describe "#previous" do
|
39
|
+
it "can back up simply" do
|
40
40
|
result = subject.previous
|
41
41
|
expect(result).to be_a described_class
|
42
42
|
expect(result.to_s).to eq "2048W14: 2048-03-30 thru 2048-04-05"
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
result = described_class.new(calendar, Date.parse(
|
45
|
+
it "can wrap to the previous 52-week year" do
|
46
|
+
result = described_class.new(calendar, Date.parse("2021-12-27"), Date.parse("2022-01-02")).previous
|
47
47
|
expect(result).to be_a described_class
|
48
48
|
expect(result.to_s).to eq "2021W52: 2021-12-20 thru 2021-12-26"
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
52
|
-
result = described_class.new(calendar, Date.parse(
|
51
|
+
it "can wrap to the previous 53-week year" do
|
52
|
+
result = described_class.new(calendar, Date.parse("2024-01-01"), Date.parse("2024-01-07")).previous
|
53
53
|
expect(result).to be_a described_class
|
54
54
|
expect(result.to_s).to eq "2023W53: 2023-12-25 thru 2023-12-31"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe
|
59
|
-
it
|
58
|
+
describe "#next" do
|
59
|
+
it "can move forward simply" do
|
60
60
|
result = subject.next
|
61
61
|
expect(result).to be_a described_class
|
62
62
|
expect(result.to_s).to eq "2048W16: 2048-04-13 thru 2048-04-19"
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
result = described_class.new(calendar, Date.parse(
|
65
|
+
it "can wrap from week 52 to the next year" do
|
66
|
+
result = described_class.new(calendar, Date.parse("2021-12-20"), Date.parse("2021-12-26")).next
|
67
67
|
expect(result).to be_a described_class
|
68
68
|
expect(result.to_s).to eq "2022W1: 2021-12-27 thru 2022-01-02"
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
result = described_class.new(calendar, Date.parse(
|
71
|
+
it "can wrap from week 53 to the next year" do
|
72
|
+
result = described_class.new(calendar, Date.parse("2023-12-25"), Date.parse("2023-12-31")).next
|
73
73
|
expect(result).to be_a described_class
|
74
74
|
expect(result.to_s).to eq "2024W1: 2024-01-01 thru 2024-01-07"
|
75
75
|
end
|