“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay who are based in Denmark...”

Rob Lacey
Senior Software Engineer, Copenhagen, Denmark

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"