Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 3afaf9c

Browse files
veqrynfarbodsalimi
authored andcommitted
do not calculate day count twice
1 parent 892c173 commit 3afaf9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func quote(v driver.Value) string {
134134

135135
func formatTime(value time.Time) string {
136136
// toDate() overflows after 65535 days, but toDateTime() only overflows when time.Time overflows (after 9223372036854775807 seconds)
137-
if (value.Hour()+value.Minute()+value.Second()+value.Nanosecond()) == 0 && value.Unix()/24/3600 <= math.MaxUint16 {
138-
return fmt.Sprintf("toDate(%d)", value.Unix()/24/3600)
137+
if days := value.Unix() / 24 / 3600; days <= math.MaxUint16 && (value.Hour()+value.Minute()+value.Second()+value.Nanosecond()) == 0 {
138+
return fmt.Sprintf("toDate(%d)", days)
139139
}
140140
return fmt.Sprintf("toDateTime(%d)", value.Unix())
141141
}

0 commit comments

Comments
 (0)