Created
March 18, 2010 15:16
-
-
Save hypomodern/336457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Need to find out how many days are in the current month? | |
# leverage the power of Date#<<(n), which "rewinds" the date by n months. | |
# it helpfully sets the day correctly if you rewind from the 31st, so rewind from 12/31. | |
days_in_current_month = ( Date.new(Time.now.year, 12, 31).to_date << ( 12 - Time.now.month ) ).day | |
# You could also make this a method call | |
def days_in_month(month_number) | |
( Date.new(Time.now.year, 12, 31).to_date << ( 12 - month_number ) ).day | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment