https://github.com/yegor256/tago
Convenient .ago() and .seconds() helpers for Ruby’s Time and String classes
https://github.com/yegor256/tago
logging ruby ruby-gem string-formatting time time-formatting time-progress
Last synced: 17 days ago
JSON representation
Convenient .ago() and .seconds() helpers for Ruby’s Time and String classes
- Host: GitHub
- URL: https://github.com/yegor256/tago
- Owner: yegor256
- License: mit
- Created: 2024-06-11T10:03:38.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2026-01-20T03:21:50.000Z (23 days ago)
- Last Synced: 2026-01-20T10:11:40.503Z (23 days ago)
- Topics: logging, ruby, ruby-gem, string-formatting, time, time-formatting, time-progress
- Language: Ruby
- Homepage: https://rubygems.org/gems/tago
- Size: 203 KB
- Stars: 2
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Adds `.ago()` Method to the `Time` Class
[](https://www.rultor.com/p/yegor256/tago)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/tago/actions/workflows/rake.yml)
[](https://www.0pdd.com/p?name=yegor256/tago)
[](https://badge.fury.io/rb/tago)
[](https://codecov.io/github/yegor256/tago?branch=master)
[](https://rubydoc.info/github/yegor256/tago/master/frames)
[](https://hitsofcode.com/view/github/yegor256/tago)
[](https://github.com/yegor256/tago/blob/master/LICENSE.txt)
First, install it:
```bash
gem install tago
```
Here is how you use it:
```ruby
start = Time.now
# something long
puts "It took #{start.ago} to do it"
```
It's also possible to convert Float seconds to text:
```ruby
s = Time.now - start
puts "It took #{s.seconds}"
```
The `seconds` method accepts optional formatting flags:
```ruby
9.444.seconds # => "9s444ms"
9.444.seconds(:round) # => "9s" (omits sub-units)
9.444.seconds(:short) # => "9s" (also omits sub-units)
300.0.seconds(:pretty) # => "five minutes" (words instead of abbreviations)
300.0.seconds(:pretty, :short) # => "5 min" (numeric with short unit names)
5.0.seconds(:pretty, :caps) # => "Five seconds" (capitalizes first letter)
```
The same flags work with `ago`:
```ruby
start.ago(:round)
start.ago(:pretty)
start.ago(:pretty, :short)
start.ago(:pretty, :caps)
start.ago(Time.now, :round)
```
The gem basically extends the `Float` and `Time` classes with new methods.
## How to contribute
Read
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have
[Ruby](https://www.ruby-lang.org/en/) 3.2+ and
[Bundler](https://bundler.io/) installed. Then:
```bash
bundle update
bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.