Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/core_ext/date.rb
Instance Method Summary collapse
- #nth_day_of_month ⇒ Object
-
#nth_day_of_month?(n) ⇒ Boolean
return true if this is the nth of this day within the month, for example, if n is 2, and this is the second wednesday of the month, return true.
- #nth_last_day_of_month ⇒ Object
Instance Method Details
#nth_day_of_month ⇒ Object
2 3 4 |
# File 'lib/core_ext/date.rb', line 2 def nth_day_of_month 1 + ( (self.mday - 1) / 7 ) end |
#nth_day_of_month?(n) ⇒ Boolean
return true if this is the nth of this day within the month, for example, if n is 2, and this is the second wednesday of the month, return true. If n is -1, and this is the last saturday of the month, return true. It doesn’t matter which day it is, it matters whether it’s the first, second, third, etc, or if it’s the last, second last, third last, etc
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/core_ext/date.rb', line 19 def nth_day_of_month? n case n <=> 0 when -1 nth_last_day_of_month == n when 0 raise ArgumentError.new("must be non-zero integer") when 1 nth_day_of_month == n end end |
#nth_last_day_of_month ⇒ Object
6 7 8 9 |
# File 'lib/core_ext/date.rb', line 6 def nth_last_day_of_month last_day = self.end_of_month.mday - 1 - (last_day - self.mday) / 7 end |