Introduction
FatPeriod
provides a Ruby Period
class for dealing with time periods, that
is ranges whose endpoints are Date
s. Set operations, for example, are
provided for Period, as well as methods for parsing strings into Periods and
methods for breaking a larger periods into an array of smaller periods of
various ‘chunk’ sizes that correspond to calendar-related periods such as
days, weeks, months, and so forth.’
Installation
Installing the gem
Add this line to your application’s Gemfile:
gem 'fat_period'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fat_period
Usage
Construction of Periods
A Period is constructed with two arguments for the begin and end date. The
begin date must be on or before the end date. Each argument can be (1) a
Date, (2) a string parseable as a Date by the Date.parse method, or (3) an
object that responds to #to_s
and can be parsed as a Date by Date.parse:
p1 = Period.new(Date.today, Date.today + 30)
p2 = Period.new('Nov 22, 1963', Date.today)
p3 = Period.new('1961-01-21', '1963-11-22')
puts "Camelot lasted #{p3.length} days"
Period Constants
The Period
class depends on the extensions to Date
made by the fat_core
gem, which you can read about here. It defines two constants, Date::BOT
and
Date::EOT
, which define beginning of time and end of time for practical
commercial purposes.
Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ddoherty03/fat_table.