Files
kumomta/docs/reference/template/timeformat.md
T
Wez Furlong 42bf5c5e61 docs: adjust reference to improve search terms
We've been hoping that mkdocs-material will ship the much anticipated
search enhancements for some time, but it's time to recognize that
we need to do something to improve the search results with how
things work right now.

This is a big commit that changes the titles of the various pages
from the code-annotated synopsis to just the name of the function.

This makes it much easier now to match things like `kumo.reject`
directly, but `reject` remains awkward to find.

I think this is the best that we can do at this time.

A few functions have been annotated with the `status: deprecated` to
show as deprecated in the toc/nav (shows with a little trash can next
to the name).
2025-05-16 14:02:19 -07:00

47 lines
1.5 KiB
Markdown

# timeformat
```rust
pub fn timeformat(
state: &State<'_, '_>,
value: Value,
kwargs: Kwargs,
) -> Result<String, Error>
```
Formats a timestamp as time.
The value needs to be a unix timestamp, or a parsable string (ISO 8601) or a
format supported by `chrono` or `time`.
The filter accepts two keyword arguments (`format` and `tz`) to influence the format
and the timezone. The default format is `"medium"`. The defaults for these keyword
arguments are taken from two global variables in the template context: `TIME_FORMAT`
and `TIMEZONE`. If the timezone is set to `"original"` or is not configured, then
the timezone of the value is retained. Otherwise the timezone is the name of a
timezone [from the database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
{% raw %}
```jinja
{{ value|timeformat }}
```
```jinja
{{ value|timeformat(format="short") }}
```
```jinja
{{ value|timeformat(format="short", tz="Europe/Vienna") }}
```
{% endraw %}
This filter currently uses the `time` crate to format dates and uses the format
string specification of that crate in version 2. For more information read the
[Format description documentation](https://time-rs.github.io/book/api/format-description.html).
Additionally some special formats are supported:
* `short` and `medium`: hour and minute (`16:37`)
* `long`: includes seconds too (`16:37:22`)
* `full`: includes subseconds too (`16:37:22.0`)
* `unix`: a unix timestamp in seconds only (`1687624642`)
* `iso`: date and time in iso format (`2023-06-24T16:37:22+00:00`)