github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/time.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "time" 25 26 "github.com/hashgraph/hedera-protobufs-go/services" 27 ) 28 29 func _DurationToProtobuf(duration time.Duration) *services.Duration { 30 return &services.Duration{ 31 Seconds: int64(duration.Seconds()), 32 } 33 } 34 35 func _DurationFromProtobuf(pb *services.Duration) time.Duration { 36 if pb == nil { 37 return time.Duration(0) 38 } 39 return time.Duration(pb.Seconds * int64(time.Second)) 40 } 41 42 func _TimeToProtobuf(t time.Time) *services.Timestamp { 43 return &services.Timestamp{ 44 Seconds: t.Unix(), 45 Nanos: int32(t.UnixNano() - (t.Unix() * 1e+9)), 46 } 47 } 48 49 func _TimeFromProtobuf(pb *services.Timestamp) time.Time { 50 if pb == nil { 51 return time.Time{} 52 } 53 return time.Unix(pb.Seconds, int64(pb.Nanos)) 54 }