Class: DateUtility

DateUtility()

Utility helpers for parsing, grouping, and formatting dates.

Constructor

new DateUtility()

Since:
  • 2.37.0
Source:

Methods

getRelativeDateString(value, referenceValue, optionsopt) → {string}

Return a human-readable string describing how much newer or older a date is compared to a reference date, e.g. "one day newer" or "two days older". It will resolve to seconds, minutes, hours, days, months, or years as appropriate. If the date is the same as the reference date, return "current".
Parameters:
Name Type Attributes Description
value string | number | Date Date-like value to compare.
referenceValue string | number | Date Date-like reference value.
options object <optional>
Formatting options.
Properties
Name Type Attributes Description
newerWord string <optional>
Set to customize the "newer" label, for example, "before". Defaults to "newer".
olderWord string <optional>
Set to customize the "older" label, for example, "after". Defaults to "older".
currentWord string <optional>
Set to customize the "current" label. For example, "right now". Defaults to "current".
Source:
Returns:
Relative date string, or empty string when invalid.
Type
string

isValidDate(value) → {boolean}

Check if a value is a valid Date instance.
Parameters:
Name Type Description
value * Candidate value.
Source:
Returns:
True when value is a valid Date.
Type
boolean

toDate(value) → {Date|null}

Convert a value into a Date.
Parameters:
Name Type Description
value string | number | Date Date-like value.
Source:
Returns:
Parsed Date or null when invalid.
Type
Date | null

toDayId(value, groupingTimeZoneopt, prefixopt) → {string}

Convert a date into a stable day identifier.
Parameters:
Name Type Attributes Default Description
value string | number | Date Date-like value.
groupingTimeZone "local" | "UTC" <optional>
local Day boundary mode.
prefix string <optional>
date Prefix to include in ID.
Source:
Returns:
Stable ID string.
Type
string

toISODateOnly(value, groupingTimeZoneopt) → {string}

Convert a date into a YYYY-MM-DD string.
Parameters:
Name Type Attributes Default Description
value string | number | Date Date-like value.
groupingTimeZone "local" | "UTC" <optional>
local Day boundary mode.
Source:
Returns:
Date-only string, or empty string when invalid.
Type
string

toISOString(value) → {string}

Convert a date-ish value into an ISO-8601 timestamp.
Parameters:
Name Type Description
value string | number | Date Date-like value.
Source:
Returns:
ISO timestamp or empty string when invalid.
Type
string

toLocalTimestampWithZone(value) → {string}

Format a local timestamp with a short timezone token.
Parameters:
Name Type Description
value string | number | Date Date-like value.
Source:
Returns:
Formatted timestamp or empty string when invalid.
Type
string

toLocaleDateString(value, optionsopt) → {string}

Format a date using locale-aware date formatting.
Parameters:
Name Type Attributes Description
value string | number | Date Date-like value.
options object <optional>
Formatting options.
Properties
Name Type Attributes Description
locale string <optional>
Locale override. Set to null to use the default locale.
formatOptions Intl.DateTimeFormatOptions <optional>
Options for date formatting. Defaults to { year: "numeric", month: "long", day: "numeric" }.
Source:
Returns:
Formatted date or empty string when invalid.
Type
string

toMidnightDate(value, groupingTimeZoneopt) → {Date|null}

Build a Date for start-of-day in the requested timezone mode.
Parameters:
Name Type Attributes Default Description
value string | number | Date Date-like value.
groupingTimeZone "local" | "UTC" <optional>
local Day boundary mode.
Source:
Returns:
Midnight Date or null when invalid.
Type
Date | null