How to know if today's date is in a date range?

前端 未结 8 1701
死守一世寂寞
死守一世寂寞 2020-12-12 10:14

I have an event with start_time and end_time and want to check if the event is \"in progress\". That would be to check if today\'s date is in the r

相关标签:
8条回答
  • 2020-12-12 11:10

    Because the date class includes the Comparable module, every date object has a between? method.

    require 'date'
    
    today           = Date.today
    tomorrow        = today + 1
    one_month_later = today >> 1
    
    tomorrow.between?(today, one_month_later) # => true
    
    0 讨论(0)
  • 2020-12-12 11:12

    If they're timestamps:

    def in_progress?
      (start_time..end_time).include?(Time.now)
    end
    0 讨论(0)
提交回复
热议问题