aboutsummaryrefslogtreecommitdiff
path: root/src/time/format.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-01-03 10:24:29 -0800
committerIan Lance Taylor <iant@golang.org>2018-01-03 20:50:44 +0000
commit86cca11ffde0a4a353f0cc7bf7cfcdffd7929398 (patch)
treeb0ce4afebc5e1db6ac330031f5e3cab406dc1ae2 /src/time/format.go
parent74d8340cf6d8fc958992ded4ffb6c4a53327dfa1 (diff)
downloadgo-86cca11ffde0a4a353f0cc7bf7cfcdffd7929398.tar.gz
go-86cca11ffde0a4a353f0cc7bf7cfcdffd7929398.zip
time: revert CL 78735 (was: space padding using underscore)
CL 78735 description: time: add space padding layout strings(using underscore) for not only day but others As mentioned in #22802, only day component of layout string has space padding(represented by one underscore before its placeholder). This commit expands the rule for month, hour, minute and second. Updates #22802 (maybe fixes it) Revert this CL because it breaks currently working formats that happen to use underscores. Fixes #23259 Change-Id: I64acaaca9b5b74785ee0f0be7910574e87daa649 Reviewed-on: https://go-review.googlesource.com/85998 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/time/format.go')
-rw-r--r--src/time/format.go72
1 files changed, 10 insertions, 62 deletions
diff --git a/src/time/format.go b/src/time/format.go
index 4f28e3be0c..a60474f026 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -90,7 +90,6 @@ const (
stdLongMonth = iota + stdNeedDate // "January"
stdMonth // "Jan"
stdNumMonth // "1"
- stdUnderMonth // "_1"
stdZeroMonth // "01"
stdLongWeekDay // "Monday"
stdWeekDay // "Mon"
@@ -99,13 +98,10 @@ const (
stdZeroDay // "02"
stdHour = iota + stdNeedClock // "15"
stdHour12 // "3"
- stdUnderHour12 // "_3"
stdZeroHour12 // "03"
stdMinute // "4"
- stdUnderMinute // "_4"
stdZeroMinute // "04"
stdSecond // "5"
- stdUnderSecond // "_5"
stdZeroSecond // "05"
stdLongYear = iota + stdNeedDate // "2006"
stdYear // "06"
@@ -191,24 +187,13 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
}
return layout[0:i], stdDay, layout[i+1:]
- case '_': // _1, _2, _2006, _3, _4, _5
- if len(layout) >= i+2 {
- switch layout[i+1] {
- case '1':
- return layout[0:i], stdUnderMonth, layout[i+2:]
- case '2':
- //_2006 is really a literal _, followed by stdLongYear
- if len(layout) >= i+5 && layout[i+1:i+5] == "2006" {
- return layout[0 : i+1], stdLongYear, layout[i+5:]
- }
- return layout[0:i], stdUnderDay, layout[i+2:]
- case '3':
- return layout[0:i], stdUnderHour12, layout[i+2:]
- case '4':
- return layout[0:i], stdUnderMinute, layout[i+2:]
- case '5':
- return layout[0:i], stdUnderSecond, layout[i+2:]
+ case '_': // _2, _2006
+ if len(layout) >= i+2 && layout[i+1] == '2' {
+ //_2006 is really a literal _, followed by stdLongYear
+ if len(layout) >= i+5 && layout[i+1:i+5] == "2006" {
+ return layout[0 : i+1], stdLongYear, layout[i+5:]
}
+ return layout[0:i], stdUnderDay, layout[i+2:]
}
case '3':
@@ -559,11 +544,6 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
b = append(b, m...)
case stdNumMonth:
b = appendInt(b, int(month), 0)
- case stdUnderMonth:
- if month < 10 {
- b = append(b, ' ')
- }
- b = appendInt(b, int(month), 0)
case stdZeroMonth:
b = appendInt(b, int(month), 2)
case stdWeekDay:
@@ -589,16 +569,6 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
hr = 12
}
b = appendInt(b, hr, 0)
- case stdUnderHour12:
- // Noon is 12PM, midnight is 12AM.
- hr := hour % 12
- if hr == 0 {
- hr = 12
- }
- if hr < 10 {
- b = append(b, ' ')
- }
- b = appendInt(b, hr, 0)
case stdZeroHour12:
// Noon is 12PM, midnight is 12AM.
hr := hour % 12
@@ -608,20 +578,10 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
b = appendInt(b, hr, 2)
case stdMinute:
b = appendInt(b, min, 0)
- case stdUnderMinute:
- if min < 10 {
- b = append(b, ' ')
- }
- b = appendInt(b, min, 0)
case stdZeroMinute:
b = appendInt(b, min, 2)
case stdSecond:
b = appendInt(b, sec, 0)
- case stdUnderSecond:
- if sec < 10 {
- b = append(b, ' ')
- }
- b = appendInt(b, sec, 0)
case stdZeroSecond:
b = appendInt(b, sec, 2)
case stdPM:
@@ -886,10 +846,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
case stdLongMonth:
month, value, err = lookup(longMonthNames, value)
month++
- case stdNumMonth, stdUnderMonth, stdZeroMonth:
- if std == stdUnderMonth && len(value) > 0 && value[0] == ' ' {
- value = value[1:]
- }
+ case stdNumMonth, stdZeroMonth:
month, value, err = getnum(value, std == stdZeroMonth)
if month <= 0 || 12 < month {
rangeErrString = "month"
@@ -913,26 +870,17 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
if hour < 0 || 24 <= hour {
rangeErrString = "hour"
}
- case stdHour12, stdUnderHour12, stdZeroHour12:
- if std == stdUnderHour12 && len(value) > 0 && value[0] == ' ' {
- value = value[1:]
- }
+ case stdHour12, stdZeroHour12:
hour, value, err = getnum(value, std == stdZeroHour12)
if hour < 0 || 12 < hour {
rangeErrString = "hour"
}
- case stdMinute, stdUnderMinute, stdZeroMinute:
- if std == stdUnderMinute && len(value) > 0 && value[0] == ' ' {
- value = value[1:]
- }
+ case stdMinute, stdZeroMinute:
min, value, err = getnum(value, std == stdZeroMinute)
if min < 0 || 60 <= min {
rangeErrString = "minute"
}
- case stdSecond, stdUnderSecond, stdZeroSecond:
- if std == stdUnderSecond && len(value) > 0 && value[0] == ' ' {
- value = value[1:]
- }
+ case stdSecond, stdZeroSecond:
sec, value, err = getnum(value, std == stdZeroSecond)
if sec < 0 || 60 <= sec {
rangeErrString = "second"