Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/expanded_date.rb

Instance Method Summary collapse

Instance Method Details

#beginning_of_monthObject



62
63
64
# File 'lib/expanded_date.rb', line 62

def beginning_of_month
  self::class.civil(self.year, self.month, 1)
end

#beginning_of_next_monthObject



74
75
76
# File 'lib/expanded_date.rb', line 74

def beginning_of_next_month
  self.beginning_of_month.next_month
end

#beginning_of_prev_monthObject



78
79
80
# File 'lib/expanded_date.rb', line 78

def beginning_of_prev_month
  self.beginning_of_month.prev_month
end

#end_of_monthObject



57
58
59
60
# File 'lib/expanded_date.rb', line 57

def end_of_month  
  d = next_month
  self::class.civil(d.year, d.month, 1)-1
end

#end_of_next_monthObject



66
67
68
# File 'lib/expanded_date.rb', line 66

def end_of_next_month
  self.beginning_of_month.next_month.end_of_month
end

#end_of_prev_monthObject



70
71
72
# File 'lib/expanded_date.rb', line 70

def end_of_prev_month
  self.beginning_of_month-1
end

#next_monthObject

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_weekObject



25
26
27
# File 'lib/expanded_date.rb', line 25

def next_week
  self + 7
end

#prev_monthObject

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_weekObject



29
30
31
# File 'lib/expanded_date.rb', line 29

def prev_week
  self - 7
end

#tomorrowObject



17
18
19
# File 'lib/expanded_date.rb', line 17

def tomorrow
  self + 1
end

#yesterdayObject



21
22
23
# File 'lib/expanded_date.rb', line 21

def yesterday
  self - 1
end