utils-date-local v1.0.0
Installation
npm install @/utils-date-local
Usage
import { isValidDate, getFirstDateOfMonth, getEndDateOfMonth, getEndDateOfWeek, getEndTimeOfDay, getFirstDateOfWeek, getStartOfDay, formatMonth, formatWeek, formatDay, } from '@utils-date';
Functions
isValidDate(date: Date): boolean Checks if the input is a valid Date object.
getFirstDateOfMonth(date: Date): Date Returns the first date of the month for the given input date.
getEndDateOfMonth(date: Date): Date Returns the last date of the month for the given input date.
getEndDateOfWeek(date: Date): Date Returns the last date (Saturday) of the week for the given input date.
getEndTimeOfDay(date: Date): Date Returns the end time (23:59:59.999) of the input date.
getFirstDateOfWeek(date: Date): Date Returns the first date (Sunday) of the week for the given input date.
getStartOfDay(date: Date): Date Returns the start time (00:00:00.000) of the input date.
formatMonth(date: Date, options?: Object): string Formats the input date to display the month and year.
formatWeek(startDate: Date, endDate: Date, options?: Object): string Formats the start and end dates of a week into a readable string.
formatDay(date: Date, options?: Object): string Formats the input date to display the day, month, and year.
Examples
const currentDate = new Date(); const firstDateOfMonth = getFirstDateOfMonth(currentDate); const endOfWeek = getEndDateOfWeek(currentDate);
console.log(formatMonth(firstDateOfMonth)); // Output: "Jan 2023" console.log(formatWeek(currentDate, endOfWeek)); // Output: "Jan 15, 2023 - Jan 21, 2023"
5 months ago