@master4n/temporal-transformer
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@master4n/temporal-transformer

Owner Badge Package License Package Downloads

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

  1. Library Installation:

    npm install --save-dev @master4n/temporal-transformer

Usage

  1. 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
  2. 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.

Package Sidebar

Install

npm i @master4n/temporal-transformer

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

21.2 kB

Total Files

20

Last publish

Collaborators

  • master4novice