@mesa-libs/dates
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Date Manager

Mesa Mobile Thinking

Description

This library have to be used in backend projects to work with dates. It is going to standardize the way all projects work with dates. This libbrary uses dayjs to work with dates.

How it works?

This library exports only one class with static methods, so the only thing you have to do is import the class and call its methods.

Getting current date

This method returns the current date as an iso string

import { DateManager } from '@mesa-libs/dates';

const currentate = DateManager.now();

console.log(currentate); // expected output: string with current date in iso 8601 format. Eg: 2019-01-25T02:00:00.000Z

Getting a formatted date

This method returns the sent date with the format sent. If any format were sent the default format is going to be 'YYYY-MM-DD'.

import { DateManager } from '@mesa-libs/dates';

const date = DateManager.formatDate('2023-12-21 23:34:01', 'DD-MM-YYYY HH:mm:ss');

console.log(date); // expected output: 21-12-2023 23:34:01


const date = DateManager.formatDate('2023-12-21', 'DD-MM-YYYY');

console.log(date); // expected output: 21-12-2023


const date = DateManager.formatDate('2023-12-21', 'DD-MM-YY');

console.log(date); // expected output: 21-12-23


const date = DateManager.formatDate('2023-12-21');

console.log(date); // expected output: 2023-12-21

cheking if the sent date is expired

This method returns TRUE when a date is expired and false if the date is not expired.

import { DateManager } from '@mesa-libs/dates';

// considering current date as 2024-01-01

// testing current date
const expired = DateManager.isExpired('2024-01-01');

console.log(expired); // expected output: FALSE


// testing a past date
const expired = DateManager.isExpired('2023-12-21');

console.log(expired); // expected output: FALSE


// testing a future date
const expired = DateManager.isExpired('2024-12-21');

console.log(expired); // expected output: TRUE

Readme

Keywords

none

Package Sidebar

Install

npm i @mesa-libs/dates

Weekly Downloads

0

Version

1.0.5

License

MIT License

Unpacked Size

38.3 kB

Total Files

7

Last publish

Collaborators

  • tiagomuniz1