This library enables the use of numeric or text representations of months, conversions between month and date objects, the ability to find the number of days and retrieve the dates for all days in a month, and the ability to move forward and back a month at a time.
Add this line to your application's Gemfile:
gem 'month.rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install month.rb
Month.new(2006, 1)
# => #<Month @year = 2006, @month = 1>
Month.new(1)
# => #<Month @year = Date.today.year, @month = 1>
Month.of('January')
# => #<Month @year = Date.today.year, @month = 1>
Month.of('Jan')
# => #<Month @year = Date.today.year, @month = 1>
Month.today
# => #<Month @year = Date.today.year, @month = Date.today.month)>
Date.new(2006, 1, 1).to_month
# => #<Month @year = 2006, @month = 1>
Month.new(2006, 1).to_date
# => #<Date @year = 2006, @month = 1, @day = 1>
Month.new(1).to_number
# => 1
Month.new(1).to_short
# => 'Jan'
Month.new(1).to_long
# => 'January'
Month.new(2006, 1).to_number
# => 1
Month.new(2006, 1).to_short
# => 'Jan'
Month.new(2006, 1).to_long
# => 'January'
Month.new(1).to_s
# => "January #{Date.today.year}"
Month.new(2011, 1).to_s(:long)
# => "January #{Date.today.year}"
Month.new(2011, 1).to_s('long')
# => "January #{Date.today.year}"
Month.new(2011, 1).to_s(:short)
# => "Jan #{Date.today.year}"
Month.new(2011, 1).to_s('short')
# => "Jan #{Date.today.year}"
Month.new(2011, 1).to_s
# => 'January 2011'
Month.new(2011, 1).to_s(:long)
# => 'January 2011'
Month.new(2011, 1).to_s('long')
# => 'January 2011'
Month.new(2011, 1).to_s(:short)
# => 'Jan 2011'
Month.new(2011, 1).to_s('short')
# => 'Jan 2011'
end
Month.of('January') == Month.of('January')
# => true
Month.of('January') > Month.of('January')
# => false
Month.of('February') > Month.of('January')
# => true
Month.of('January') < Month.of('February')
# => true
Month.beginning_of_month(2006, 1)
# => #<Date @year = 2006, @month = 1, @day = 1>
Month.end_of_month(2006, 1)
# => #<Date @year = 2006, @month = 1, @day = 31>
Month.new(2006, 1).beginning_of_month
# => #<Date @year = 2006, @month = 1, @day = 1>
Month.new(2006, 1).end_of_month
# => #<Date @year = 2006, @month = 1, @day = 31>
Month.dates(2006, 10, day: 'Sunday')
# => [1, 8, 15, 22, 29]
Month.new(2011, 1).date('First', 'Monday')
# => 3
Month.new(2006, 10).day(1) # Return the day name of first day of the month.
# => 'Sunday'
Month.days('January')
# => 31
Month.of('January').days
# => 31
Month.new(2011, 1).previous_month
# => #<Month @year = 2010, @month = 12>
Month.new(2011, 1).next_month
# => #<Month @year = 2011, @month = 2>
Month.new(2011, 1).last_year
# => #<Month @year = 2010, @month = 2>
Month.new(2011, 1).next_year
# => #<Month @year = 2012, @month = 1>
- Fork it: https://github.com/thoran/month.rb/fork
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Create a new pull request