count-age
v3.1.2
Published
This tool counts differences between dates
Downloads
5
Maintainers
Readme
Count Age
This tool counts differences between dates
Install
npm i count-age
Usage:
import { countAge } from "count-age";
const myAge = countAge('2000-01-01T09:30:00.000Z');
I/O expectations
INPUT
Function can be provided by one input date or two.
- If this will be provided only first date, second will be defined as now and function will count difference between input date and now .
- If this will be provided two dates, function will count difference between provided dates.
Input dates can be string
for date creation, timestamp number
, or instance of next object:
type DateProps = {
years: number;
months: number;
days: number;
hours?: number;
minutes?: number;
seconds?: number;
};
OUTPUT
This function anyway returns object with status and message.
enum STATUS {
SUCCESS = 'SUCCESS',
ERROR = 'ERROR',
}
// error messages
enum MESSAGE {
invalid = 'Invalid Date',
startBiggerEnd = 'Start date is bigger than end date',
}
// success message
type templeteSuccessMessage = '{{ count }} year(s), {{ count }} month(s), {{ count }} day(s), {{ count }} hour(s), {{ count }} minute(s), {{ count }} second(s) have passed between dates: {{ date-start }} - {{ date-end }}'
Success result object also contains field result:
type result = {
difference: {
years: number;
months: number;
days: number;
hours: number;
minutes: number;
seconds: number;
};
startDate: string;
endDate: string;
}