Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
localhostdotdev / relative-past-time.rb
Last active February 24, 2019 22:33
Get relative time in the past (with a shorter output option)
class RelativeTime
MINUTE = 60
HOUR = 60 * MINUTE
DAY = 24 * HOUR
WEEK = 7 * DAY
MONTH = 4 * WEEK
YEAR = 12 * MONTH
def self.for(date_to, date_from = Time.zone.now, short: false)
diff = (date_from.to_time - date_to.to_time).round
gem 'rails', github: 'rails/rails'
require 'active_record'
`dropdb bug_1; createdb bug_1`
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'bug_1',
host: 'localhost',