Skip to content

Calculates the birth year and current age based on the age as of a date.

License

Notifications You must be signed in to change notification settings

kenany/birth-by-age-at-date

Repository files navigation

birth-by-age-at-date

Calculates the birth year and current age based on the age as of a date. Based off, believe it or not, Wikipedia's Template:Birth_based_on_age_as_of_date.

Example

You know someone who was 50 years old on January 15, 2013. You would like to know what their birth year might be and/or their current age:

var birthByAgeAtDate = require('birth-by-age-at-date');

birthByAgeAtDate(50, new Date(2013, 0, 15));
// => {
// =>   lowerYear: 1962,
// =>   upperYear: 1963,
// =>   lowerAge: 50,
// =>   upperAge: 51
// => }

Installation

$ npm install birth-by-age-at-date

API

var birthByAgeAtDate = require('birth-by-age-at-date');

birthByAgeAtDate(age, date[, currentDate])

Calculates the birth year and current age based on the knowledge that the individual was Number age at Date date. Returns an Object:

  • .lowerYear
  • .upperYear
  • .lowerAge
  • .upperAge (may be undefined)

There will always be two possible birth years: .lowerYear and .upperYear. .upperAge will not appear if the number of days elapsed in date's year is equal to the number of days elapsed in currentDate's year.

By default, new Date() is used to calculate current age. You can optionally pass your own currentDate as a third argument.

About

Calculates the birth year and current age based on the age as of a date.

Resources

License

Stars

Watchers

Forks

Packages