Class: Date
Class Method Summary collapse
- .days_between(start, finish) ⇒ Object
- .months_between(start, finish) ⇒ Object
- .weeks_between(start, finish) ⇒ Object
- .years_between(start, finish) ⇒ Object
Class Method Details
.days_between(start, finish) ⇒ Object
6 7 8 |
# File 'lib/bad_ass_extensions/date.rb', line 6 def self.days_between(start, finish) (finish - start).to_i end |
.months_between(start, finish) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/bad_ass_extensions/date.rb', line 14 def self.months_between(start, finish) if start.year != finish.year difference = (12 - start.month) + (12 * years_between(start, finish)) + finish.month else difference = finish.month - start.month end difference -= 1 if finish.day < start.day difference end |
.weeks_between(start, finish) ⇒ Object
10 11 12 |
# File 'lib/bad_ass_extensions/date.rb', line 10 def self.weeks_between(start, finish) days_between(start, finish) / 7 end |
.years_between(start, finish) ⇒ Object
24 25 26 27 28 |
# File 'lib/bad_ass_extensions/date.rb', line 24 def self.years_between(start, finish) difference = finish.year - start.year difference -= 1 if difference > 0 && (finish.month < start.month || finish.day < start.day) difference end |