Time.now Is On My Side

Dan Croak

I needed an open? method. First try:

def open?
  opens_at < Time.now < closes_at
end

However, Ruby doesn’t support that kind of expression. Second try:

def open?
  (opens_at < Time.now) && (Time.now < closes_at)
end

It’s noisy and lacks expression. Third time’s a charm:

def open?
  Time.now.between?(opens_at, closes_at)
end

Ship it.

About thoughtbot

We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.