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

前端 未结 8 1705
死守一世寂寞
死守一世寂寞 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
    

提交回复
热议问题