Dates Toolbox
dates_toolbox is a fully feature gem full of utilities for manipulating dates.
Installation
Add this line to your application's Gemfile:
gem 'dates_toolbox'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dates_toolbox
Usage
Basic
The following methods are available.
- the_day = The numeric day part of a given date
- the_month = The numeric month part of a given date
- the_year = The numeric year part of a given date
- day_of_the_week (dotw) = The day of the week for a given date (Sunday = 0, Saturday = 6)
- day_of_the_week_name (dotwn) = The name of the day of the week for a given date
- day_of_the_year (doty) = The day of the year for a given date
- days_between = The number of days between to days (excluding both given days)
- weekends = Arrays of Date objects for weekends between given dates (including both given dates)
- weekends_string = Array of date strings for weekends between given dates (including both given dates)
- weekdays = Arrays of Date objects for weekdays between given dates (including both given dates)
- weekdays_string = Array of date strings for weekdays between given dates (including both given dates)
Advanced
All of the methods will default to a UK date format (%d/%m/%Y), however it is also possible to set a custom date format in one of 2 different ways.
d = Date.new
d.format = '%m-%d-%Y'
d.the_day('6-23-1912', '%m-%d-%Y')
Examples
d = Date.new
puts d.the_day('23/6/1912')
puts '23/6/1912'.the_day
puts d.the_month('23/6/1912')
puts '23/6/1912'.the_month
puts d.the_year('23/6/1912')
puts '23/6/1912'.the_year
puts d.day_of_the_week('23/6/1912')
puts '23/6/1912'.day_of_the_week
puts d.day_of_the_week_name('23/6/1912')
puts '23/6/1912'.day_of_the_week_name
puts d.day_of_the_year('23/6/1912')
puts '23/6/1912'.day_of_the_year
puts d.days_between('23/6/1912', '7/6/1954')
puts '23/6/1912'.days_between('7/6/1954')
puts d.weekends('1/1/2000', '31/1/2000')
puts '1/1/2000'.weekends('31/1/2000')
puts d.weekends_string('1/1/2000', '31/1/2000')
puts '1/1/2000'.weekends_string('31/1/2000')
puts d.weekdays('1/1/2000', '15/1/2000')
puts '1/1/2000'.weekdays('15/1/2000')
puts d.weekdays_string('1/1/2000', '15/1/2000')
puts '1/1/2000'.weekdays_string('15/1/2000')
Method Aliases
- day_of_the_week is aliased to dotw
- day_of_the_week_name is aliased to dotwn
- day_of_the_year is aliased to doty
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.
Testing
For local testing make sure that you run bundle exec rspec spec
and then rake install
to install the gem locally.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/WolfSoftware/dates_toolbox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the dates_toolbox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
To-Do List