@@ -90,7 +90,6 @@ const (
9090 stdLongMonth = iota + stdNeedDate // "January"
9191 stdMonth // "Jan"
9292 stdNumMonth // "1"
93- stdUnderMonth // "_1"
9493 stdZeroMonth // "01"
9594 stdLongWeekDay // "Monday"
9695 stdWeekDay // "Mon"
@@ -99,13 +98,10 @@ const (
9998 stdZeroDay // "02"
10099 stdHour = iota + stdNeedClock // "15"
101100 stdHour12 // "3"
102- stdUnderHour12 // "_3"
103101 stdZeroHour12 // "03"
104102 stdMinute // "4"
105- stdUnderMinute // "_4"
106103 stdZeroMinute // "04"
107104 stdSecond // "5"
108- stdUnderSecond // "_5"
109105 stdZeroSecond // "05"
110106 stdLongYear = iota + stdNeedDate // "2006"
111107 stdYear // "06"
@@ -191,24 +187,13 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
191187 }
192188 return layout [0 :i ], stdDay , layout [i + 1 :]
193189
194- case '_' : // _1, _2, _2006, _3, _4, _5
195- if len (layout ) >= i + 2 {
196- switch layout [i + 1 ] {
197- case '1' :
198- return layout [0 :i ], stdUnderMonth , layout [i + 2 :]
199- case '2' :
200- //_2006 is really a literal _, followed by stdLongYear
201- if len (layout ) >= i + 5 && layout [i + 1 :i + 5 ] == "2006" {
202- return layout [0 : i + 1 ], stdLongYear , layout [i + 5 :]
203- }
204- return layout [0 :i ], stdUnderDay , layout [i + 2 :]
205- case '3' :
206- return layout [0 :i ], stdUnderHour12 , layout [i + 2 :]
207- case '4' :
208- return layout [0 :i ], stdUnderMinute , layout [i + 2 :]
209- case '5' :
210- return layout [0 :i ], stdUnderSecond , layout [i + 2 :]
190+ case '_' : // _2, _2006
191+ if len (layout ) >= i + 2 && layout [i + 1 ] == '2' {
192+ //_2006 is really a literal _, followed by stdLongYear
193+ if len (layout ) >= i + 5 && layout [i + 1 :i + 5 ] == "2006" {
194+ return layout [0 : i + 1 ], stdLongYear , layout [i + 5 :]
211195 }
196+ return layout [0 :i ], stdUnderDay , layout [i + 2 :]
212197 }
213198
214199 case '3' :
@@ -559,11 +544,6 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
559544 b = append (b , m ... )
560545 case stdNumMonth :
561546 b = appendInt (b , int (month ), 0 )
562- case stdUnderMonth :
563- if month < 10 {
564- b = append (b , ' ' )
565- }
566- b = appendInt (b , int (month ), 0 )
567547 case stdZeroMonth :
568548 b = appendInt (b , int (month ), 2 )
569549 case stdWeekDay :
@@ -589,16 +569,6 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
589569 hr = 12
590570 }
591571 b = appendInt (b , hr , 0 )
592- case stdUnderHour12 :
593- // Noon is 12PM, midnight is 12AM.
594- hr := hour % 12
595- if hr == 0 {
596- hr = 12
597- }
598- if hr < 10 {
599- b = append (b , ' ' )
600- }
601- b = appendInt (b , hr , 0 )
602572 case stdZeroHour12 :
603573 // Noon is 12PM, midnight is 12AM.
604574 hr := hour % 12
@@ -608,20 +578,10 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
608578 b = appendInt (b , hr , 2 )
609579 case stdMinute :
610580 b = appendInt (b , min , 0 )
611- case stdUnderMinute :
612- if min < 10 {
613- b = append (b , ' ' )
614- }
615- b = appendInt (b , min , 0 )
616581 case stdZeroMinute :
617582 b = appendInt (b , min , 2 )
618583 case stdSecond :
619584 b = appendInt (b , sec , 0 )
620- case stdUnderSecond :
621- if sec < 10 {
622- b = append (b , ' ' )
623- }
624- b = appendInt (b , sec , 0 )
625585 case stdZeroSecond :
626586 b = appendInt (b , sec , 2 )
627587 case stdPM :
@@ -886,10 +846,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
886846 case stdLongMonth :
887847 month , value , err = lookup (longMonthNames , value )
888848 month ++
889- case stdNumMonth , stdUnderMonth , stdZeroMonth :
890- if std == stdUnderMonth && len (value ) > 0 && value [0 ] == ' ' {
891- value = value [1 :]
892- }
849+ case stdNumMonth , stdZeroMonth :
893850 month , value , err = getnum (value , std == stdZeroMonth )
894851 if month <= 0 || 12 < month {
895852 rangeErrString = "month"
@@ -913,26 +870,17 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
913870 if hour < 0 || 24 <= hour {
914871 rangeErrString = "hour"
915872 }
916- case stdHour12 , stdUnderHour12 , stdZeroHour12 :
917- if std == stdUnderHour12 && len (value ) > 0 && value [0 ] == ' ' {
918- value = value [1 :]
919- }
873+ case stdHour12 , stdZeroHour12 :
920874 hour , value , err = getnum (value , std == stdZeroHour12 )
921875 if hour < 0 || 12 < hour {
922876 rangeErrString = "hour"
923877 }
924- case stdMinute , stdUnderMinute , stdZeroMinute :
925- if std == stdUnderMinute && len (value ) > 0 && value [0 ] == ' ' {
926- value = value [1 :]
927- }
878+ case stdMinute , stdZeroMinute :
928879 min , value , err = getnum (value , std == stdZeroMinute )
929880 if min < 0 || 60 <= min {
930881 rangeErrString = "minute"
931882 }
932- case stdSecond , stdUnderSecond , stdZeroSecond :
933- if std == stdUnderSecond && len (value ) > 0 && value [0 ] == ' ' {
934- value = value [1 :]
935- }
883+ case stdSecond , stdZeroSecond :
936884 sec , value , err = getnum (value , std == stdZeroSecond )
937885 if sec < 0 || 60 <= sec {
938886 rangeErrString = "second"
0 commit comments