Section 7.24. Dividing a Month into Weeks


7.23. Determining the Number of Days in a Month

At the time of this writing, there is no built-in function to do this. You can easily write a simple method for this:

require 'date' def month_days(month,year=Date.today.year)   mdays = [nil,31,28,31,30,31,30,31,31,30,31,30,31]   mdays[2] = 29 if Date.leap?(year)   mdays[month] end days = month_days(5)             # 31 (May) days = month_days(2,2000)        # 29 (February 2000) days = month_days(2,2100)        # 28 (February 2000)





The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net