Skip to content

Commit

Permalink
make microseconds optional too
Browse files Browse the repository at this point in the history
  • Loading branch information
exekias committed Mar 19, 2024
1 parent 33f6139 commit 2cf11c7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pgtype/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ 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
Expand Down

0 comments on commit 2cf11c7

Please sign in to comment.