aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/datetime64_test.go
blob: def009c6fb33f0fd2e8bee5e2bc0304bae2396fe (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
25
26
27
28
29
30
31
32
33
34
35
36
package proto

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestDateTime64_Time(t *testing.T) {
	for _, p := range []Precision{
		PrecisionSecond,
		1,
		PrecisionMilli,
		PrecisionMicro,
		PrecisionNano,
		8,
	} {
		t.Run(p.Duration().String(), func(t *testing.T) {
			for _, v := range []time.Time{
				{}, // zero time
				time.Unix(1546290000, 0).UTC(),
			} {
				d := ToDateTime64(v, p)
				vt := d.Time(p)
				assert.Equal(t, ToDateTime64(v, p), d)
				assert.Equal(t, v.Unix(), vt.Unix())
				assert.True(t, p.Valid())
			}
		})
	}
	t.Run("Duration", func(t *testing.T) {
		assert.Equal(t, time.Second, PrecisionSecond.Duration(), "sec")
		assert.Equal(t, time.Nanosecond, PrecisionNano.Duration(), "ns")
	})
}