trading_day_jp 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: 9205b753b14e42d931a01a8d90b46c9cd695e254
4
- data.tar.gz: 94fa5f305d24b40632138dab2e3d51b859d4cadf
3
+ metadata.gz: e315bfe807f4ff907de1ba0d03da3a51f3290d55
4
+ data.tar.gz: 7cd6adc0580c37f497966de34407c1603264f750
5
5
  SHA512:
6
- metadata.gz: 84d895e9523bf4112b9af8d6163375b25567a65e01017c4135ed2f82a33703e8268d31c9f6209f316dd64217b229108d9fdf868ac997469de6ee208e8d561d63
7
- data.tar.gz: d2d49ab97d15ab8a3a10ced316fddc703a393cb73fbc3584dcbb89a0019e6a141450510722eb05d7890c8772fc2c823f1fd8228e07ffd578510ea7b140252794
6
+ metadata.gz: a979fdd2f7fe3835023b88b62901da8672cd054fc92af7586e11841e88b3f499b4d853619473429ee14f8b8e9c6d23df28133b9d8c4aafa06faa7797816edd45
7
+ data.tar.gz: 257734a3cbbbdfe7ca6cebc639175f596ebbabdee7f308c8203e5927682caad65e800035e6d2db3e651a03756576e48ea1b8dd98bbe354471ee57992188cc7eb
@@ -1,3 +1,3 @@
1
1
  module TradingDayJp
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -3,6 +3,8 @@ require "trading_day_jp/date"
3
3
  module TradingDayJp
4
4
 
5
5
  class << self
6
+ @@day_minus = [nil, 0, 1, 2, 3, 4, 5, 6]
7
+ @@day_add = [nil, 0, 4, 3, 2, 1, 0, -1, -2]
6
8
 
7
9
  def open?(date)
8
10
  date.trading_day_jp?
@@ -30,6 +32,38 @@ module TradingDayJp
30
32
  end
31
33
  end
32
34
 
35
+ def beginning_of_week(date)
36
+ date = date - @@day_minus[date.cwday]
37
+ cweek = date.cweek
38
+
39
+ loop do
40
+ if date.trading_day_jp?
41
+ return date
42
+ elsif date.cweek != cweek
43
+ return
44
+ end
45
+
46
+ cweek = date.cweek
47
+ date = date + 1
48
+ end
49
+ end
50
+
51
+ def end_of_week(date)
52
+ date = date + @@day_add[date.cwday]
53
+ cweek = date.cweek
54
+
55
+ loop do
56
+ if date.trading_day_jp?
57
+ return date
58
+ elsif date.cweek != cweek
59
+ return
60
+ end
61
+
62
+ cweek = date.cweek
63
+ date = date - 1
64
+ end
65
+ end
66
+
33
67
  def beginning_of_month(date)
34
68
  date = Date.new(date.year, date.month)
35
69
 
@@ -49,6 +49,56 @@ describe TradingDayJp do
49
49
  end
50
50
  end
51
51
 
52
+ describe '.beginning_of_week' do
53
+ it 'その週の最初の取引日を取得する' do
54
+ date = Date.new 2015, 5, 8
55
+
56
+ expect(TradingDayJp.beginning_of_week date).to eq Date.new(2015, 5, 7)
57
+ end
58
+
59
+ context '月曜' do
60
+ let(:date) { Date.new 2014, 2, 3 }
61
+
62
+ it { expect(TradingDayJp.beginning_of_week date).to eq date }
63
+ end
64
+
65
+ context 'その週は取引日がない' do
66
+ it 'returns nil' do
67
+ allow_any_instance_of(Date).to receive(:trading_day_jp?) { false }
68
+
69
+ date = Date.new 2014, 2, 3
70
+
71
+ expect(TradingDayJp.beginning_of_week date).to be_nil
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '.end_of_week' do
77
+ it 'その週の最後の取引日を取得する' do
78
+ date = Date.new 2014, 3, 19
79
+
80
+ expect(TradingDayJp.end_of_week date).to eq Date.new(2014, 3, 20)
81
+ end
82
+
83
+ context '日曜' do
84
+ it do
85
+ date = Date.new 2014, 2, 23
86
+
87
+ expect(TradingDayJp.end_of_week date).to eq Date.new(2014, 2, 21)
88
+ end
89
+ end
90
+
91
+ context 'その週は取引日がない' do
92
+ it 'returns nil' do
93
+ allow_any_instance_of(Date).to receive(:trading_day_jp?) { false }
94
+
95
+ date = Date.new 2014, 2, 3
96
+
97
+ expect(TradingDayJp.end_of_week date).to be_nil
98
+ end
99
+ end
100
+ end
101
+
52
102
  describe '.beginning_of_month' do
53
103
  it 'その月の最初の取引日を取得する' do
54
104
  date = Date.new 2014, 6, 10
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trading_day_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takehiko Shinkura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,3 +100,4 @@ test_files:
100
100
  - spec/spec_helper.rb
101
101
  - spec/trading_day_jp/date_spec.rb
102
102
  - spec/trading_day_jp_spec.rb
103
+ has_rdoc: