Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/expanded_date.rb
Instance Method Summary collapse
- #beginning_of_month ⇒ Object
- #beginning_of_next_month ⇒ Object
- #beginning_of_prev_month ⇒ Object
- #end_of_month ⇒ Object
- #end_of_next_month ⇒ Object
- #end_of_prev_month ⇒ Object
-
#next_month ⇒ Object
This date in next month.
- #next_week ⇒ Object
-
#prev_month ⇒ Object
This date in previous month.
- #prev_week ⇒ Object
- #tomorrow ⇒ Object
- #yesterday ⇒ Object
Instance Method Details
#beginning_of_month ⇒ Object
61 62 63 |
# File 'lib/expanded_date.rb', line 61 def beginning_of_month self::class.civil(self.year, self.month, 1) end |
#beginning_of_next_month ⇒ Object
73 74 75 |
# File 'lib/expanded_date.rb', line 73 def beginning_of_next_month self.beginning_of_month.next_month end |
#beginning_of_prev_month ⇒ Object
77 78 79 |
# File 'lib/expanded_date.rb', line 77 def beginning_of_prev_month self.beginning_of_month.prev_month end |
#end_of_month ⇒ Object
57 58 59 |
# File 'lib/expanded_date.rb', line 57 def end_of_month self.beginning_of_next_month-1 end |
#end_of_next_month ⇒ Object
65 66 67 |
# File 'lib/expanded_date.rb', line 65 def end_of_next_month self.beginning_of_month.next_month.end_of_month end |
#end_of_prev_month ⇒ Object
69 70 71 |
# File 'lib/expanded_date.rb', line 69 def end_of_prev_month self.beginning_of_month-1 end |
#next_month ⇒ Object
This date in next month. Raises ArgumentError: invalid date if the date does not exist.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/expanded_date.rb', line 46 def next_month m = month + 1 y = year if m == 13 m = 1 y = y + 1 end d = day self::class.civil(y,m,d) end |
#next_week ⇒ Object
25 26 27 |
# File 'lib/expanded_date.rb', line 25 def next_week self + 7 end |
#prev_month ⇒ Object
This date in previous month
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/expanded_date.rb', line 34 def prev_month m = month - 1 y = year if m == 0 m = 12 y = y - 1 end d = day self::class.civil(y,m,d) end |
#prev_week ⇒ Object
29 30 31 |
# File 'lib/expanded_date.rb', line 29 def prev_week self - 7 end |
#tomorrow ⇒ Object
17 18 19 |
# File 'lib/expanded_date.rb', line 17 def tomorrow self + 1 end |
#yesterday ⇒ Object
21 22 23 |
# File 'lib/expanded_date.rb', line 21 def yesterday self - 1 end |