Skip to content

Commit 0981d9f

Browse files
dsnetgopherbot
authored andcommitted
time: add DateTime, DateOnly, and TimeOnly
Add named constants for the 3rd, 4th, and 13th most popular formats. Fixes #52746 Change-Id: I7ce92e44dcae18c089124f1d6f5bc2d6359d436c Reviewed-on: https://go-review.googlesource.com/c/go/+/412495 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Joseph Tsai <[email protected]>
1 parent 662a729 commit 0981d9f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

api/next/52746.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pkg time, const DateOnly = "2006-01-02" #52746
2+
pkg time, const DateOnly ideal-string #52746
3+
pkg time, const DateTime = "2006-01-02 15:04:05" #52746
4+
pkg time, const DateTime ideal-string #52746
5+
pkg time, const TimeOnly = "15:04:05" #52746
6+
pkg time, const TimeOnly ideal-string #52746

src/time/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ const (
116116
StampMilli = "Jan _2 15:04:05.000"
117117
StampMicro = "Jan _2 15:04:05.000000"
118118
StampNano = "Jan _2 15:04:05.000000000"
119+
DateTime = "2006-01-02 15:04:05"
120+
DateOnly = "2006-01-02"
121+
TimeOnly = "15:04:05"
119122
)
120123

121124
const (

src/time/format_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ var formatTests = []FormatTest{
115115
{"StampMilli", StampMilli, "Feb 4 21:00:57.012"},
116116
{"StampMicro", StampMicro, "Feb 4 21:00:57.012345"},
117117
{"StampNano", StampNano, "Feb 4 21:00:57.012345600"},
118+
{"DateTime", DateTime, "2009-02-04 21:00:57"},
119+
{"DateOnly", DateOnly, "2009-02-04"},
120+
{"TimeOnly", TimeOnly, "21:00:57"},
118121
{"YearDay", "Jan 2 002 __2 2", "Feb 4 035 35 4"},
119122
{"Year", "2006 6 06 _6 __6 ___6", "2009 6 09 _6 __6 ___6"},
120123
{"Month", "Jan January 1 01 _1", "Feb February 2 02 _2"},

0 commit comments

Comments
 (0)