mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722'
This commit is contained in:
@@ -27,7 +27,7 @@ aliases: [/methods/time/format]
|
||||
To [localize] the return value, use the [`time.Format`] function instead.
|
||||
|
||||
[localize]: /getting-started/glossary/#localization
|
||||
[`time.Format`]: /functions/time/format
|
||||
[`time.Format`]: /functions/time/format/
|
||||
{{% /note %}}
|
||||
|
||||
Use the `Format` method with any `time.Time` value, including the four predefined front matter dates:
|
||||
@@ -44,7 +44,7 @@ Use the `Format` method with any `time.Time` value, including the four predefine
|
||||
{{% note %}}
|
||||
Use the [`time.Format`] function to format string representations of dates, and to format raw TOML dates that exclude time and time zone offset.
|
||||
|
||||
[`time.Format`]: /functions/time/format
|
||||
[`time.Format`]: /functions/time/format/
|
||||
{{% /note %}}
|
||||
|
||||
## Layout string
|
||||
|
26
docs/content/en/methods/time/Round.md
Normal file
26
docs/content/en/methods/time/Round.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
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
|
||||
- functions/time/ParseDuration
|
||||
- methods/time/Truncate
|
||||
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
|
24
docs/content/en/methods/time/Truncate.md
Normal file
24
docs/content/en/methods/time/Truncate.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
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
|
||||
- functions/time/ParseDuration
|
||||
- methods/time/Round
|
||||
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
|
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: YearDay
|
||||
description: Returns the day of the year of the given time.Time value, in the range [1, 365] for non-leap years, and [1,366] in leap years.
|
||||
description: Returns the day of the year of the given time.Time value, in the range [1, 365] for non-leap years, and [1, 366] in leap years.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
Reference in New Issue
Block a user