Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock market hours? #4

Open
jch opened this issue Dec 20, 2023 · 1 comment
Open

Stock market hours? #4

jch opened this issue Dec 20, 2023 · 1 comment

Comments

@jch
Copy link

jch commented Dec 20, 2023

I'm currently using this method to calculate whether market is open. The problem is it doesn't handle EST vs EDT. Thoughts on adding something more robust to your gem?

class MarketHours
  def self.open?(time = nil)
    Time.use_zone('Eastern Time (US & Canada)') do
      time ||= Time.current
      return false if time.on_weekend?

      market_open = Time.zone.local(time.year, time.month, time.day, 9, 30)
      market_close = Time.zone.local(time.year, time.month, time.day, 16, 0)

      time.between?(market_open, market_close)
    end
  end
end
@wakproductions
Copy link
Owner

Time zones are tricky. One problem with this is that Time.current is from Rails. I think a gem like this should not need to have Rails as a dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants