https://github.com/sn/wobbly
Wobbly is a simple Ruby library that parses shorthand relative date and time duration strings, making it easy to specify durations like "1h2m" (1 hour, 2 minutes) or "5Y" (5 years) in a concise format.
https://github.com/sn/wobbly
date datetime ruby ruby-gem ruby-library rubygems
Last synced: about 22 hours ago
JSON representation
Wobbly is a simple Ruby library that parses shorthand relative date and time duration strings, making it easy to specify durations like "1h2m" (1 hour, 2 minutes) or "5Y" (5 years) in a concise format.
- Host: GitHub
- URL: https://github.com/sn/wobbly
- Owner: sn
- License: gpl-3.0
- Created: 2017-11-27T19:02:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-02T13:36:13.000Z (about 1 year ago)
- Last Synced: 2026-01-13T07:29:28.560Z (9 days ago)
- Topics: date, datetime, ruby, ruby-gem, ruby-library, rubygems
- Language: Ruby
- Homepage: https://rubygems.org/gems/wobbly
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Wobbly: Simple Date Token Parser for Ruby
Wobbly is a Ruby library that parses a given time-based token string to calculate a date in the future. It's lightweight and intuitive, perfect for adding flexible time calculations to your Ruby projects.
[](https://buymeacoffee.com/underwulf)
Requirements
-----------------
Ruby 2.0.0 or higher is recommended.
Installation
-----------------
Install the [gem](https://rubygems.org/gems/wobbly) with:
```bash
gem install wobbly
```
Getting Started
-----------------
```ruby
require 'wobbly'
Wobbly.in('1h2m') # => 2017-11-27 19:58:44 +0200
```
Available Tokens
-----------------
Wobbly supports the following tokens, which can be combined in any order:
- `s` - seconds
- `m` - minutes
- `h` - hours
- `D` - days
- `W` - weeks
- `M` - months (approximated as 30 days)
- `Y` - years (approximated as 365 days)
Examples
-----------------
Here are some usage examples demonstrating how Wobbly interprets different token strings:
```ruby
Wobbly.in('1h2m8s') # Adds 1 hour, 2 minutes, and 8 seconds to the current time
Wobbly.in('5Y') # Adds 5 years to the current time
Wobbly.in('3Y8m') # Adds 3 years and 8 minutes to the current time
Wobbly.in('3Y8M2W1D') # Adds 3 years, 8 months, 2 weeks, and 1 day to the current time
```
Running the tests
-----------------
To test Wobbly, run the following command:
```bash
rake test
```
License
-----------------
Please see [LICENSE](https://github.com/sn/Wobbly/blob/master/LICENSE) for licensing details.
Author
-----------------
[github.com/sn](https://github.com/sn)