dates
In Filters
Date-related filters for Eleventy.
import {
toISOString,
year,
dateFormat,
longDate,
shortDate,
relativeDate,
timeAgo,
} from '@allons-y/dashly/filters/dates';
toISOString(date)
Convert a date-like value to an ISO 8601 string. Returns an empty string for falsy inputs or unparseable dates.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
date
|
string | number | Date |
Returns
string
year(date)
Extract the four-digit year from a date-like value. Returns an empty string for falsy or unparseable inputs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
date
|
string | number | Date |
Returns
number | ''
dateFormat(value, options?, locale?)
Format a date using Intl.DateTimeFormat. Returns the input unchanged on
falsy or unparseable values so templates can render gracefully.
Defaults to timeZone: 'UTC' so a date-only string like '2026-01-15'
(which Date parses as midnight UTC) renders as "15 January" everywhere,
not "14 January" on machines west of Greenwich. Pass timeZone in
options to override.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number | Date |
||
options
(optional)
|
Intl.DateTimeFormatOptions |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
Returns
string | number | Date
: The formatted string, or value unchanged when it is falsy or unparseable.
longDate(value, locale?)
Format a date as a long-form date (e.g. "15 January 2026").
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number | Date |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
Returns
string | number | Date
: The formatted date, or value unchanged when it is falsy or unparseable.
shortDate(value, locale?)
Format a date as an abbreviated month-and-year (e.g. "Jan 2026").
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number | Date |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
Returns
string | number | Date
: The formatted date, or value unchanged when it is falsy or unparseable.
relativeDate(value, locale?, options?)
Format a date as a locale-aware relative phrase (e.g. "2 days ago",
"in 3 months"). Wraps Intl.RelativeTimeFormat.
The reference point is now by default but can be overridden — useful for
stable build output and for testing.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number | Date |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
|
options
(optional)
|
object |
||
options.now
(optional)
|
Date |
Reference date to compare against. Defaults to new Date(). |
|
options.style
(optional)
|
Intl.RelativeTimeFormatStyle |
'long' |
|
options.numeric
(optional)
|
'auto' | 'always' |
'auto' |
'auto' produces "yesterday" / "tomorrow"; 'always' forces "1 day ago". |
Returns
string
Examples
// 'yesterday'
relativeDate(new Date(Date.now() - 86_400_000));
// '2 mo. ago'
relativeDate('2026-01-15', 'en-US', { now: new Date('2026-03-20'), style: 'short' });
{{ post.date | timeAgo }}
timeAgo(value, locale?, options?)
Alias for relativeDate. Some teams prefer the | timeAgo name.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
string | number | Date |
||
locale
(optional)
|
Intl.LocalesArgument |
'en-US' |
|
options
(optional)
|
object |
||
options.now
(optional)
|
Date |
Reference date to compare against. Defaults to new Date(). |
|
options.style
(optional)
|
Intl.RelativeTimeFormatStyle |
'long' |
|
options.numeric
(optional)
|
'auto' | 'always' |
'auto' |
'auto' produces "yesterday" / "tomorrow"; 'always' forces "1 day ago". |
Returns
string
Examples
// 'yesterday'
relativeDate(new Date(Date.now() - 86_400_000));
// '2 mo. ago'
relativeDate('2026-01-15', 'en-US', { now: new Date('2026-03-20'), style: 'short' });
{{ post.date | timeAgo }}