Debian Codegraph @

pdata/pcommon/timestamp_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pcommon
5
6 import (
7 "testing"
8 "time"
9
10 "github.com/stretchr/testify/assert"
11 )
12
13 func TestUnixNanosConverters(t *testing.T) {
14 t1 := time.Date(2020, 3, 24, 1, 13, 23, 789, time.UTC)
15 tun := Timestamp(t1.UnixNano())
16
17 assert.EqualValues(t, uint64(1585012403000000789), tun)
18 assert.Equal(t, tun, NewTimestampFromTime(t1))
19 assert.Equal(t, t1, NewTimestampFromTime(t1).AsTime())
20 assert.Equal(t, "2020-03-24 01:13:23.000000789 +0000 UTC", t1.String())
21 }
22
23 func TestZeroTimestamp(t *testing.T) {
24 assert.Equal(t, time.Unix(0, 0).UTC(), Timestamp(0).AsTime())
25 assert.Zero(t, NewTimestampFromTime(time.Unix(0, 0).UTC()))
26 assert.Equal(t, "1970-01-01 00:00:00 +0000 UTC", Timestamp(0).String())
27 }