aboutsummaryrefslogtreecommitdiff
path: root/src/time/format.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2022-08-22 13:33:56 -0700
committerGopher Robot <gobot@golang.org>2022-08-29 19:29:37 +0000
commit4029124cf4e79ed6f1c6d4cc0a19331eeddd58a6 (patch)
treeb6933195eb33bc73038732e058e36922a19cdf6b /src/time/format.go
parent68b10c2bb8ab95397c70b32ce7c3373eaa6ae9ce (diff)
downloadgo-4029124cf4e79ed6f1c6d4cc0a19331eeddd58a6.tar.xz
time: add fuzz test for Time.appendFormatRFC3339
Time.appendFormatRFC3339 is a specialized implementation of Time.appendFormat. We expect the two to be identical. Add a fuzz test to ensure this property. Updates #54093 Change-Id: I0bc41ee6e016d3dac75d1ac372d8c9c7266d0299 Reviewed-on: https://go-review.googlesource.com/c/go/+/425100 Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/time/format.go')
-rw-r--r--src/time/format.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/time/format.go b/src/time/format.go
index c32861c6db..6d5da323dc 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -618,6 +618,17 @@ func (t Time) Format(layout string) string {
// AppendFormat is like Format but appends the textual
// representation to b and returns the extended buffer.
func (t Time) AppendFormat(b []byte, layout string) []byte {
+ switch layout {
+ case RFC3339:
+ return t.appendFormatRFC3339(b, false)
+ case RFC3339Nano:
+ return t.appendFormatRFC3339(b, true)
+ default:
+ return t.appendFormat(b, layout)
+ }
+}
+
+func (t Time) appendFormat(b []byte, layout string) []byte {
var (
name, offset, abs = t.locabs()
@@ -630,14 +641,6 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
sec int
)
- // Handle most frequent layouts separately.
- switch layout {
- case RFC3339:
- return t.appendFormatRFC3339(b, abs, offset, false)
- case RFC3339Nano:
- return t.appendFormatRFC3339(b, abs, offset, true)
- }
-
// Each iteration generates one std value.
for layout != "" {
prefix, std, suffix := nextStdChunk(layout)
@@ -793,7 +796,9 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
return b
}
-func (t Time) appendFormatRFC3339(b []byte, abs uint64, offset int, nanos bool) []byte {
+func (t Time) appendFormatRFC3339(b []byte, nanos bool) []byte {
+ _, offset, abs := t.locabs()
+
// Format date.
year, month, day, _ := absDate(abs, true)
b = appendInt(b, year, 4)