Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/sixarm_ruby_date_age.rb
Instance Method Summary (collapse)
-
- (Integer) age_in_days(compare_date = Date.today)
(also: #age_in_days_on)
The age in days for a given date.
-
- (Integer) age_in_years(compare_date = Date.today)
(also: #age_in_years_on)
The age in years for a given date.
Instance Method Details
- (Integer) age_in_days(compare_date = Date.today) Also known as: age_in_days_on
The age in days for a given date.
53 54 55 56 |
# File 'lib/sixarm_ruby_date_age.rb', line 53 def age_in_days(compare_date=Date.today) (compare_date.is_a? Date) or raise ArgumentError, "compare_date must be a date" (compare_date-self).to_i end |
- (Integer) age_in_years(compare_date = Date.today) Also known as: age_in_years_on
The age in years for a given date.
81 82 83 84 85 86 87 |
# File 'lib/sixarm_ruby_date_age.rb', line 81 def age_in_years(compare_date=Date.today) (compare_date.is_a? Date) or raise ArgumentError, "compare_date must be a date" age=compare_date.year-year compare_month = compare_date.month age-=1 if compare_month < month or (compare_month==month and compare_date.day < day) age end |