Debian Codegraph @

pdata/pcommon/timestamp.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pcommon // import "go.opentelemetry.io/collector/pdata/pcommon"
5
6 import (
7 "time"
8 )
9
10 // Timestamp is a time specified as UNIX Epoch time in nanoseconds since
11 // 1970-01-01 00:00:00 +0000 UTC.
12 type Timestamp uint64
13
14 // NewTimestampFromTime constructs a new Timestamp from the provided time.Time.
15 func NewTimestampFromTime(t time.Time) Timestamp {
16 return Timestamp(uint64(t.UnixNano()))
17 }
18
19 // AsTime converts this to a time.Time.
20 func (ts Timestamp) AsTime() time.Time {
21 return time.Unix(0, int64(ts)).UTC()
22 }
23
24 // String returns the string representation of this in UTC.
25 func (ts Timestamp) String() string {
26 return ts.AsTime().String()
27 }