The source for this gem is located on Github: https://github.com/mkrisher/happymondays
To learn more about Date calculations in ActiveSupport: http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Calculations.html
Instructions for irb use
1) clone the repo
2) build the gem
3) install the gem
4) require in irb
5) define the day of the week to start the work week
Date.week_start_day = 'sunday'
6) create a new date object
d = Date.new(2011, 2, 8) # => Tue, 08 Feb 2011
7) request a date object representing the beginning of the week for the date instance
d.adjusted_beginning_of_week.strftime('%a %m/%d/%Y') # => Sun, 06 Feb 2011
8) request a date object representing the end of the week for the date instance
d.adjusted_end_of_week.strftime('%a %m/%d/%Y') # => Sat, 12 Feb 2011
9) if you want to clean up after yourself and "reset" Thread.current
10) if you want to work in a block that cleans up after itself
Date.with_week_start_day('sunday') do d = Date.new(2011, 2, 8) # => Tue, 08 Feb 2011 d.adjusted_beginning_of_week.strftime('%a %m/%d/%Y') # => Sun, 06 Feb 2011 end
Why use this?
1) this gem was created out of a need to alter the standard Ruby week from beginning on Monday and ending on Sunday
2) this gem is simply a mixin that extends the Date and ActiveSupport::CoreExtensions::Date::Calculations classes
3) it can be used anywhere a normal Ruby Date object would be used
4) the gem allows you to set the day of the week the week starts on
5) the gem also allows you to set the number of days in the work week, for example the default M-F being 5 vs. M-W being 3
Feel free to submit commits or feature requests. If you send a patch, remember to update the corresponding unit tests. In fact, I prefer new feature to be submitted in the form of new unit tests.
For other information contact mkrisher at gmail.com.
Happy Mondays are an English alternative rock band from Manchester, England.
Most people don't think Mondays are happy, however if you like your job, maybe your Mondays are happy.
This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.