Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@sineverba/date-convert

sineverba16MIT2.3.0TypeScript support: included

Convert a date from / to ISO format YYYYMMDD to human readable format (DD/MM/YYYY)

npm, package, date, format

readme

Date Convert

CI / CD Status
NPM npm version
Semaphore CI Build Status
Circle CI CircleCI
Coverall Coverage Status
SonarCloud Quality Gate Status

date-convert converts a ISO format YYYYMMDD string "19820405" to "05/04/1982" (where 05 is day and 04 is April). Use "/" as separator in output.

It works also with a date with other format. Simply, call the method fromIsoToHuman.

For example

const newDate = fromIsoToHuman("2024-01-31T15:27:42.427438", "DD/MM/YYYY");
console.log(newDate); // It prints 31/01/2024

Accepted INPUT

Input Output
"20220323" 23/03/2022
"2022-03-23" 23/03/2022
"2022-03-09T12:31:16.699904" 09/03/2022

Installation

npm install @sineverba/date-convert

Usage

// Import module
import { fromHumanToIso, fromIsoToHuman } from "@sineverba/date-convert";
// Or
// var {fromIsoToHuman, fromHumanToIso} = require('@sineverba/date-convert');

const humanDate = fromIsoToHuman("20200102");
console.log(humanDate); // returns 02/01/2020

const humanDateWithFormat = fromIsoToHuman("20200102", "YYYY-MM-DD");
console.log(humanDateWithFormat); // returns 2020-01-02

const isoDate = fromHumanToIso("02/01/2020");
console.log(isoDate); // returns 20200102

const isoDateWithFormat = fromHumanToIso("2020-01-02", "YYYY-MM-DD");
console.log(isoDateWithFormat); // returns 20200102

Tests

npm run test for simple test

npm run coverage for coverage

changelog

2.3.0

  • Upgrade dependencies
  • Upgrade dependencies
  • Migrate constants to ENUM

2.2.0

  • Upgrade dependencies
  • Change var to const in tests

2.1.0

  • Add Cucumber
  • Upgrade dependencies

2.0.0

  • Fix code smell
  • Upgrade dependencies
  • Move to TypeScript

1.4.0

  • Handle custom human date format
  • Upgrade dependencies

1.3.0

  • Upgrade dependencies
  • Add custom format

1.2.0

  • Fix deploy
  • Refactor Semaphore
  • Clean Semaphore - Upgrade dependencies
  • Add handle separator

1.1.0

  • Reorganize project and fix some trouble on CI/CD
  • Add SonarQube and fix some code smells
  • Upgrade dependencies

1.0.0

  • Change suite test
  • Add Circle CI

0.2.0

  • Move to Semaphore CI
  • Bump dependencies
  • Skip test on tagging

0.1.0

  • First version