birth-by-age-at-date
v5.0.0
Published
Calculates the birth year and current age based on the age as of a date
Downloads
20
Readme
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 beundefined
)
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.