github.com/kiali/kiali@v1.84.0/tracing/jaeger/model/time.go (about) 1 // Copyright (c) 2019 The Jaeger Authors. 2 // Copyright (c) 2017 Uber Technologies, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package model 17 18 import ( 19 "time" 20 ) 21 22 // EpochMicrosecondsAsTime converts microseconds since epoch to time.Time value. 23 func EpochMicrosecondsAsTime(ts uint64) time.Time { 24 seconds := ts / 1000000 25 nanos := 1000 * (ts % 1000000) 26 return time.Unix(int64(seconds), int64(nanos)).UTC() 27 } 28 29 // TimeAsEpochMicroseconds converts time.Time to microseconds since epoch, 30 // which is the format the StartTime field is stored in the Span. 31 func TimeAsEpochMicroseconds(t time.Time) uint64 { 32 return uint64(t.UnixNano() / 1000) 33 } 34 35 // MicrosecondsAsDuration converts duration in microseconds to time.Duration value. 36 func MicrosecondsAsDuration(v uint64) time.Duration { 37 return time.Duration(v) * time.Microsecond 38 } 39 40 // DurationAsMicroseconds converts time.Duration to microseconds, 41 // which is the format the Duration field is stored in the Span. 42 func DurationAsMicroseconds(d time.Duration) uint64 { 43 return uint64(d.Nanoseconds() / 1000) 44 }