web / lib/utils/date
lib/utils/date
Provides utility functions for formatting and validating dates.
This module contains helpers to convert date strings or Date objects into consistent, human-readable formats for display in the user interface. It handles null or invalid date inputs gracefully and provides options for both long (date and time) and short (date only) formats.
Functions
isValidDate()
isValidDate(
date):boolean
Check if a Date object is valid.
Parameters
date
Date
Date object to validate
Returns
boolean
True if the date is valid, false if invalid (NaN time)
Example
const date = new Date('invalid');
isValidDate(date); // Returns false
const validDate = new Date('2024-01-15');
isValidDate(validDate); // Returns truehasInvalidIsoDatePart()
hasInvalidIsoDatePart(
date):boolean
Parameters
date
string
Returns
boolean
parseDateInput()
parseDateInput(
date):Date|null
Parameters
date
string | number | Date | null | undefined
Returns
Date | null
formatDate()
formatDate(
date,options?):string
Parameters
date
DateInput
options?
includeTime?
boolean
Returns
string
formatDateShort()
formatDateShort(
date):string
Format a date for short display (just the date, no time).
Parameters
date
string | Date | null | undefined
Returns
string
formatLongDate()
formatLongDate(
date,includeTime?):string
Format a date in long format with weekday, suitable for emails and notifications.
Parameters
date
Date to format
string | Date | null | undefined
includeTime?
boolean = false
Whether to include hour and minute (default: false)
Returns
string
Formatted date string like “Saturday, March 15, 2026” or “Unknown” if invalid