HUGO
Menu
GitHub 90498 stars Mastodon

compare.Lt

Reports whether the first argument is less than all of the subsequent arguments.
Syntax
compare.Lt ARG1 ARG2 [ARG...]
Returns
bool
Alias
lt

Usage

The compare.Lt function reports whether the first argument is less than all of the subsequent arguments. Numbers are compared by value, regardless of type. You can also use this function to compare strings, boolean values, dates, and other comparable data types.

time.Time values are compared by the moment they represent, regardless of time zone. To compare date strings, such as custom date parameters in front matter, convert them with the time.AsTime function first.

Examples

{{ compare.Lt 1 1 }} → false
{{ compare.Lt 1 2 }} → true
{{ compare.Lt 2 1 }} → false

{{ compare.Lt 1 1 1 }} → false
{{ compare.Lt 1 1 2 }} → false
{{ compare.Lt 1 2 1 }} → false
{{ compare.Lt 1 2 2 }} → true

{{ compare.Lt 2 1 1 }} → false
{{ compare.Lt 2 1 2 }} → false
{{ compare.Lt 2 2 1 }} → false

Comparing numbers of different types:

{{ compare.Lt 1 1.0 }} → false

Comparing other data types:

{{ compare.Lt "ab" "a" }} → false
{{ compare.Lt now (time "1964-12-30") }} → false
{{ compare.Lt true false }} → false

Comparing moments in different time zones, where the later calendar date is the earlier moment:

{{ $utc := time.AsTime "2023-07-19T17:42:36Z" }}
{{ $tokyo := time.AsTime "2023-07-20T02:15:09" "Asia/Tokyo" }}
{{ compare.Lt $tokyo $utc }} → true