Localized relative date/time formatting (both for past and future dates) in Ruby/Rails.
Automatically chooses the right units (seconds, minutes, etc) to format a time interval.
- just now
- 45 s ago
- 15 m ago
- 3 h ago
- Yesterday at 2pm
- Monday at 7am
- etc
Add this line to your application's Gemfile:
gem 'a_moment_ago'
Then execute:
bundle install
Or install it yourself
gem install a_moment_ago
### created_at.rb
require 'time_ago'
class CreatedAtTime
def time_of_creation
@created = TimeAgo.new.time_ago
end
end
created_time = CreatedAtTime.new
created_time.time_of_creation
# app/controllers/appointments/appointments_ago.rb
require "time_ago"
class Appointments::AppointmentsAgo
# function defination for example
def appontment_time
@appointment_last_visited = TimeAgo.new.time_ago
end
end
# app/controllers/appointments_controller.rb
class AppointmentsController < ApplicationController
def create
@appointment_time = Appointments::AppointmentsAgo.new.appontment_time
render json: { "appointment_time": @appointment_time }, status: :ok
end
end
- Fork the repo ( https://github.com/[my-github-username]/time_ago/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request