Timefly
A simple library which makes it easier to get time related data, eg, age from Date of birth, elapsed time in beautiful format, etc.
Installation
gem install timeflyUsage
To initialize you can pass an instance of Time, Date or a String
require 'timefly'
Timefly.new(Time.new(1987, 8, 2))
#str_origin_time can be String or formats YYYY.MM.DD, YYYY-MM-DD, YYYY/MM/DD
Timefly.new(str_origin_time)To get the elapsed time
Timefly.new(origin_time).elapsed_time
# => 4 hours agoTo get a custom format of the elapsed_time
Timefly.new(origin_time).elapsed_time(format: '%n%u')
# => 4h
# %n - numeric value of the difference
# %u - short form of the unit
# %U - full unitTo get the age from date of birth
# dob is the date of birth
Timefly.new(dob).age
# => 27If you want to retrieve age in years and months then
Timefly.new(dob).age({ format: '%y years, %m months' })
# => 27 years, 10 monthsContributing
- Fork it
- Create your feature branch (
git checkout -b my-new-awesome-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-awesome-feature) - Create new Pull Request
- Relax and enjoy a beer