Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Zero value time.Time for date and date32 #391

Closed
KevinJoiner opened this issue Mar 8, 2024 · 0 comments
Closed

Support Zero value time.Time for date and date32 #391

KevinJoiner opened this issue Mar 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@KevinJoiner
Copy link
Contributor

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

  1. Create a zero-valued time
  2. convert it to a Date and a DateTime
  3. 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant