项目作者: max-power

项目描述 :
Age Calculation
高级语言: Ruby
项目地址: git://github.com/max-power/age.git
创建时间: 2017-12-10T22:47:54Z
项目社区:https://github.com/max-power/age

开源协议:

下载


Age

Installation

Add this line to your application’s Gemfile:

  1. gem 'power-age'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install power-age

Usage

Age::now(timestamp)

shortcut for Age.new(timestamp).now

Age::new(timestamp)

Age#new accepts a Time, Date or DateTime object as argument.

Age#now

  1. birthday = Time.new(1990, 3, 14)
  2. Age.new(birthday).now

Age#at(timestamp)

  1. User = Struct.new(:dob)
  2. Event = Struct.new(:start_date)
  3. event = Event.new(Time.new(2020, 2, 20))
  4. user = User.new(Time.new(1970, 6, 21))
  5. Age.new(user.dob).at event.start_date

ActiveRecord/ActiveModel

  1. class User < ApplicationRecord
  2. has_person_name
  3. has_age
  4. end
  5. class Dog < ApplicationRecord
  6. has_age column: :pet_birth_date
  7. end
  8. user = User.new(dob: Date.new(2000, 1, 1))
  9. user.age
  10. user.age(at: Time.now + 1.day)