Document time.Truncate and time.Round

This commit is contained in:
Joe Mooring
2024-04-18 09:02:32 -07:00
committed by GitHub
parent 76a1263e7f
commit 8085d85e38
3 changed files with 51 additions and 0 deletions
+5
View File
@@ -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.
+24
View File
@@ -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
+22
View File
@@ -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