aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/datetime.go
blob: 4917339e293fe9cbf17edc88f799848d79f8bdd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package proto

import "time"

// DateTime represents DateTime type.
type DateTime uint32

// ToDateTime converts time.Time to DateTime.
func ToDateTime(t time.Time) DateTime {
	if t.IsZero() {
		return 0
	}
	return DateTime(t.Unix())
}

// Time returns DateTime as time.Time.
func (d DateTime) Time() time.Time {
	if d == 0 {
		return time.Time{}
	}
	// https://clickhouse.com/docs/en/sql-reference/data-types/datetime/#usage-remarks
	// ClickHouse stores UTC timestamps that are timezone-agnostic.
	return time.Unix(int64(d), 0)
}