9 type appender interface {
10 Append([]byte, time.Time) []byte
13 type appenderList []appender
15 // does the time.Format thing
16 type timefmtw struct {
20 func timefmt(s string) *timefmtw {
21 return &timefmtw{s: s}
24 func (v timefmtw) Append(b []byte, t time.Time) []byte {
25 return t.AppendFormat(b, v.s)
28 func (v timefmtw) str() string {
32 func (v timefmtw) canCombine() bool {
36 func (v timefmtw) combine(w combiner) appender {
37 return timefmt(v.s + w.str())
40 type verbatimw struct {
44 func verbatim(s string) *verbatimw {
45 return &verbatimw{s: s}
48 func (v verbatimw) Append(b []byte, _ time.Time) []byte {
49 return append(b, v.s...)
52 func (v verbatimw) canCombine() bool {
53 return canCombine(v.s)
56 func (v verbatimw) combine(w combiner) appender {
57 if _, ok := w.(*timefmtw); ok {
58 return timefmt(v.s + w.str())
60 return verbatim(v.s + w.str())
63 func (v verbatimw) str() string {
67 // These words below, as well as any decimal character
68 var combineExclusion = []string{
78 func canCombine(s string) bool {
79 if strings.ContainsAny(s, "0123456789") {
82 for _, word := range combineExclusion {
83 if strings.Contains(s, word) {
90 type combiner interface {
92 combine(combiner) appender
98 func (v century) Append(b []byte, t time.Time) []byte {
103 return append(b, strconv.Itoa(n)...)
108 func (v weekday) Append(b []byte, t time.Time) []byte {
109 n := int(t.Weekday())
113 return append(b, byte(n+48))
116 type weeknumberOffset int
118 func (v weeknumberOffset) Append(b []byte, t time.Time) []byte {
120 offset := int(t.Weekday()) - int(v)
126 return append(b, '0', '0')
129 n := ((yd - offset) / 7) + 1
133 return append(b, strconv.Itoa(n)...)
136 type weeknumber struct{}
138 func (v weeknumber) Append(b []byte, t time.Time) []byte {
143 return append(b, strconv.Itoa(n)...)
146 type dayofyear struct{}
148 func (v dayofyear) Append(b []byte, t time.Time) []byte {
151 b = append(b, '0', '0')
155 return append(b, strconv.Itoa(n)...)
160 func (v hourwblank) Append(b []byte, t time.Time) []byte {
162 if bool(v) && h > 12 {
168 return append(b, strconv.Itoa(h)...)