Sha256: ba09b98e01362ad5e66498848f96d5a17f45e4c76acbd2a7760d42c6e507d66a
Contents?: true
Size: 602 Bytes
Versions: 13
Compression:
Stored size: 602 Bytes
Contents
module NxtSupport class BirthDate include NxtInit attr_init date: ->(date_or_string) { parse_date(date_or_string) } def to_age(today = Date.current) today.year - date.year - (today.month > date.month || (today.month == date.month && today.day >= date.day) ? 0 : 1) end def to_age_in_months(today = Date.current) (today.year * 12 + today.month) - (date.year * 12 + date.month) end def to_date date end private def parse_date(date_or_string) date_or_string.is_a?(Date) ? date_or_string : Date.parse(date_or_string) end end end
Version data entries
13 entries across 13 versions & 1 rubygems