Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
gem providing an easy api for changing the start and end days for Ruby's Date object
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
Gemfile
README.mdown
Rakefile
happymondays.gemspec

README.mdown

Happy Mondays

Mike Krisher

Details

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

rake build

3) install the gem

rake install

4) require in irb

require 'happymondays'

Example usage:

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

Date.clear_adjusted_weeks

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

Support

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.

Other stuff

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.

Warranty

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.

Something went wrong with that request. Please try again.