Get the difference between two time
Add this line to your application's Gemfile:
gem 'time_subtract'
And then execute:
$ bundle
Or install it yourself as:
$ gem install time_subtract
time.smart_subtract time2
date.smart_subtract date2
# This will return
'2 years 1 month 8 days 10 hours 5 minutes 23 seconds'.
If you want result as hash
time.smart_subtract(time2, hash: true)
# or
date.smart_subtract(date2, hash: true)
# or
(time - time2).time_diff_hash
# or
seconds = 123456
seconds.time_diff_hash
# This will return
#=> {:year => 0, :month => 0, :day => 1, :hour=> 10, :minute => 17, :second => 36}
- Fork it ( https://github.com/ponnusamygit/time_subtract/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
- Get format from user
Time Subtract uses RSpec for test coverage. Inside the gem directory, you can run the specs with:
rpsec spec/time_subtract_spec.rb
MIT