@skinnyjames/hourglass
v1.2.1
Published
library for measuring relative time
Downloads
5
Readme
hourglass
library for working with relative time
usage
npm install @skinnyjames/hourglass
or include dist/hourglass.js for use in the browser
<script type="text/javascript" src="hourglass.js"></script>
<!-- hourglass now available via window -->
const hourglass = require('@skinnyjames/hourglass')
// Pass an object with a years, months, weeks, hours, minutes, seconds and a from property
let aYearAgo = hourglass({
seconds: -31536000,
from: new Date(2000, 0, 1, 0, 0, 0)
})
let twoThousandYearsAgo = hourglass({
years: -2000,
from: new Date(Date.now())
})
// or pass in as two parameters
let whenThePyramidsWereBuilt = hourglass(-146011680000, new Date(2000, 0, 1, 0, 0, 0, 0))
get the number of years elapsed
console.log(whenThePyramidsWereBuilt.years)
> -4630
get the span in seconds in between two events
let deathOfAlexanderTheGreat = hourglass(-73255805000, new Date(2000, 0, 1, 0, 0, 0, 0))
let spanInYears = (whenThePyramidsWereBuilt - deathOfAlexanderTheGreat) / hourglass.SECONDS_PER_YEAR
console.log(Math.round(spanInYears))
> 2307
find out the years elapsed from an arbitary date
let future = new Date(8000, 0, 1, 0, 0, 0, 0)
console.log(deathOfAlexanderTheGreat.from(future).years)
> -8326
print a friendly date (in progress)
console.log(aYearAgo.strftime('%years year and %months months from %date'))
> -1 year and 0 months from 1/1/2000
export to object
exportObject = aYearAgo.export()
development
please feel free to submit pull requests, report a bug, or just share your knowledge and ideas!