0.2.2 • Published 3 years ago
@wilkins-software/time-conversion-helpers v0.2.2
Time Conversion Helpers
A small library of helpers that convert one unit of time to another (roughly). For instance...
import { seconds } from '@wilkins-software/time-conversion-helpers';
const numberOfSeconds = minutes(2).toSeconds(); // 120
Badges
API Reference
Exported Functions
functions: Accepted time units
function | argument | Returns |
---|---|---|
seconds | numberOfSeconds | ConverterObject |
minutes | numberOfMinutes | ConverterObject |
hours | numberOfHours | ConverterObject |
days | numberOfDays | ConverterObject |
weeks | numberOfWeeks | ConverterObject |
months | numberOfMonths | ConverterObject |
years | numberOfYears | ConverterObject |
ConverterObject
The object returned by all time converters. It contains methods to convert to any other time unit:
Method | Returns |
---|---|
toMilliseconds() | number |
toSeconds() | number |
toMinutes() | number |
toHours() | number |
toDays() | number |
toWeeks() | number |
toMonths() | number |
toYears() | number |
Authors
Usage/Examples
Convert seconds to miliseconds for setTimeout()
import { seconds } from '@wilkins-software/time-conversion-helpers'
setTimeout(() => {
console.log('this will fire after 4 seconds');
}, seconds(4).toMilliseconds())
Convert days to seconds for a cache control header
import { days } from '@wilkins-software/time-conversion-helpers'
const headers = {
'Cache-Control': `max-age=${days(30).toSeconds()}`
}