Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

strong-roots-capital/years-between

Repository files navigation

years-between Build status npm version codecov

List years between two dates, inclusive

Install

npm install @strong-roots-capital/years-between

Use

import yearsBetween from '@strong-roots-capital/years-between'
import moment from 'moment'

console.log(
    yearsBetween(
        moment.utc().startOf('year').toDate(),
        moment.utc().startOf('year').toDate()
    )
)
//=>[ 2019 ]

console.log(
    yearsBetween(
        moment.utc().startOf('year').toDate(),
        moment.utc().startOf('year').add(1, 'years').toDate()
    )
)
//=>[ 2019, 2020 ]

console.log(
    // Note: supports function currying
    yearsBetween(moment.utc().startOf('year').toDate())
                (moment.utc().startOf('year').add(2, 'years').toDate())
)
//=>[ 2019, 2020, 2021 ]