Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/caironoleto/nostradamus

Nostradamus knows his future…
https://github.com/caironoleto/nostradamus

Last synced: 3 months ago
JSON representation

Nostradamus knows his future…

Awesome Lists containing this project

README

        

# The Nostradamus gem

You can parse human time to seconds or convert seconds to human time.

## Install nostradamus gem

Add `nostradamus` in Gemfile and run `bundle install`.

gem "nostradamus"

Or only execute `gem install nostradamus` on terminal.

## How to use

### Human time to seconds:
```ruby
Nostradamus.parse("10:00") # => 36000
Nostradamus.parse("10:00:00") # => 36000
```

### Seconds to human time:
```ruby
Nostradamus.humanize(36000, :short) # => "10:00"
Nostradamus.humanize(36000) # => "10:00:00"
```

### Sum with seconds
```ruby
time = Nostradamus.new("12:00") + 60
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"
```

### Sum with another Nostradamus instance
```ruby
time = Nostradamus.new("12:00") + Nostradamus.new(60)
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"
```

### Compare times
```ruby
Nostradamus.new("12:00") == 43260
Nostradamus.new("00:01:00") == Nostradamus.new(60)
```

### Returning a Time object
```ruby
Nostradamus.new("12:00").to_time # => Returns a object: Time.new(CURRENT_YEAR, CURRENT_MONTH, CURRENT_DAY, 12, 0)
Nostradamus.new("12:00").to_time(:on => Date.new(2012, 5, 1)) # => Returns a object: Time.new(2012, 5, 1, 12, 0)
```

## Contributing

If you want to contribute, please:

* Fork the project.
* Make your feature addition or bug fix.
* Send me a pull request on Github.

## Code Status

[![Build Status](https://travis-ci.org/caironoleto/nostradamus.svg?branch=master)](https://travis-ci.org/caironoleto/nostradamus)