timeboss 0.0.9 → 0.0.10
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/lib/timeboss/calendar/day.rb +5 -1
- data/lib/timeboss/calendar/support/month_based.rb +1 -1
- data/lib/timeboss/calendar/week.rb +11 -16
- data/lib/timeboss/version.rb +1 -1
- data/spec/calendar/day_spec.rb +1 -1
- data/spec/calendar/support/month_based_spec.rb +11 -1
- data/spec/calendar/week_spec.rb +5 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a46b4d08fd0e17154dbb9f2f806d74e3e0dd83ad2a6dff04102dd5142a975809
|
4
|
+
data.tar.gz: e231795ad178299e99475a03f7fc589d234373ce672f525653b9e67c209d00cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4a01cd350e3df24190b5818e0cc71ea09b15e57ae73db9620e812b138b9badcb8acd8fb5fa33a35c52049e7893e37cf7a3beed40c8eebbbfddd46158d0ff72f
|
7
|
+
data.tar.gz: 493dd68afa5bd7df4b49c36881946ef869844f538a791780da86a966988be349debd9077a35cb0f834a20b5f0920088da2547cac33de1ec7618783d5f8f69b74
|
@@ -21,7 +21,11 @@ module TimeBoss
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def index
|
24
|
-
@_index ||= (start_date -
|
24
|
+
@_index ||= (start_date - year.start_date).to_i + 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def year_index
|
28
|
+
@_year_index ||= year.year_index
|
25
29
|
end
|
26
30
|
|
27
31
|
private
|
@@ -20,7 +20,7 @@ module TimeBoss
|
|
20
20
|
def weeks
|
21
21
|
base = calendar.year(year_index)
|
22
22
|
num_weeks = (((base.end_date - base.start_date) + 1) / 7.0).to_i
|
23
|
-
num_weeks.times.map { |i| Week.new(calendar,
|
23
|
+
num_weeks.times.map { |i| Week.new(calendar, base.start_date + (i * 7).days, base.start_date + ((i * 7) + 6).days) }
|
24
24
|
.select { |w| w.start_date.between?(start_date, end_date) }
|
25
25
|
end
|
26
26
|
|
@@ -4,12 +4,8 @@ require_relative './support/unit'
|
|
4
4
|
module TimeBoss
|
5
5
|
class Calendar
|
6
6
|
class Week < Support::Unit
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(calendar, year_index, index, start_date, end_date)
|
7
|
+
def initialize(calendar, start_date, end_date)
|
10
8
|
super(calendar, start_date, end_date)
|
11
|
-
@year_index = year_index
|
12
|
-
@index = index
|
13
9
|
end
|
14
10
|
|
15
11
|
def name
|
@@ -24,23 +20,22 @@ module TimeBoss
|
|
24
20
|
"#{name}: #{start_date} thru #{end_date}"
|
25
21
|
end
|
26
22
|
|
23
|
+
def index
|
24
|
+
@_index ||= (((start_date - year.start_date) + 1) / 7.0).to_i + 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def year_index
|
28
|
+
@_year_index ||= year.year_index
|
29
|
+
end
|
30
|
+
|
27
31
|
private
|
28
32
|
|
29
33
|
def down
|
30
|
-
|
31
|
-
(calendar.year_for(start_date) - 1).weeks.last
|
32
|
-
else
|
33
|
-
self.class.new(calendar, year_index, index - 1, start_date - 1.week, end_date - 1.week)
|
34
|
-
end
|
34
|
+
self.class.new(calendar, start_date - 1.week, end_date - 1.week)
|
35
35
|
end
|
36
36
|
|
37
37
|
def up
|
38
|
-
|
39
|
-
if index == weeks.last.index
|
40
|
-
self.class.new(calendar, year_index + 1, 1, start_date + 1.week, end_date + 1.week)
|
41
|
-
else
|
42
|
-
weeks[index]
|
43
|
-
end
|
38
|
+
self.class.new(calendar, start_date + 1.week, end_date + 1.week)
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
data/lib/timeboss/version.rb
CHANGED
data/spec/calendar/day_spec.rb
CHANGED
@@ -24,7 +24,7 @@ module TimeBoss
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#index' do
|
27
|
-
before(:each) { allow(
|
27
|
+
before(:each) { allow(subject).to receive(:year).and_return double(start_date: start_date - 3) }
|
28
28
|
|
29
29
|
it 'gets its index within the year' do
|
30
30
|
expect(subject.index).to eq 4
|
@@ -32,7 +32,17 @@ module TimeBoss
|
|
32
32
|
it 'can get the relevant weeks for the period' do
|
33
33
|
result = subject.weeks
|
34
34
|
result.each { |w| expect(w).to be_instance_of TimeBoss::Calendar::Week }
|
35
|
-
expect(result.map
|
35
|
+
expect(result.map { |w| w.start_date.to_s }).to eq [
|
36
|
+
'2018-06-25',
|
37
|
+
'2018-07-02',
|
38
|
+
'2018-07-09',
|
39
|
+
'2018-07-16',
|
40
|
+
'2018-07-23',
|
41
|
+
'2018-07-30',
|
42
|
+
'2018-08-06',
|
43
|
+
'2018-08-13',
|
44
|
+
'2018-08-20'
|
45
|
+
]
|
36
46
|
end
|
37
47
|
end
|
38
48
|
|
data/spec/calendar/week_spec.rb
CHANGED
@@ -4,7 +4,7 @@ module TimeBoss
|
|
4
4
|
let(:calendar) { instance_double(TimeBoss::Calendar) }
|
5
5
|
let(:start_date) { Date.parse('2048-04-06') }
|
6
6
|
let(:end_date) { Date.parse('2048-04-12') }
|
7
|
-
let(:subject) { described_class.new(calendar,
|
7
|
+
let(:subject) { described_class.new(calendar, start_date, end_date) }
|
8
8
|
|
9
9
|
it 'knows its stuff' do
|
10
10
|
expect(subject.start_date).to eq start_date
|
@@ -12,18 +12,10 @@ module TimeBoss
|
|
12
12
|
expect(subject.to_range).to eq start_date..end_date
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'knows its name' do
|
16
|
-
expect(subject.name).to eq '2048W15'
|
17
|
-
end
|
18
|
-
|
19
15
|
it 'knows its title' do
|
20
16
|
expect(subject.title).to eq "Week of April 6, 2048"
|
21
17
|
end
|
22
18
|
|
23
|
-
it 'can stringify itself' do
|
24
|
-
expect(subject.to_s).to include(subject.name, start_date.to_s, end_date.to_s)
|
25
|
-
end
|
26
|
-
|
27
19
|
describe '#current?' do
|
28
20
|
it 'knows when it is' do
|
29
21
|
allow(Date).to receive(:today).and_return start_date
|
@@ -46,13 +38,13 @@ module TimeBoss
|
|
46
38
|
end
|
47
39
|
|
48
40
|
it 'can wrap to the previous 52-week year' do
|
49
|
-
result = described_class.new(calendar,
|
41
|
+
result = described_class.new(calendar, Date.parse('2021-12-27'), Date.parse('2022-01-02')).previous
|
50
42
|
expect(result).to be_a described_class
|
51
43
|
expect(result.to_s).to eq "2021W52: 2021-12-20 thru 2021-12-26"
|
52
44
|
end
|
53
45
|
|
54
46
|
it 'can wrap to the previous 53-week year' do
|
55
|
-
result = described_class.new(calendar,
|
47
|
+
result = described_class.new(calendar, Date.parse('2024-01-01'), Date.parse('2024-01-07')).previous
|
56
48
|
expect(result).to be_a described_class
|
57
49
|
expect(result.to_s).to eq "2023W53: 2023-12-25 thru 2023-12-31"
|
58
50
|
end
|
@@ -66,13 +58,13 @@ module TimeBoss
|
|
66
58
|
end
|
67
59
|
|
68
60
|
it 'can wrap from week 52 to the next year' do
|
69
|
-
result = described_class.new(calendar,
|
61
|
+
result = described_class.new(calendar, Date.parse('2021-12-20'), Date.parse('2021-12-26')).next
|
70
62
|
expect(result).to be_a described_class
|
71
63
|
expect(result.to_s).to eq "2022W1: 2021-12-27 thru 2022-01-02"
|
72
64
|
end
|
73
65
|
|
74
66
|
it 'can wrap from week 53 to the next year' do
|
75
|
-
result = described_class.new(calendar,
|
67
|
+
result = described_class.new(calendar, Date.parse('2023-12-25'), Date.parse('2023-12-31')).next
|
76
68
|
expect(result).to be_a described_class
|
77
69
|
expect(result.to_s).to eq "2024W1: 2024-01-01 thru 2024-01-07"
|
78
70
|
end
|