1
0
mirror of https://github.com/golang/go synced 2024-11-07 05:46:17 -07:00
go/src/time
Kevin Burke bb09f8a29b time: make time.Time print a valid Go string with %#v
Previously calling fmt.Sprintf("%#v", t) on a time.Time value would
yield a result like:

    time.Time{wall:0x0, ext:63724924180, loc:(*time.Location)(nil)}

which does not compile when embedded in a Go program, and does not
tell you what value is represented at a glance.

This change adds a GoString method that returns much more legible
output:

    "time.Date(2009, time.February, 5, 5, 0, 57, 12345600, time.UTC)"

which gives you more information about the time.Time and also can be
usefully embedded in a Go program without additional work.

Update Quote() to hex escape non-ASCII characters (copying logic
from strconv), which makes it safer to embed them in the output of
GoString().

Fixes #39034.

Change-Id: Ic985bafe4e556f64e82223c643f65143c9a45c3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/267017
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
2021-05-02 20:59:26 +00:00
..
testdata time: move slim test tzdata to testdata directory 2021-04-14 19:38:36 +00:00
tzdata all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
embed.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
example_test.go
export_android_test.go
export_test.go time: properly quote strings containing quotes and backslashes 2021-04-06 19:18:47 +00:00
export_windows_test.go
format_test.go time: make time.Time print a valid Go string with %#v 2021-05-02 20:59:26 +00:00
format.go time: make time.Time print a valid Go string with %#v 2021-05-02 20:59:26 +00:00
genzabbrs.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
internal_test.go time: check int64 overflow in Time.addSec 2021-03-17 19:48:52 +00:00
mono_test.go
sleep_test.go runtime, time: disable preemption in addtimer 2021-03-10 21:49:24 +00:00
sleep.go
sys_plan9.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
sys_unix.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
sys_windows.go
tick_test.go time: increase slop for TestTicker 2021-04-27 19:37:31 +00:00
tick.go
time_test.go time: add Time.Unix{Milli,Micro} and to-Time helpers UnixMicro, UnixMilli 2021-03-27 05:38:26 +00:00
time.go time: add Time.Unix{Milli,Micro} and to-Time helpers UnixMicro, UnixMilli 2021-03-27 05:38:26 +00:00
tzdata_test.go
zoneinfo_abbrs_windows.go
zoneinfo_android_test.go
zoneinfo_android.go
zoneinfo_ios.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
zoneinfo_js.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
zoneinfo_plan9.go
zoneinfo_read.go time: use offset and isDST when caching zone from extend string 2021-04-05 18:52:42 +00:00
zoneinfo_test.go time: add missing "os" import to zoneinfo_test.go 2021-04-15 00:40:43 +00:00
zoneinfo_unix_test.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
zoneinfo_unix.go all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
zoneinfo_windows_test.go
zoneinfo_windows.go
zoneinfo.go time: add Time.IsDST() to check if its Location is in Daylight Savings Time 2021-03-15 23:56:07 +00:00