@@ -32,7 +32,8 @@ const (
32
32
stdLongYear = iota + stdNeedDate // "2006"
33
33
stdYear // "06"
34
34
stdFirstTwoDigitYear // "20"
35
- stdISO8601WeekYear = iota + stdNeedISOISO8601Week // last two digitsof ISO 8601 week-based year
35
+ stdYearDay // day of the year as a decimal number (range [001,366])
36
+ stdISO8601WeekYear = iota + stdNeedISOISO8601Week // last two digits of ISO 8601 week-based year
36
37
stdISO8601LongWeekYear // ISO 8601 week-based year
37
38
stdISO8601Week // ISO 8601 week
38
39
stdPM = iota + stdNeedClock // "PM"
@@ -60,13 +61,14 @@ func AppendFormat(b []byte, t time.Time, layout string) []byte {
60
61
var (
61
62
name , offset , abs = locabs (& t )
62
63
63
- year int = - 1
64
+ year = - 1
64
65
month time.Month
65
66
day int
66
- hour int = - 1
67
+ yday int
68
+ hour = - 1
67
69
min int
68
70
sec int
69
- iso8601WeekYear int = - 1
71
+ iso8601WeekYear = - 1
70
72
iso8601Week int
71
73
)
72
74
@@ -83,7 +85,7 @@ func AppendFormat(b []byte, t time.Time, layout string) []byte {
83
85
84
86
// Compute year, month, day if needed.
85
87
if year < 0 && std & stdNeedDate != 0 {
86
- year , month , day , _ = absDate (abs , true )
88
+ year , month , day , yday = absDate (abs , true )
87
89
}
88
90
89
91
// Compute hour, minute, second if needed.
@@ -115,6 +117,8 @@ func AppendFormat(b []byte, t time.Time, layout string) []byte {
115
117
b = appendInt (b , year , 4 )
116
118
case stdFirstTwoDigitYear :
117
119
b = appendInt (b , year / 100 , 2 )
120
+ case stdYearDay :
121
+ b = appendInt (b , yday , 3 )
118
122
case stdMonth :
119
123
b = append (b , month .String ()[:3 ]... )
120
124
case stdLongMonth :
@@ -214,9 +218,7 @@ func AppendFormat(b []byte, t time.Time, layout string) []byte {
214
218
// nextStdChunk finds the first occurrence of a std string in
215
219
// layout and returns the text before, the std string, and the text after.
216
220
func nextStdChunk (layout string ) (prefix string , std int , suffix string ) {
217
- var (
218
- specPos int = - 1
219
- )
221
+ specPos := - 1
220
222
221
223
for i := 0 ; i < len (layout ); i ++ {
222
224
c := int (layout [i ])
@@ -243,15 +245,15 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
243
245
case 'd' : // 02
244
246
return layout [0 :specPos ], stdZeroDay , layout [i + 1 :]
245
247
case 'D' : // %m/%d/%y
246
- return layout [0 :specPos ], stdZeroMonth , "/%d/%y" + layout [i + 1 :]
248
+ return layout [0 :specPos ], stdYield , "%m /%d/%y" + layout [i + 1 :]
247
249
case 'e' : // _2
248
250
return layout [0 :specPos ], stdUnderDay , layout [i + 1 :]
249
251
case 'f' : // fraction seconds in microseconds (Python)
250
252
std = stdFracSecond0
251
253
std |= 6 << stdArgShift // microseconds precision
252
254
return layout [0 :specPos ], std , layout [i + 1 :]
253
255
case 'F' : // %Y-%m-%d
254
- return layout [0 :specPos ], stdLongYear , "-%m-%d" + layout [i + 1 :]
256
+ return layout [0 :specPos ], stdYield , "%Y -%m-%d" + layout [i + 1 :]
255
257
case 'g' :
256
258
return layout [0 :specPos ], stdISO8601WeekYear , layout [i + 1 :]
257
259
case 'G' :
@@ -261,7 +263,7 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
261
263
case 'I' :
262
264
return layout [0 :specPos ], stdZeroHour12 , layout [i + 1 :]
263
265
case 'j' :
264
- // TODO: day of the year as a decimal number (range [001,366])
266
+ return layout [ 0 : specPos ], stdYearDay , layout [ i + 1 :]
265
267
case 'm' :
266
268
return layout [0 :specPos ], stdZeroMonth , layout [i + 1 :]
267
269
case 'M' :
@@ -290,7 +292,7 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
290
292
case 'w' :
291
293
return layout [0 :specPos ], stdNumWeekDay , layout [i + 1 :]
292
294
case 'W' :
293
- // TODO: week of the year as a decimal number (Monday is the first day of the wee )
295
+ // TODO: week of the year as a decimal number (Monday is the first day of the week )
294
296
//case 'x': // locale depended, not supported
295
297
//case 'X': // locale depended, not supported
296
298
case 'y' :
0 commit comments