Date Utility Functions Documentation

This npm package offers various utility functions for managing dates in TypeScript. Below, you'll find detailed descriptions of each function along with code examples demonstrating their usage.

formatDate

Formats a date object into a string based on the provided format.

Parameters

Returns

The formatted date string.

Example

const { formatDate } = require('auxin');

const date = new Date();
const formattedDate = formatDate(date, 'YYYY-MM-DD HH:mm:ss');
console.log(formattedDate); // Output: '2024-04-21 12:30:45'

getCurrentDateTime

Gets the current date and time formatted as a string according to the specified format.

Parameters

Returns

The formatted current date and time string.

Example

const { getCurrentDateTime } = require('auxin');

const formattedDateTime = getCurrentDateTime('YYYY-MM-DD HH:mm:ss');
console.log(formattedDateTime); // Output: '2024-04-21 12:30:45'

parseDate

Parses a date string and returns a Date object.

Parameters

Returns

The parsed Date object, or null if parsing fails.

Example

const { parseDate } = require('auxin');

const dateString = '2024-04-21';
const parsedDate = parseDate(dateString);
console.log(parsedDate); // Output: Date object for '2024-04-21'

isLeapYear

Checks if a given year is a leap year.

Parameters

Returns

True if the year is a leap year, false otherwise.

Example

const { isLeapYear } = require('auxin');

const year = 2024;
const isLeap = isLeapYear(year);
console.log(isLeap); // Output: true