date
PoolZero-dependency date library - Tree-shakeable alternative to date-fns and moment.js
dist
Functions
function format(date: Date, options?: FormatOptions): string
Format date using Intl.DateTimeFormat Leverages native Intl API for locale-aware formatting Zero dependencies, all formatting done natively
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
optionsoptional | FormatOptions | - Formatting options |
function formatISO(date: Date, options?: ISOFormatOptions): string
Format date as ISO 8601 string
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
optionsoptional | ISOFormatOptions | - ISO options |
function formatRelative(date: Date, baseDate?: Date, options?: RelativeTimeOptions): string
Format date as relative time ("2 hours ago", "in 3 days") Uses Intl.RelativeTimeFormat for locale-aware relative formatting
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
baseDateoptional | Date | - Base date to compare against (defaults to now) |
optionsoptional | RelativeTimeOptions | - Relative time options |
function parseISO(dateString: string): Date
Parse ISO 8601 date string Supports ISO 8601 and RFC 3339 formats
| Parameter | Type | Description |
|---|---|---|
dateString | string | - ISO 8601 or RFC 3339 string |
function add(date: Date, duration: Duration): Date
Add duration to date (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to add to |
duration | Duration | - Duration to add |
function subtract(date: Date, duration: Duration): Date
Subtract duration from date (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to subtract from |
duration | Duration | - Duration to subtract |
function startOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date
Get start of time unit (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to operate on |
unit | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | - Time unit ('year', 'month', 'day', 'hour', 'minute', 'second') |
function endOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date
Get end of time unit (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to operate on |
unit | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | - Time unit |
function isValid(date: Date): boolean
Check if date is valid
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to validate |
function diff(dateLeft: Date, dateRight: Date, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds'): number
Calculate difference between dates
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - Later date |
dateRight | Date | - Earlier date |
unit | 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds' | - Unit to return difference in |
function compare(dateLeft: Date, dateRight: Date): number
Compare two dates
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - First date |
dateRight | Date | - Second date |
function isEqual(dateLeft: Date, dateRight: Date): boolean
Check if dates are equal
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - First date |
dateRight | Date | - Second date |
function isBefore(date: Date, dateToCompare: Date): boolean
Check if date is before another
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to check |
dateToCompare | Date | - Date to compare against |
function isAfter(date: Date, dateToCompare: Date): boolean
Check if date is after another
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to check |
dateToCompare | Date | - Date to compare against |
dist
Functions
function format(date: Date, options?: FormatOptions): string
Format date using Intl.DateTimeFormat Leverages native Intl API for locale-aware formatting Zero dependencies, all formatting done natively
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
optionsoptional | FormatOptions | - Formatting options |
function formatISO(date: Date, options?: ISOFormatOptions): string
Format date as ISO 8601 string
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
optionsoptional | ISOFormatOptions | - ISO options |
function formatRelative(date: Date, baseDate?: Date, options?: RelativeTimeOptions): string
Format date as relative time ("2 hours ago", "in 3 days") Uses Intl.RelativeTimeFormat for locale-aware relative formatting
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to format |
baseDateoptional | Date | - Base date to compare against (defaults to now) |
optionsoptional | RelativeTimeOptions | - Relative time options |
function parseISO(dateString: string): Date
Parse ISO 8601 date string Supports ISO 8601 and RFC 3339 formats
| Parameter | Type | Description |
|---|---|---|
dateString | string | - ISO 8601 or RFC 3339 string |
function add(date: Date, duration: Duration): Date
Add duration to date (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to add to |
duration | Duration | - Duration to add |
function subtract(date: Date, duration: Duration): Date
Subtract duration from date (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to subtract from |
duration | Duration | - Duration to subtract |
function startOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date
Get start of time unit (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to operate on |
unit | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | - Time unit ('year', 'month', 'day', 'hour', 'minute', 'second') |
function endOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date
Get end of time unit (immutable)
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to operate on |
unit | 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | - Time unit |
function isValid(date: Date): boolean
Check if date is valid
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to validate |
function diff(dateLeft: Date, dateRight: Date, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds'): number
Calculate difference between dates
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - Later date |
dateRight | Date | - Earlier date |
unit | 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds' | - Unit to return difference in |
function compare(dateLeft: Date, dateRight: Date): number
Compare two dates
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - First date |
dateRight | Date | - Second date |
function isEqual(dateLeft: Date, dateRight: Date): boolean
Check if dates are equal
| Parameter | Type | Description |
|---|---|---|
dateLeft | Date | - First date |
dateRight | Date | - Second date |
function isBefore(date: Date, dateToCompare: Date): boolean
Check if date is before another
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to check |
dateToCompare | Date | - Date to compare against |
function isAfter(date: Date, dateToCompare: Date): boolean
Check if date is after another
| Parameter | Type | Description |
|---|---|---|
date | Date | - Date to check |
dateToCompare | Date | - Date to compare against |
Taxes calculated at checkout based on your location.