nasdaq_schedule 1.0.0
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +8 -0
- data/lib/nasdaq_schedule.rb +132 -0
- data/lib/nasdaq_schedule/errors.rb +9 -0
- data/lib/nasdaq_schedule/stock_market.rb +17 -0
- data/lib/nasdaq_schedule/version.rb +3 -0
- data/nasdaq_schedule.gemspec +26 -0
- data/spec/nasdaq_schedule_spec.rb +169 -0
- data/spec/spec_helper.rb +1 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0bdfb269b97ff7aeef6a09d74c4fb0266e63d3e
|
4
|
+
data.tar.gz: 4ff3b90ea2dcca6cae383aaffac2ec268012e2a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8f7c9d486a8b5fd396a68c7a47e1664a371d480253d68d80e37b6ff7b5ccc6583816aa1e2a9f2df6b26efc0af506fc308e6afd199f46bf0fc4dcbb4dc8e70f3
|
7
|
+
data.tar.gz: 8c0ce356cbabb2c8e8d183feb958f3153153a09a90f846769ce73b6665efca2ad1b56573fd32dc46da81e01518fb69ff40ca689b59a075c9ab962d69f1f66848
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kamil Leczycki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# NasdaqSchedule
|
2
|
+
|
3
|
+
ActiveSupport::TimeWithZone extension. Provides a set of set instance methods which return specific time informations according to Nasdaq working schedule and market hours. Nasdaq schedule can be found here http://www.nasdaq.com/about/trading-schedule.aspx . The market timezone is EST/EDT.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nasdaq_schedule'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nasdaq_schedule
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
```ruby
|
21
|
+
date = Time.zone.now => Tue, 09 Dec 2014 14:01:10 PST -08:00
|
22
|
+
|
23
|
+
# 'in_nasdaq_time_zone' returns time in Nasdaq time zone.
|
24
|
+
date.in_nasdaq_time_zone
|
25
|
+
=> Tue, 09 Dec 2014 17:01:10 EST -05:00
|
26
|
+
|
27
|
+
# 'nasdaq_holiday?' returns true if the given date is a Nasdaq holiday,
|
28
|
+
otherwise false.
|
29
|
+
date.nasdaq_holiday?
|
30
|
+
=> false
|
31
|
+
|
32
|
+
# 'nasdaq_working_day?' returns true if the given date is Nasdaq working day, otherwise false.
|
33
|
+
date.nasdaq_working_day?
|
34
|
+
=> true
|
35
|
+
|
36
|
+
# 'nasdaq_open' returns Nasdaq open time in given timezone.
|
37
|
+
date.nasdaq_open
|
38
|
+
=> Tue, 09 Dec 2014 06:30:00 PST -08:00
|
39
|
+
|
40
|
+
# 'nasdaq_close' returns Nasdaq close time in given timezone.
|
41
|
+
date.nasdaq_close
|
42
|
+
=> Tue, 09 Dec 2014 13:00:00 PST -08:00
|
43
|
+
|
44
|
+
# Both will raise NasdaqSchedule::Errors::NotWorkingDay when used on weekends or holidays.
|
45
|
+
|
46
|
+
# 'nasdaq_previous_day' returns previous working day for Nasdaq.
|
47
|
+
date.nasdaq_previous_day
|
48
|
+
=> Mon, 08 Dec 2014 14:01:10 PST -08:00
|
49
|
+
|
50
|
+
# 'nasdaq_next_day' returns next working day for Nasdaq.
|
51
|
+
date.nasdaq_next_day
|
52
|
+
=> Wed, 10 Dec 2014 14:01:10 PST -08:00
|
53
|
+
|
54
|
+
# 'nasdaq_closest_open' returns open time of closest working day.
|
55
|
+
(date + 4.days)
|
56
|
+
=> Sat, 13 Dec 2014 14:01:10 PST -08:00
|
57
|
+
|
58
|
+
(date + 4.days).nasdaq_closest_open
|
59
|
+
=> Mon, 15 Dec 2014 06:30:00 PST -08:00
|
60
|
+
|
61
|
+
# 'nasdaq_closest_close' returns close time of closest working day.
|
62
|
+
(date + 4.days).nasdaq_closest_close
|
63
|
+
=> Mon, 15 Dec 2014 13:00:00 PST -08:00
|
64
|
+
```
|
65
|
+
|
66
|
+
## Running specs
|
67
|
+
- Clone the repo
|
68
|
+
- run `bundle exec rake spec`
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( http://github.com/camol/nasdaq_schedule/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require "nasdaq_schedule/version"
|
2
|
+
require "nasdaq_schedule/stock_market"
|
3
|
+
require "nasdaq_schedule/errors"
|
4
|
+
require 'active_support/all'
|
5
|
+
require "holidays"
|
6
|
+
|
7
|
+
module NasdaqSchedule
|
8
|
+
def in_nasdaq_time_zone
|
9
|
+
same_zone? ? self : self.in_time_zone(market_zone)
|
10
|
+
end
|
11
|
+
|
12
|
+
def nasdaq_holiday?
|
13
|
+
!nasdaq_holiday.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def nasdaq_working_day?
|
17
|
+
market_time.send(:weekday?) &&
|
18
|
+
!market_time.nasdaq_holiday? &&
|
19
|
+
!(market_time.monday? && market_time.yesterday.nasdaq_holiday?) &&
|
20
|
+
!(market_time.friday? && market_time.tomorrow.nasdaq_holiday? && !market_time.send(:nasdaq_end_of_accounting_period_on_friday?))
|
21
|
+
end
|
22
|
+
|
23
|
+
def nasdaq_open
|
24
|
+
nasdaq_working_hours[:open]
|
25
|
+
end
|
26
|
+
|
27
|
+
def nasdaq_close
|
28
|
+
nasdaq_working_hours[:close]
|
29
|
+
end
|
30
|
+
|
31
|
+
def nasdaq_previous_day
|
32
|
+
nasdaq_day(:yesterday)
|
33
|
+
end
|
34
|
+
|
35
|
+
def nasdaq_next_day
|
36
|
+
nasdaq_day(:tomorrow)
|
37
|
+
end
|
38
|
+
|
39
|
+
def nasdaq_closest_open
|
40
|
+
nasdaq_closest_working_hours[:open]
|
41
|
+
end
|
42
|
+
|
43
|
+
def nasdaq_closest_close
|
44
|
+
nasdaq_closest_working_hours[:close]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
attr_reader :market_zone
|
49
|
+
|
50
|
+
def nasdaq_day(corresponding_day)
|
51
|
+
date = market_time.send(corresponding_day)
|
52
|
+
until date.nasdaq_working_day?
|
53
|
+
date = date.send(corresponding_day)
|
54
|
+
end
|
55
|
+
date.in_time_zone(original_zone)
|
56
|
+
end
|
57
|
+
|
58
|
+
def nasdaq_working_hours
|
59
|
+
must_be_working_day
|
60
|
+
{
|
61
|
+
open: market_time.change(hour: 9, min: 30).in_time_zone(original_zone),
|
62
|
+
close: market_time.change(hour: 16 + close_hours, min: 0).in_time_zone(original_zone)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def nasdaq_closest_working_hours
|
67
|
+
(nasdaq_working_day? ? self : nasdaq_next_day).send(:nasdaq_working_hours)
|
68
|
+
end
|
69
|
+
|
70
|
+
def nasdaq_holiday
|
71
|
+
holiday_hash = to_date.holidays(:us, :informal).first || {}
|
72
|
+
NasdaqSchedule::StockMarket::HOLIDAYS[holiday_hash[:name]]
|
73
|
+
end
|
74
|
+
|
75
|
+
def market_zone
|
76
|
+
@market_zone ||= NasdaqSchedule::StockMarket::ZONE
|
77
|
+
end
|
78
|
+
|
79
|
+
def market_time
|
80
|
+
in_nasdaq_time_zone
|
81
|
+
end
|
82
|
+
|
83
|
+
def same_zone?
|
84
|
+
send(:zone).to_s == self.in_time_zone(market_zone).zone.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
def weekday?
|
88
|
+
(1..5).include?(market_time.wday)
|
89
|
+
end
|
90
|
+
|
91
|
+
def nasdaq_end_of_accounting_period_on_friday?
|
92
|
+
quarter_months = [3, 6, 9, 12]
|
93
|
+
if market_time.friday? && quarter_months.include?(market_time.month)
|
94
|
+
last_month_days = []
|
95
|
+
3.times{ |i| last_month_days << market_time.end_of_month.day - i}
|
96
|
+
return true if last_month_days.include?(market_time.day)
|
97
|
+
end
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
def close_hours
|
102
|
+
close_hours = if market_time.nasdaq_working_day?
|
103
|
+
if previous_day = market_time.yesterday.send(:nasdaq_holiday)
|
104
|
+
if !market_time.monday? && previous_day[:day].to_i > 0
|
105
|
+
previous_day[:close_hours]
|
106
|
+
end
|
107
|
+
elsif next_day = market_time.tomorrow.send(:nasdaq_holiday)
|
108
|
+
if !market_time.friday? && next_day[:day].to_i < 0
|
109
|
+
next_day[:close_hours]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
close_hours.to_i
|
114
|
+
end
|
115
|
+
|
116
|
+
def must_be_working_day
|
117
|
+
raise NasdaqSchedule::Errors::NotWorkingDay unless market_time.nasdaq_working_day?
|
118
|
+
end
|
119
|
+
|
120
|
+
def original_zone
|
121
|
+
abbreviation_to_zones_mappings[zone]
|
122
|
+
end
|
123
|
+
|
124
|
+
# This method is used only to properly handle conversation back to original time zone.
|
125
|
+
# This needs to be an instance method in order to properly handle day light savings and return
|
126
|
+
# the date in the original time zone.
|
127
|
+
def abbreviation_to_zones_mappings
|
128
|
+
Hash[ActiveSupport::TimeZone.all.map{ |z| [self.in_time_zone(z).strftime('%Z'), z.name] }]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
ActiveSupport::TimeWithZone.send :include, NasdaqSchedule
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NasdaqSchedule
|
2
|
+
module StockMarket
|
3
|
+
ZONE = "Eastern Time (US & Canada)"
|
4
|
+
|
5
|
+
HOLIDAYS = {
|
6
|
+
"New Year's Day" => {},
|
7
|
+
"Martin Luther King, Jr. Day" => {},
|
8
|
+
"Presidents' Day" => {},
|
9
|
+
"Good Friday" => {},
|
10
|
+
"Memorial Day" => {},
|
11
|
+
"Independence Day" => { day: -1, close_hours: -3 },
|
12
|
+
"Labor Day" => {},
|
13
|
+
"Thanksgiving" => { day: 1, close_hours: -3 },
|
14
|
+
"Christmas Day" => { day: -1, close_hours: -3 }
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nasdaq_schedule/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nasdaq_schedule"
|
8
|
+
spec.version = NasdaqSchedule::VERSION
|
9
|
+
spec.authors = ["Kamil Leczycki"]
|
10
|
+
spec.email = ["camol88@gmail.com"]
|
11
|
+
spec.summary = %q{Provide informations about NASDAQ trading schedule.}
|
12
|
+
spec.description = %q{Ruby gem extension for ActiveSupport::TimeWithZone. Responsible for giving detailed informations about NASDAQ stock market trading schedule.}
|
13
|
+
spec.homepage = "https://github.com/camol/nasdaq_schedule"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "activesupport"
|
24
|
+
spec.add_development_dependency "holidays"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe NasdaqSchedule do
|
5
|
+
let(:test_zone) { "Pacific Time (US & Canada)" }
|
6
|
+
let(:market_zone) { NasdaqSchedule::StockMarket::ZONE }
|
7
|
+
let(:workweek_day) { Time.zone.parse("13/08/2014 10:00") }
|
8
|
+
let(:weekend) { [Time.zone.parse("16/08/2014 10:00"), Time.zone.parse("17/08/2014 10:00")] }
|
9
|
+
let(:holidays) do
|
10
|
+
Hash[(workweek_day.beginning_of_year.to_date..workweek_day.end_of_year.to_date).map do |d|
|
11
|
+
holiday = d.holidays(:us, :informal).first
|
12
|
+
if holiday.present? && NasdaqSchedule::StockMarket::HOLIDAYS.keys.include?(holiday[:name])
|
13
|
+
[holiday[:name], holiday[:date].in_time_zone(test_zone)]
|
14
|
+
end
|
15
|
+
end.compact]
|
16
|
+
end
|
17
|
+
let(:independance_day) { holidays["Independence Day"] }
|
18
|
+
let(:christmas_day) { holidays["Christmas Day"] }
|
19
|
+
let(:thanksgiving) { holidays["Thanksgiving"] }
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
Time.zone = test_zone
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#in_nasdaq_time_zone' do
|
26
|
+
context "workweek day" do
|
27
|
+
it "returns time in market time zone" do
|
28
|
+
expect(workweek_day.in_nasdaq_time_zone.zone).to eql workweek_day.in_time_zone(market_zone).zone
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns self if same time zone" do
|
32
|
+
market_week_day = workweek_day.in_time_zone(market_zone)
|
33
|
+
expect(market_week_day.in_nasdaq_time_zone).to be market_week_day
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#nasdaq_holiday?' do
|
39
|
+
context "workweek day" do
|
40
|
+
it { expect(workweek_day.nasdaq_holiday?).to be_falsey }
|
41
|
+
end
|
42
|
+
context "weekend" do
|
43
|
+
it { expect(weekend.map(&:nasdaq_holiday?)).to all(be_falsey) }
|
44
|
+
end
|
45
|
+
context "holidays" do
|
46
|
+
it { expect(holidays.values.map(&:nasdaq_holiday?)).to all(be_truthy) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#nasdaq_working_day?" do
|
51
|
+
context "workweek day" do
|
52
|
+
it { expect(workweek_day.nasdaq_working_day?).to be_truthy }
|
53
|
+
end
|
54
|
+
context "weekend" do
|
55
|
+
it { expect(weekend.map(&:nasdaq_working_day?)).to all(be_falsey) }
|
56
|
+
end
|
57
|
+
context "holidays" do
|
58
|
+
it { expect(holidays.values.map(&:nasdaq_working_day?)).to all(be_falsey) }
|
59
|
+
end
|
60
|
+
context "holidays on weekend" do
|
61
|
+
# Independence Day
|
62
|
+
it "returns false for monday if holiday was on sunday" do
|
63
|
+
expect(workweek_day.change(day: 5, month: 7, year: 2010).nasdaq_working_day?).to be_falsey
|
64
|
+
end
|
65
|
+
it "returns false for friday if holiday was on sunday" do
|
66
|
+
expect(workweek_day.change(day: 3, month: 7, year: 2009).nasdaq_working_day?).to be_falsey
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#nasdaq_open' do
|
72
|
+
context "workweek day" do
|
73
|
+
it "returns time object with market open hour" do
|
74
|
+
expect(workweek_day.nasdaq_open).to eql workweek_day.change(hour: 6, min: 30)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context "weekend and holidays" do
|
78
|
+
it "raises NasdaqSchedule::Errors::NotWorkingDay" do
|
79
|
+
(weekend + holidays.values).each{ |d| expect{ d.nasdaq_open }.to raise_error(NasdaqSchedule::Errors::NotWorkingDay) }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#nasdaq_close' do
|
85
|
+
context "workweek day" do
|
86
|
+
it "returns time object with market open hour" do
|
87
|
+
expect(workweek_day.nasdaq_close).to eql workweek_day.change(hour: 13, min: 0)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context "weekend and holidays" do
|
91
|
+
it "raises NasdaqSchedule::Errors::NotWorkingDay" do
|
92
|
+
(weekend + holidays.values).each{ |d| expect{ d.nasdaq_close }.to raise_error(NasdaqSchedule::Errors::NotWorkingDay) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
context "around some holidays returns 3 hours earlier closing time for" do
|
96
|
+
it "day before Independence Day" do
|
97
|
+
before_independance_day = independance_day - 1.day
|
98
|
+
expect(before_independance_day.nasdaq_close).to eql before_independance_day.change(hour: 10, min: 0)
|
99
|
+
end
|
100
|
+
it "day before Christmas Day" do
|
101
|
+
before_christmas_day = christmas_day - 1.day
|
102
|
+
expect(before_christmas_day.nasdaq_close).to eql before_christmas_day.change(hour: 10, min: 0)
|
103
|
+
end
|
104
|
+
it "day after Thanksgiving" do
|
105
|
+
after_thanksgiving = thanksgiving + 1.day
|
106
|
+
expect(after_thanksgiving.nasdaq_close).to eql after_thanksgiving.change(hour: 10, min: 0)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#nasdaq_previous_day" do
|
112
|
+
context "workweek day" do
|
113
|
+
it "returns tuesday for wednesday" do
|
114
|
+
expect(workweek_day.nasdaq_previous_day.tuesday?).to be_truthy
|
115
|
+
end
|
116
|
+
it "returns friday for monday" do
|
117
|
+
expect((workweek_day - 3.days).nasdaq_previous_day.friday?).to be_truthy
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#nasdaq_next_day" do
|
123
|
+
context "workweek day" do
|
124
|
+
it "returns thursday for wednesday" do
|
125
|
+
expect(workweek_day.nasdaq_next_day.thursday?).to be_truthy
|
126
|
+
end
|
127
|
+
it "returns monday for friday" do
|
128
|
+
expect((workweek_day + 3.days).nasdaq_next_day.monday?).to be_truthy
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#nasdaq_closest_open" do
|
134
|
+
context "workweek day" do
|
135
|
+
it "returns same day with open time in zone" do
|
136
|
+
expect(workweek_day.nasdaq_closest_open).to eql workweek_day.change(hour: 6, min: 30)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
context "weekend" do
|
140
|
+
it "returns monday with open in time zone" do
|
141
|
+
weekend.each{ |w| expect(w.nasdaq_closest_open).to eql Time.zone.parse("18/08/2014 6:30") }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#nasdaq_closest_close" do
|
147
|
+
context "workweek day" do
|
148
|
+
it "returns same day with open time in zone" do
|
149
|
+
expect(workweek_day.nasdaq_closest_close).to eql workweek_day.change(hour: 13, min: 00)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
context "weekend" do
|
153
|
+
it "returns monday with open in time zone" do
|
154
|
+
weekend.each{ |w| expect(w.nasdaq_closest_close).to eql Time.zone.parse("18/08/2014 13:00") }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
context "holidays" do
|
158
|
+
it "Independence Day" do
|
159
|
+
expect(independance_day.nasdaq_closest_close).to eql (independance_day + 3.days).change(hour: 13, min: 0)
|
160
|
+
end
|
161
|
+
it "Christmas Day" do
|
162
|
+
expect(christmas_day.nasdaq_closest_close).to eql (christmas_day + 1.day).change(hour: 13, min: 0)
|
163
|
+
end
|
164
|
+
it "day after Thanksgiving" do
|
165
|
+
expect(thanksgiving.nasdaq_closest_close).to eql (thanksgiving + 1.day).change(hour: 10, min: 0)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'nasdaq_schedule'
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nasdaq_schedule
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kamil Leczycki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: holidays
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby gem extension for ActiveSupport::TimeWithZone. Responsible for giving
|
84
|
+
detailed informations about NASDAQ stock market trading schedule.
|
85
|
+
email:
|
86
|
+
- camol88@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/nasdaq_schedule.rb
|
99
|
+
- lib/nasdaq_schedule/errors.rb
|
100
|
+
- lib/nasdaq_schedule/stock_market.rb
|
101
|
+
- lib/nasdaq_schedule/version.rb
|
102
|
+
- nasdaq_schedule.gemspec
|
103
|
+
- spec/nasdaq_schedule_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/camol/nasdaq_schedule
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Provide informations about NASDAQ trading schedule.
|
129
|
+
test_files:
|
130
|
+
- spec/nasdaq_schedule_spec.rb
|
131
|
+
- spec/spec_helper.rb
|