Do not encode interval microseconds when they are 0

This make the encode match what postgres does
pull/2010/head
Carlos Pérez-Aradros Herce 2024-03-19 14:42:26 +01:00 committed by Jack Christensen
parent 48ae1f4b2c
commit 01d649b2bf
1 changed files with 21 additions and 12 deletions

View File

@ -132,9 +132,12 @@ func (encodePlanIntervalCodecText) Encode(value any, buf []byte) (newBuf []byte,
if interval.Days != 0 {
buf = append(buf, strconv.FormatInt(int64(interval.Days), 10)...)
buf = append(buf, " day "...)
buf = append(buf, " day"...)
}
if interval.Microseconds != 0 {
buf = append(buf, " "...)
absMicroseconds := interval.Microseconds
if absMicroseconds < 0 {
absMicroseconds = -absMicroseconds
@ -144,10 +147,16 @@ func (encodePlanIntervalCodecText) Encode(value any, buf []byte) (newBuf []byte,
hours := absMicroseconds / microsecondsPerHour
minutes := (absMicroseconds % microsecondsPerHour) / microsecondsPerMinute
seconds := (absMicroseconds % microsecondsPerMinute) / microsecondsPerSecond
microseconds := absMicroseconds % microsecondsPerSecond
timeStr := fmt.Sprintf("%02d:%02d:%02d.%06d", hours, minutes, seconds, microseconds)
timeStr := fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
buf = append(buf, timeStr...)
microseconds := absMicroseconds % microsecondsPerSecond
if microseconds != 0 {
buf = append(buf, fmt.Sprintf(".%06d", microseconds)...)
}
}
return buf, nil
}