Support Zero value time.Time for date and date32
KevinJoiner opened this issue · 0 comments
KevinJoiner commented
Describe the bug
zero value for a time.Time
object is inconsistently handled between the Date and DateTime types.
If a user uses time.Time{}
for a DateTime or a DateTime32 object, it gets translated to UNIX time of 0. But this is not the case for the ToDate
functions for Date and Date32. Currently if time.Time{}
is used for Date object the resulting date is 1974-10-01
due to casting a negative unix time to a uint.
Steps to reproduce
- Create a zero-valued time
- convert it to a Date and a DateTime
- Notice inconsistent Dates
Expected behaviour
Both Date and date time convert time.Time{}
to the same value, preferably 0
Code example
package main
import (
"fmt"
"time"
"github.com/ClickHouse/ch-go/proto"
)
func main() {
zeroTime := time.Time{}
date := proto.ToDate(zeroTime)
dateTime := proto.ToDateTime(zeroTime)
fmt.Printf("Date: %d\n", date)
fmt.Printf("DateTime: %d\n", dateTime)
// Output: Date: 1734
// DateTime: 0
}