Dates and durations
This section covers utilities for handling dates and durations using the dayjs
library and the tims
package. These tools allow you to manage time zones, format dates, and perform various date-related calculations easily.
Locale Configuration
The locale for dayjs
is determined by the environment variable BOT_LOCALE
. When set, the corresponding locale file is imported, and dayjs
is configured to use it. If the specified locale is incorrect, a warning is logged.
Time Zone Support
dayjs
is extended with time zone functionality using the timezone
plugin. You can set a default time zone using the BOT_TIMEZONE
environment variable.
Plugins
The following plugins are extended in dayjs
to enhance its capabilities:
UTC: Handle UTC time formatting and manipulation.
Relative Time: Display relative time (e.g., "2 hours ago").
Timezone: Manage different time zones effectively.
To Object: Convert date objects into simpler formats.
Usage of dayjs
dayjs
You can now utilize dayjs
for various date manipulations and formatting:
Example:
tims
Package
tims
PackageIn addition to dayjs
, all exports from the tims
package are available. This package provides additional utilities for displaying and calculating durations.
Example:
uptime
The uptime in milliseconds is provided from the utilities.
Example:
Last updated