Project

wobbly

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.25
~> 13.2.1
 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.

"Buy Me A Coffee"

Requirements

Ruby 2.0.0 or higher is recommended.

Installation

Install the gem with:

gem install wobbly

Getting Started

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:

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:

rake test

License

Please see LICENSE for licensing details.

Author

github.com/sn