Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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…
- Host: GitHub
- URL: https://github.com/caironoleto/nostradamus
- Owner: caironoleto
- Created: 2012-07-25T18:23:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T18:20:52.000Z (almost 7 years ago)
- Last Synced: 2023-04-11T13:58:12.332Z (almost 2 years ago)
- Language: Ruby
- Homepage:
- Size: 22.5 KB
- Stars: 2
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)