epoch-handler
v1.2.1
Published
A simple epoch handling library for javascript
Downloads
1
Readme
Epoch-Handler
This is a simple javascript library to allow easy handling of epoch times. Follow the below usage to get started with this package.
Installation
npm i epoch-handler --save
Usage
| props | defaults | description |
| ------- | ----------- | ---------------------- |
| epoch | required | The epoch value must be provided there are is an import called getEpochTimeLocale
which can be imported from this package if you want to get the current epoch in seconds and then you will be able to add or subtract seconds from them. |
| type | null
| The type property allows you to access deaper functionality there is currently only on action that can be used which is time_until
which will return the amount of time remaining between two epoch values.|
| output | seconds
| You can choose between two output types, these are object
and seconds
. The object
setting returns an object containing hours, minutes and seconds between two epoch numbers. seconds
returns the amount of seconds as a number between the epoch value passed in and the currect time epoch. |
| format | null
| The format options can be found below this allows you format an epoch value to give it a more human readable output |
import {
epochHandler,
getEpochTimeLocale,
} from 'epoch-handler';
epochHandler({
epoch: 1593529909 || getEpochTimeLocale()+50,
type: 'time_until',
output: 'seconds'
})
Formatting
The seperators between the Day month year can be any value you like so feel free to use -
/
:
in the formatting string. This will also work for the hours minutes and seconds part of the string as well so fell free to use them as well.
| Valid Options | Return Value |
| --------------------- | ---------------------- |
| YYYY/MM/DD hh:mm:ss
| 2020/01/22 12:03:23
|
| DD/MM/YYYY hh:mm:ss
| 22/01/2020 12:03:23
|
| DD/MM/YY hh:mm:ss
| 22/01/2020 12:03:23
|
| YY/MM/DD hh:mm:ss
| 20/01/22 12:03:23
|
| DD/MM/YYYY
| 22/01/2020
|
| YYYY/MM/DD
| 2020/01/22
|
| YY/MM/DD
| 20/01/22
|
| hh:mm:ss
| 12:03:23
|
import {
epochHandler,
getEpochTimeLocale,
} from 'epoch-handler';
epochHandler({
epoch: 1593529909 || getEpochTimeLocale()+50,
format: 'YYYY/MM/DD hh:mm:ss'
})