1.0.1 • Published 3 years ago
time-descriptor v1.0.1
time-descriptor
This package is ment to better visualize relative time declarations.
import { MINUTES, SECONDS, inDays } from "time-descriptor";
const start = Date.now();
setInterval(() => {
// Days running
console.log(inDays(Date.now() - start));
}, 3 * MINUTES + 25 * SECONDS);
Setup
Get the package from npm and add it to your package.json.
yarn add time-descriptor
or if you preferr the npm way
npm install --save time-descriptor
Usecases
This package handles relative time. It is not meant to be a replacement for date-fns. I highly recommend to use date-fns, if you have complex calculations.
Relative time declaration
// Add 15 minutes to current timestamp
Date.now() + 15 * MINUTES;
Very specific time declaration
// 5 * 24 * 60 * 60 * 1000 + 3 * 60 * 60 * 1000 + 12 * 60 * 1000
5 * DAYS + 3 * HOURS + 12 SECONDS
Conversion to decimal numbers
// 442800000 ms = 5.125 days
inDays(5 * DAYS + 3 * HOURS);
Additions
- This package package supports up to weeks, since everything beyond requires context, and I haven't found a smart solution for:
Example:1 * MONTH
wich is<= 31 && >= 28