diff --git a/content/en/getting-started/glossary.md b/content/en/getting-started/glossary.md index dcbc228ae..c9a965f7c 100644 --- a/content/en/getting-started/glossary.md +++ b/content/en/getting-started/glossary.md @@ -32,6 +32,7 @@ weight: 60 [U](#unmarshal)  [V](#variable)  [W](#walk)  +[Z](#zero-time)  ###### action @@ -446,3 +447,7 @@ Used to position an element within a collection sorted by weight. Assign weights ###### weighted page Contained within a [taxonomy object](#taxonomy-object), a weighted page is a [map](#map) with two elements: a `Page` object, and its [taxonomic weight](#taxonomic-weight) as defined in front matter. Access the elements using the `Page` and `Weight` keys. + +###### zero time + +The _zero time_ is January 1, 0001, 00:00:00 UTC. Formatted per [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) the _zero time_ is 0001-01-01T00:00:00-00:00. diff --git a/content/en/methods/time/Round.md b/content/en/methods/time/Round.md new file mode 100644 index 000000000..543152031 --- /dev/null +++ b/content/en/methods/time/Round.md @@ -0,0 +1,24 @@ +--- +title: Round +description: Returns the result of rounding TIME to the nearest multiple of DURATION since January 1, 0001, 00:00:00 UTC. +categories: [] +keywords: [] +action: + related: + - functions/time/AsTime + returnType: time.Time + signatures: [TIME.Round DURATION] +--- + +The rounding behavior for halfway values is to round up. + +The `Round` method operates on TIME as an absolute duration since the [zero time]; it does not operate on the presentation form of the time. If DURATION is a multiple of one hour, `Round` may return a time with a non-zero minute, depending on the time zone. + +```go-html-template +{{ $t := time.AsTime "2023-01-27T23:44:58-08:00" }} +{{ $d := time.ParseDuration "1h"}} + +{{ ($t.Round $d).Format "2006-01-02T15:04:05-00:00" }} → 2023-01-28T00:00:00-00:00 +``` + +[zero time]: /getting-started/glossary/#zero-time diff --git a/content/en/methods/time/Truncate.md b/content/en/methods/time/Truncate.md new file mode 100644 index 000000000..f88460e28 --- /dev/null +++ b/content/en/methods/time/Truncate.md @@ -0,0 +1,22 @@ +--- +title: Truncate +description: Returns the result of rounding TIME down to a multiple of DURATION since January 1, 0001, 00:00:00 UTC. +categories: [] +keywords: [] +action: + related: + - functions/time/AsTime + returnType: time.Time + signatures: [TIME.Truncate DURATION] +--- + +The `Truncate` method operates on TIME as an absolute duration since the [zero time]; it does not operate on the presentation form of the time. If DURATION is a multiple of one hour, `Truncate` may return a time with a non-zero minute, depending on the time zone. + +```go-html-template +{{ $t := time.AsTime "2023-01-27T23:44:58-08:00" }} +{{ $d := time.ParseDuration "1h"}} + +{{ ($t.Truncate $d).Format "2006-01-02T15:04:05-00:00" }} → 2023-01-27T23:00:00-00:00 +``` + +[zero time]: /getting-started/glossary/#zero-time