aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Watkins <marwatk@marcuswatkins.net>2022-07-21 12:38:51 -0600
committerGopher Robot <gobot@golang.org>2022-07-25 16:15:08 +0000
commitdcea1ee6e3b805c2967950d48fddff5c69d2af85 (patch)
tree3301d803808eb25bf9538ef32a85a9ce7753888d
parent37c8112b825a2c60d1b3776c0b4f4c643391d490 (diff)
downloadgo-dcea1ee6e3b805c2967950d48fddff5c69d2af85.tar.gz
go-dcea1ee6e3b805c2967950d48fddff5c69d2af85.zip
time: clarify documentation for allowed formats and add tests to prove them
The existing documentation for the time.Layout const states "Only these values are recognized", but then doesn't include the numeric forms for month leading to ambiguity and assumptions that may not be true. It's unclear, for example, that space padding is only available for day of the month. Finally I add tests to show the behaviors in specific scenarios. Change-Id: I4e08a14834c17b6bdf3b6b47d39dafa8c1a138fb Reviewed-on: https://go-review.googlesource.com/c/go/+/418875 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
-rw-r--r--src/time/format.go8
-rw-r--r--src/time/format_test.go7
2 files changed, 11 insertions, 4 deletions
diff --git a/src/time/format.go b/src/time/format.go
index 5f696189ff..8431ff89b4 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -53,10 +53,10 @@ import "errors"
// verbatim in the input to Parse.
//
// Year: "2006" "06"
-// Month: "Jan" "January"
-// Textual day of the week: "Mon" "Monday"
-// Numeric day of the month: "2" "_2" "02"
-// Numeric day of the year: "__2" "002"
+// Month: "Jan" "January" "01" "1"
+// Day of the week: "Mon" "Monday"
+// Day of the month: "2" "_2" "02"
+// Day of the year: "__2" "002"
// Hour: "15" "3" "03" (PM or AM)
// Minute: "4" "04"
// Second: "5" "05"
diff --git a/src/time/format_test.go b/src/time/format_test.go
index ab72fae323..9ae2b8017a 100644
--- a/src/time/format_test.go
+++ b/src/time/format_test.go
@@ -116,6 +116,13 @@ var formatTests = []FormatTest{
{"StampMicro", StampMicro, "Feb 4 21:00:57.012345"},
{"StampNano", StampNano, "Feb 4 21:00:57.012345600"},
{"YearDay", "Jan 2 002 __2 2", "Feb 4 035 35 4"},
+ {"Year", "2006 6 06 _6 __6 ___6", "2009 6 09 _6 __6 ___6"},
+ {"Month", "Jan January 1 01 _1", "Feb February 2 02 _2"},
+ {"DayOfMonth", "2 02 _2 __2", "4 04 4 35"},
+ {"DayOfWeek", "Mon Monday", "Wed Wednesday"},
+ {"Hour", "15 3 03 _3", "21 9 09 _9"},
+ {"Minute", "4 04 _4", "0 00 _0"},
+ {"Second", "5 05 _5", "57 57 _57"},
}
func TestFormat(t *testing.T) {