@master4n/temporal-transformer
v1.1.0
Published
Epoch convertor
Downloads
17
Maintainers
Readme
@master4n/temporal-transformer
Temporal Transformer is a library that converts epoch values to human-readable dates and dates to epoch value in both the user's local timezone and GMT. The project uses the moment-timezone
library to handle date and time conversions and formatting.
Features
- Automatically detects the type of epoch (seconds, milliseconds, microseconds, nanoseconds).
- Converts epoch values to human-readable dates.
- Converts human-readable dates to epoch values.
- Displays dates in both the user's local timezone and GMT.
- User-friendly output with clear assumptions about the epoch type.
Installation
Library Installation:
npm install --save-dev @master4n/temporal-transformer
Usage
Method use to convert from epoch to date:
import { convertEpoch, EpochToDate } from @master4n/temporal-transformer const epoch = 1622547800000; // Example epoch value const data: EpochToDate = convertEpoch(epoch); // Default format 'YYYY-MM-DD HH:mm:ss' used. const data: EpochToDate = convertEpoch(epoch, 'YYYY-DD-MM HH:mm:ss'); // User provided formatted output
Method use to convert from date object to epoch:
import { convertDateToEpoch, DateToEpoch } from @master4n/temporal-transformer const date = new Date(); // Any date. const timezone = 'America/New_York' const data: DateToEpoch = convertDateToEpoch(date); // Default user timezone used for formatting. const data: DateToEpoch = convertDateToEpoch(date, timezone); // User provided timezone used for formatting
Credits
These definitions were written by Master4Novice.