Week Of Month
Week Of Month is a library which gives you week_of_month method on Date and Time class object, that returns week of the month. It basically extends the Date and Time class with several useful date helpers.
Getting Started
Week Of Month is released as a Ruby Gem. The gem is to be installed within a Ruby or Rails application. To install, simply add the following to your Gemfile:
gem 'week_of_month'
Run bundle install and don’t forget to restart your server after you install a new gem.
Usage
It returns week split of that date's month
Date.new(2012,1,1).week_split
=> [[1, 2, 3, 4, 5, 6, 7],
[8, 9, 10, 11, 12, 13, 14],
[15, 16, 17, 18, 19, 20, 21],
[22, 23, 24, 25, 26, 27, 28],
[29, 30, 31]]
It returns month's week in which the date lies
Date.new(2012,1,1).week_of_month => 1
It return true if date lies in first week of month, else false.
Date.new(2012,1,1).first_week? => true
It returns true if date lies in second week of month, else false.
Date.new(2012,1,9).second_week? => true
It returns true if date lies in last week of month, else false.
Date.new(2012,1,31).last_week? => true
It returns total number of weeks in month.
Date.new(2012,1,31).total_weeks => 5
It returns month's week in which the date lies
Date.new(2012,1,31).week_of_month_in_eng => "Fifth"
Tools Being Used
We believe strongly in not writing code unless we have to, so Week Of Month is built using
Ruby Date Class
Ruby Time Class
Version History
1.2.1
Support for Time class
Methods Added
name_of_week_day, name_of_month, week_end?, working_day?, all_sundays_in_month, all_mondays_in_month, all_tuesdays_in_month, all_wednesdays_in_month, all_thursdays_in_month, all_fridays_in_month, all_saturdays_in_month
1.1.0
ActiveSupport Dependency removed
Methods Added
january?, february?, march?, april?, may?, june?, july?, august?, september?, october?, november?, december?, last_day_of_month
Contributing to Week Of Month
Fork, fix, then send me a pull request.
## License
use MIT license.