timeboss 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e8eba82ecc236c031a9cd96befc6c3a7454dea1720653426af4db4df227a74
4
- data.tar.gz: f13fecfd700ffadc07d665addf4d9e7905f042452ede028ab9aa5b517b31bff8
3
+ metadata.gz: a46b4d08fd0e17154dbb9f2f806d74e3e0dd83ad2a6dff04102dd5142a975809
4
+ data.tar.gz: e231795ad178299e99475a03f7fc589d234373ce672f525653b9e67c209d00cc
5
5
  SHA512:
6
- metadata.gz: 860b8b74668c08a9ec37b37ae5c450babc26f0b130342081b40a94eec468af374618f369791a8ebeb31245ddd7e94b7c4a162e505a8924f12c2a9651e5dad1c2
7
- data.tar.gz: be224a555d90519241d32b8e2232fe357b7feca228cdd789a011d6ea76ef388bfee1528adcafeefb9a19058c0aab276ca5576b41192e844a439f730f76705af8
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 - calendar.year_for(start_date).start_date).to_i + 1
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, year_index, i + 1, base.start_date + (i * 7).days, base.start_date + ((i * 7) + 6).days) }
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
- attr_reader :year_index, :index
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
- if index == 1
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
- weeks = calendar.year_for(start_date).weeks
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TimeBoss
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
@@ -24,7 +24,7 @@ module TimeBoss
24
24
  end
25
25
 
26
26
  describe '#index' do
27
- before(:each) { allow(calendar).to receive(:year_for).with(start_date).and_return double(start_date: start_date - 3) }
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(&:name)).to eq %w[2018W26 2018W27 2018W28 2018W29 2018W30 2018W31 2018W32 2018W33 2018W34]
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
 
@@ -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, 2048, 15, start_date, end_date) }
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, 2022, 1, Date.parse('2021-12-27'), Date.parse('2022-01-02')).previous
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, 2024, 1, Date.parse('2024-01-01'), Date.parse('2024-01-07')).previous
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, 2021, 52, Date.parse('2021-12-20'), Date.parse('2021-12-26')).next
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, 2023, 53, Date.parse('2023-12-25'), Date.parse('2023-12-31')).next
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McDonald