2
0

Date text encoding pads year with 0 for at least 4 digits

e.g. 0007-01-02 instead of 7-01-02

https://github.com/jackc/pgx/commit/89f69aaea9748ae0ea121af4f1886d24966cef56#commitcomment-89173737
This commit is contained in:
Jack Christensen
2022-11-12 06:14:04 -06:00
parent a86acf61e0
commit daf570c752
2 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -193,7 +193,11 @@ func (encodePlanDateCodecText) Encode(value any, buf []byte) (newBuf []byte, err
bc = true
}
buf = strconv.AppendInt(buf, int64(year), 10)
yearBytes := strconv.AppendInt(make([]byte, 0, 6), int64(year), 10)
for i := len(yearBytes); i < 4; i++ {
buf = append(buf, '0')
}
buf = append(buf, yearBytes...)
buf = append(buf, '-')
if date.Time.Month() < 10 {
buf = append(buf, '0')