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