Module: time_helpers

Helpers for time-related operations

Classes

WaitTime

Methods

(inner) ageInMS(startTime, endTimeopt) → {number}

Compute the age in milliseconds from a date to now or an optional end time.
Parameters:
Name Type Attributes Description
startTime DateArg The time to calculate the age from.
endTime DateArg <optional>
Optional end time to calculate the age to (defaults to now)
Returns:
The age in milliseconds, or -1 if the start time is invalid.
Type
number

(inner) ageString(date) → {string}

Make a nice string like "in 2.5 minutes" representing time from a date to now.
Parameters:
Name Type Description
date DateArg The date to calculate the age from.
Returns:
A string representing the age in seconds, formatted to 1 decimal place.
Type
string

(inner) coerceDate(date) → {Optional.<Date>}

Coerce a string or number into a Date object.
Parameters:
Name Type Description
date DateArg The date to coerce.
Returns:
A Date object if coercion is successful, or null if the input is invalid.
Type
Optional.<Date>

(inner) mostRecent(…args) → {Optional.<Date>}

Returns the most recent (latest) date from a list of Date or null values.
Parameters:
Name Type Attributes Description
args Array.<DateArg> <repeatable>
Dates to compare.
Returns:
The most recent date, or null if none are valid.
Type
Optional.<Date>

(inner) nowString() → {string}

String for the current time in local datetime format, e.g. ""17/06/2025 17:59:58""
Returns:
Localized current date and time string
Type
string

(inner) quotedISOFmt(date, withMillisecondsopt) → {string}

Returns the ISO format of a date, wrapped in quotes.
Parameters:
Name Type Attributes Description
date DateArg The date to format.
withMilliseconds boolean <optional>
Whether to include milliseconds in the output.
Returns:
The quoted ISO format string, or NULL if date is null.
Type
string

(async, inner) sleep(milliseconds) → {Promise.<void>}

Asynchronous sleep helper that pauses execution for the specified number of milliseconds.
Parameters:
Name Type Description
milliseconds number The number of milliseconds to sleep.
Returns:
A promise that resolves after the specified time.
Type
Promise.<void>

(inner) subtractSeconds(date, seconds) → {Date}

Subtracts a number of seconds from a date and returns the new Date.
Parameters:
Name Type Description
date Date The original date.
seconds number The number of seconds to subtract.
Returns:
The new date with seconds subtracted.
Type
Date

(inner) timeString(_timestamp, localeopt) → {string}

Generate a string representing a timestamp. (new Date()).toLocaleDateString('en-us', { weekday: "long", year: "numeric", month: "short", day: "numeric"}) => 'Thursday, Sep 1, 2022'
Parameters:
Name Type Attributes Description
_timestamp DateArg The timestamp to convert to a string.
locale string <optional>
Optional locale string for formatting the date.
Returns:
A formatted string representing the timestamp, or NULL if the timestamp is invalid.
Type
string

(inner) timelineCutoffAt() → {Date}

Returns the oldest timestamp to use as a cutoff for timeline toots, based on config settings.
Returns:
The cutoff date for timeline toots.
Type
Date

(inner) toISOFormat(date, withMillisecondsopt) → {string}

Date to the format YYYY-MM-DDTHH:MM:SSZ
Parameters:
Name Type Attributes Default Description
date DateArg The date to convert to ISO format.
withMilliseconds boolean <optional>
false If true, includes milliseconds in the output.
Returns:
The date in ISO format, or NULL if the date is invalid.
Type
string

(inner) toISOFormatIfExists()

Like toISOFormat() but returns null if the date is undefined or null.