summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/time
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-11-13 11:07:57 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-11-13 11:07:57 +0100
commit3477d9fcec39d17f99cbc891e337658e8660f5db (patch)
tree4b315ea0ec6c804b40815e2a49911c4ef96681fd /docs/content/en/functions/time
parente79ee0d5167707d891c80906e71daa098c9e46af (diff)
parentde0df119b504a91c9e1f442b07954f366ffb2932 (diff)
downloadhugo-3477d9fcec39d17f99cbc891e337658e8660f5db.tar.gz
hugo-3477d9fcec39d17f99cbc891e337658e8660f5db.zip
Merge commit 'de0df119b504a91c9e1f442b07954f366ffb2932'
Diffstat (limited to 'docs/content/en/functions/time')
-rw-r--r--docs/content/en/functions/time/AsTime.md31
-rw-r--r--docs/content/en/functions/time/Format.md18
-rw-r--r--docs/content/en/functions/time/_common/parsable-date-time-strings.md16
3 files changed, 33 insertions, 32 deletions
diff --git a/docs/content/en/functions/time/AsTime.md b/docs/content/en/functions/time/AsTime.md
index 23e5304a5..70b2bd1f3 100644
--- a/docs/content/en/functions/time/AsTime.md
+++ b/docs/content/en/functions/time/AsTime.md
@@ -21,41 +21,34 @@ toc: true
Hugo provides [functions] and [methods] to format, localize, parse, compare, and manipulate date/time values. Before you can do any of these with string representations of date/time values, you must first convert them to [`time.Time`] values using the `time.AsTime` function.
```go-html-template
-{{ $t := "2023-10-15T14:20:28-07:00" }}
-{{ time.AsTime $t }} → 2023-10-15 14:20:28 -0700 PDT (time.Time)
+{{ $t := "2023-10-15T13:18:50-07:00" }}
+{{ time.AsTime $t }} → 2023-10-15 13:18:50 -0700 PDT (time.Time)
```
## Parsable strings
-As shown above, the first argument must be a *parsable* string representation of a date/time value. For example:
+As shown above, the first argument must be a parsable string representation of a date/time value. For example:
{{% include "functions/time/_common/parsable-date-time-strings.md" %}}
-## Time zones
+To override the default time zone, set the [`timeZone`] in your site configuration or provide a second argument to the `time.AsTime` function. For example:
-When the parsable string does not contain a time zone offset, you can do either of the following to assign a time zone other than Etc/UTC:
-
-- Provide a second argument to the `time.AsTime` function
-
- ```go-html-template
- {{ time.AsTime "15 Oct 2023" "America/Chicago" }}
- ```
-
-- Set the default time zone in your site configuration
+```go-html-template
+{{ time.AsTime "15 Oct 2023" "America/Los_Angeles" }}
+```
- {{< code-toggle file=hugo >}}
- timeZone = 'America/New_York'
- {{< /code-toggle >}}
+The list of valid time zones may be system dependent, but should include `UTC`, `Local`, or any location in the [IANA Time Zone database].
The order of precedence for determining the time zone is:
1. The time zone offset in the date/time string
-2. The time zone provide as the second argument to the `time.AsTime` function
+2. The time zone provided as the second argument to the `time.AsTime` function
3. The time zone specified in your site configuration
+4. The `Etc/UTC` time zone
-The list of valid time zones may be system dependent, but should include `UTC`, `Local`, or any location in the [IANA Time Zone database].
+[IANA Time Zone database]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
[`time.Time`]: https://pkg.go.dev/time#Time
+[`timeZone`]: https://gohugo.io/getting-started/configuration/#timezone
[functions]: /functions/time/
-[iana time zone database]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
[methods]: /methods/time/
diff --git a/docs/content/en/functions/time/Format.md b/docs/content/en/functions/time/Format.md
index 74384959b..b9db6905b 100644
--- a/docs/content/en/functions/time/Format.md
+++ b/docs/content/en/functions/time/Format.md
@@ -19,21 +19,29 @@ toc: true
Use the `time.Format` function with `time.Time` values:
```go-html-template
-{{ $t := time.AsTime "2023-02-27T23:44:58-08:00" }}
-{{ time.Format "2 Jan 2006" $t }} → 27 Feb 2023
+{{ $t := time.AsTime "2023-10-15T13:18:50-07:00" }}
+{{ time.Format "2 Jan 2006" $t }} → 15 Oct 2023
```
-Or use `time.Format` with a *parsable* string representation of a date/time value:
+Or use `time.Format` with a parsable string representation of a date/time value:
```go-html-template
-{{ $t := "27 Feb 2023" }}
-{{ time.Format "January 2, 2006" $t }} → February 27, 2023
+{{ $t := "15 Oct 2023" }}
+{{ time.Format "January 2, 2006" $t }} → October 15, 2023
```
Examples of parsable string representations:
{{% include "functions/time/_common/parsable-date-time-strings.md" %}}
+To override the default time zone, set the [`timeZone`] in your site configuration. The order of precedence for determining the time zone is:
+
+1. The time zone offset in the date/time string
+2. The time zone specified in your site configuration
+3. The `Etc/UTC` time zone
+
+[`timeZone`]: https://gohugo.io/getting-started/configuration/#timezone
+
## Layout string
{{% include "functions/_common/time-layout-string.md" %}}
diff --git a/docs/content/en/functions/time/_common/parsable-date-time-strings.md b/docs/content/en/functions/time/_common/parsable-date-time-strings.md
index a38b9983e..6d1633a6f 100644
--- a/docs/content/en/functions/time/_common/parsable-date-time-strings.md
+++ b/docs/content/en/functions/time/_common/parsable-date-time-strings.md
@@ -2,13 +2,13 @@
# Do not remove front matter.
---
-String representation|Time zone
+Format|Time zone
:--|:--
-2023-10-15T14:20:28-07:00|America/Los_Angeles
-2023-10-15T13:18:50-0700|America/Los_Angeles
-2023-10-15T13:18:50Z|Etc/UTC
-2023-10-15T13:18:50|Etc/UTC
-2023-10-15|Etc/UTC
-15 Oct 2023|Etc/UTC
+`2023-10-15T13:18:50-07:00`|`America/Los_Angeles`
+`2023-10-15T13:18:50-0700`|`America/Los_Angeles`
+`2023-10-15T13:18:50Z`|`Etc/UTC`
+`2023-10-15T13:18:50`|Default is `Etc/UTC`
+`2023-10-15`|Default is `Etc/UTC`
+`15 Oct 2023`|Default is `Etc/UTC`
-The last four examples are not fully qualified. Without a time zone offset, the time zone is set to Etc/UTC (Coordinated Universal Time).
+The last three examples are not fully qualified, and default to the `Etc/UTC` time zone.