@jacobhumston/tc.js
v1.0.3
Published
A very simple module that helps convert time. Such as seconds to minutes.
Downloads
8
Readme
tc.js - Time Convert (Javascript Package)
very simple module that converts time. (Ex; ms -> seconds)
Documentation can be found in the docs folder.
Examples
Here is an example of how to convert time:
import { convert, floorConvert, roundConvert } from '@jacobhumston/tc.js';
const time = { minutes: 300, seconds: 30, milliseconds: 500 }; // Units of time to convert
console.log(convert(time).hours); // 5.008472222222222
console.log(roundConvert(time, 2).hours); // 5.01
console.log(floorConvert(time).hours); // 5
console.log(convertTo(time, 'seconds')); // 18030.5 (Same as "convert(time).seconds")You can also use a chain to simplify adding and subtracting units of time.
import { ChainConvert } from '@jacobhumston/tc.js';
const chain = new ChainConvert();
chain.add({ minutes: 1 }).subtract({ seconds: 30 }).add({ hours: 1 });
console.log(chain.floorConvert().seconds); // 3630There is also some utility functions included in the package.
import { createInterval, createTimeout } from '@jacobhumston/tc.js';
// Create a simple timeout
createTimeout(
function () {
console.log('2 seconds is up!');
},
{ seconds: 2 }
);
// Create a simple counter
let count = 0;
createInterval(
function () {
count++;
console.log(`Count: ${count}`); // Add 1 to the counter every minute
},
{ minutes: 1 }
);