module Years

Provides some year-related methods.

Constants

VERSION

Public Class Methods

range(first_year, last_year=Date.current.year) click to toggle source

tells the age of someone, with truncation, where the leapling legal birthday is 28 February @param [Fixnum] first_year the first year of the range, say the year of company creation @param [Fixnum] last_year the last year of the range, defaults to this year @return [String]

# File lib/years.rb, line 27
def self.range first_year, last_year=Date.current.year
  raise if first_year > last_year

  (first_year == last_year) ? first_year.to_s : first_year.to_s + @@EN_DASH + last_year.to_s
end

Private Class Methods

age(date_of_birth, today, legal_leapling_birthday) click to toggle source
# File lib/years.rb, line 35
def self.age date_of_birth, today, legal_leapling_birthday
  raise if today < date_of_birth

  years = today.year - date_of_birth.year
  (birthday(date_of_birth, years, legal_leapling_birthday) > today) ? years - 1 : years
end
birthday(date_of_birth, years, legal_leapling_birthday) click to toggle source
# File lib/years.rb, line 42
def self.birthday date_of_birth, years, legal_leapling_birthday
  bday = date_of_birth.years_since years
  (leapling?(date_of_birth) and legal_leapling_birthday == :mar1) ? bday.tomorrow : bday
end
february_29th?(date) click to toggle source
# File lib/years.rb, line 51
def self.february_29th? date
  date.mday == 29 and date.mon == 2
end
leapling?(date) click to toggle source
# File lib/years.rb, line 47
def self.leapling? date
  february_29th? date
end