Ruby 2 - Time Intervals
Old blog posts I never published, except I have now #12
Say we wanted to schedule a job but wanted to limit duplicate jobs running within a specific time period. We could set a time for a job to run and ignore duplicate requests in our queue. It appears Ruby’s Time object makes this simple for us. We can round up (or floor) to the nearest, time interval. Nice.
2.2.2 :012 > Time.now.floor(15.minutes)
=> "2016-02-29T17:15:00.000+00:00"
2.2.2 :013 > Time.now.round(15.minutes)
=> "2016-02-29T17:30:00.000+00:00"