Featured image

What I enjoy most in Ruby is working with date and time objects. The standard library implements time arithmetic especially elegantly: adding and subtracting seconds, days, and months. I’ve never seen anything like this in any other language, where it looks so clear, concise, and beautiful:

require 'time'

now = Time.now
now + 20 # 20 seconds from now
now - 20 # 20 seconds ago

date = Time.now.to_date
date + 3  # 3 days from now
date - 3  # 3 days ago
date >> 6 # 6 months from now
date << 6 # 6 months ago

And ActiveSupport only enhances this impression with an additional Duration class, making working with time and dates even more pleasant:

require 'time'
require 'active_support/all'

now = Time.current
now + 1.hour
now + 1.week
now + 1.month