![]() Based on the discussion in #71631, it is hotly contested whether the default JSON representation for a Go time.Duration should be the time.Duration.String format or a particular profile of ISO 8601. Regardless of the default, it seems clear that we should at least support ISO 8601 if specified via a format flag. Note that this CL does not alter the default representation. Unfortunately, ISO 8601 is a large and evolving standard with many optional extensions and optional restrictions. Thus, the term "ISO 8601 duration" unfortunately does not resolve to a particular grammar, nor one that is stable. However, there is precedence that we can follow in this matter. JSON finds its heritage in JavaScript and JavaScript is adding a Temporal.Duration type whose default JSON representation is ISO 8601. There is a well-specified grammar for their particular profile of ISO 8601, which is documented at: https://tc39.es/proposal-temporal/#prod-Duration This particular CL adds support for ISO 8601 according to the exact same grammar that JavaScript uses. While Temporal.Duration is technically still a proposal, it is already in stage 3 of the TC39 proposal process (i.e., "no changes to the proposal are expected" and "has been recommended for implementation") and therefore close to final adoption. One major concern with ISO 8601 is that it supports nominal date units like years, months, weeks, and days that do not have an accurate meaning without being anchored to a particular point in time and place on Earth. Fortunately, JavaScript (by default) avoids producing Temporal.Duration values with nominal units unless arithmetic in JavaScript explicitly sets a largestUnits value that is larger than "hours". In the Go implementation, we support syntactically parsing the full ISO 8601 grammar (according to JavaScript), but semantically report an error if nominal units are present. This ensures that ISO 8601 durations remain accurate so long as they only use the accurate units of hours, minutes, or seconds. Updates #71631 Change-Id: I983593662f2150461ebc486a5acfeb72f0286939 Reviewed-on: https://go-review.googlesource.com/c/go/+/682403 Reviewed-by: Daniel Martà <mvdan@mvdan.cc> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
go.env | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.