Read more

Fixing the warning Time#succ is obsolete; use time + 1

Deleted user #6
December 18, 2014Software engineer

Chances are you're seeing the warning repeated a lot of times, maybe thousands of times. Here's how to reproduce the issue:

Example 1

# bad code
(Time.current .. Time.current + 1.hour).include?(Time.current)

# Use Range#cover? instead of Range#include? since the former does no typecasting into integers.
(Time.current .. Time.current + 1.hour).cover?(Time.current)

Example 2

# bad code
Post.where(:created_at => min_date.beginning_of_day .. max_date.end_of_day)

# Use 'BETWEEN x AND y'
Post.where(['posts.created_at BETWEEN ? AND ?', min_date.beginning_of_day, max_date.end_of_day])

Why?

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Ruby 1.9.2 used to define a Time#succ method that returned a new Time object 1 second later than the previous one. This was used to iterate over time spans. That means for every second in the time range, Ruby 1.9.3 will show said deprecation warning.

Credits to Philipp Antar.

Posted to makandra dev (2014-12-18 16:51)