module NasdaqSchedule
Constants
- VERSION
Attributes
market_zone[R]
Public Instance Methods
in_nasdaq_time_zone()
click to toggle source
# File lib/nasdaq_schedule.rb, line 8 def in_nasdaq_time_zone same_zone? ? self : self.in_time_zone(market_zone) end
nasdaq_close()
click to toggle source
# File lib/nasdaq_schedule.rb, line 27 def nasdaq_close nasdaq_working_hours[:close] end
nasdaq_closest_close()
click to toggle source
# File lib/nasdaq_schedule.rb, line 43 def nasdaq_closest_close nasdaq_closest_working_hours[:close] end
nasdaq_closest_open()
click to toggle source
# File lib/nasdaq_schedule.rb, line 39 def nasdaq_closest_open nasdaq_closest_working_hours[:open] end
nasdaq_holiday?()
click to toggle source
# File lib/nasdaq_schedule.rb, line 12 def nasdaq_holiday? !nasdaq_holiday.nil? end
nasdaq_next_day()
click to toggle source
# File lib/nasdaq_schedule.rb, line 35 def nasdaq_next_day nasdaq_day(:tomorrow) end
nasdaq_open()
click to toggle source
# File lib/nasdaq_schedule.rb, line 23 def nasdaq_open nasdaq_working_hours[:open] end
nasdaq_previous_day()
click to toggle source
# File lib/nasdaq_schedule.rb, line 31 def nasdaq_previous_day nasdaq_day(:yesterday) end
nasdaq_working_day?()
click to toggle source
# File lib/nasdaq_schedule.rb, line 16 def nasdaq_working_day? market_time.send(:weekday?) && !market_time.nasdaq_holiday? && !(market_time.monday? && market_time.yesterday.nasdaq_holiday?) && !(market_time.friday? && market_time.tomorrow.nasdaq_holiday? && !market_time.send(:nasdaq_end_of_accounting_period_on_friday?)) end
Private Instance Methods
abbreviation_to_zones_mappings()
click to toggle source
This method is used only to properly handle conversation back to original time zone. This needs to be an instance method in order to properly handle day light savings and return the date in the original time zone.
# File lib/nasdaq_schedule.rb, line 127 def abbreviation_to_zones_mappings Hash[ActiveSupport::TimeZone.all.map{ |z| [self.in_time_zone(z).strftime('%Z'), z.name] }] end
close_hours()
click to toggle source
# File lib/nasdaq_schedule.rb, line 101 def close_hours close_hours = if market_time.nasdaq_working_day? if previous_day = market_time.yesterday.send(:nasdaq_holiday) if !market_time.monday? && previous_day[:day].to_i > 0 previous_day[:close_hours] end elsif next_day = market_time.tomorrow.send(:nasdaq_holiday) if !market_time.friday? && next_day[:day].to_i < 0 next_day[:close_hours] end end end close_hours.to_i end
market_time()
click to toggle source
# File lib/nasdaq_schedule.rb, line 79 def market_time in_nasdaq_time_zone end
must_be_working_day()
click to toggle source
# File lib/nasdaq_schedule.rb, line 116 def must_be_working_day raise NasdaqSchedule::Errors::NotWorkingDay unless market_time.nasdaq_working_day? end
nasdaq_closest_working_hours()
click to toggle source
# File lib/nasdaq_schedule.rb, line 66 def nasdaq_closest_working_hours (nasdaq_working_day? ? self : nasdaq_next_day).send(:nasdaq_working_hours) end
nasdaq_day(corresponding_day)
click to toggle source
# File lib/nasdaq_schedule.rb, line 50 def nasdaq_day(corresponding_day) date = market_time.send(corresponding_day) until date.nasdaq_working_day? date = date.send(corresponding_day) end date.in_time_zone(original_zone) end
nasdaq_end_of_accounting_period_on_friday?()
click to toggle source
# File lib/nasdaq_schedule.rb, line 91 def nasdaq_end_of_accounting_period_on_friday? quarter_months = [3, 6, 9, 12] if market_time.friday? && quarter_months.include?(market_time.month) last_month_days = [] 3.times{ |i| last_month_days << market_time.end_of_month.day - i} return true if last_month_days.include?(market_time.day) end false end
nasdaq_holiday()
click to toggle source
# File lib/nasdaq_schedule.rb, line 70 def nasdaq_holiday holiday_hash = to_date.holidays(:us, :informal).first || {} NasdaqSchedule::StockMarket::HOLIDAYS[holiday_hash[:name]] end
nasdaq_working_hours()
click to toggle source
# File lib/nasdaq_schedule.rb, line 58 def nasdaq_working_hours must_be_working_day { open: market_time.change(hour: 9, min: 30).in_time_zone(original_zone), close: market_time.change(hour: 16 + close_hours, min: 0).in_time_zone(original_zone) } end
original_zone()
click to toggle source
# File lib/nasdaq_schedule.rb, line 120 def original_zone abbreviation_to_zones_mappings[zone] end
same_zone?()
click to toggle source
# File lib/nasdaq_schedule.rb, line 83 def same_zone? send(:zone).to_s == self.in_time_zone(market_zone).zone.to_s end
weekday?()
click to toggle source
# File lib/nasdaq_schedule.rb, line 87 def weekday? (1..5).include?(market_time.wday) end