Function fluent_datetime::DATETIME

source ·
pub fn DATETIME<'a>(
    positional: &[FluentValue<'a>],
    named: &FluentArgs<'_>
) -> FluentValue<'a>
Expand description

A Fluent function for formatted datetimes

Normally you would register this using BundleExt::add_datetime_support; you would not use it directly.

However, some frameworks like l10n require functions to be set up like this:

l10n::init!({
    functions: { "DATETIME": fluent_datetime::DATETIME }
});

Usage

today-is = Today is {$date}
today-is-fulldate = Today is {DATETIME($date, dateStyle: "full")}
now-is-time = Now is {DATETIME($date, timeStyle: "medium")}
now-is-datetime = Now is {DATETIME($date, dateStyle: "full", timeStyle: "short")}

See DATETIME in the Fluent guide and the Intl.DateTimeFormat constructor from ECMA 402 for how to use this inside a Fluent document.

We currently implement only a subset of the formatting options:

  • dateStyle
  • timeStyle

Unknown options and extra positional arguments are ignored, unknown values of known options cause the date to be returned as-is.