Documentation ¶
Overview ¶
Package timepb provides functions to do time operations with protobuf timestamp and duration structures.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add returns a new timestamp with value t + d, where d is protobuf Duration If t is nil then nil is returned. Panics on overflow. Note: d must be a valid PB Duration (d..CheckValid() is nil).
Example ¶
t1 := &tspb.Timestamp{Seconds: 10, Nanos: 1} d := &durpb.Duration{Seconds: 1, Nanos: 1e9 - 1} t2 := Add(t1, d) fmt.Println(Compare(&tspb.Timestamp{Seconds: 12, Nanos: 0}, t2) == 0) fmt.Println(Compare(&tspb.Timestamp{Seconds: 10, Nanos: 1}, t1) == 0) fmt.Println(Compare(t1, t2))
Output: true true -1
func AddStd ¶
AddStd returns a new timestamp with value t + d, where d is stdlib Duration. If t is nil then nil is returned. Panics on overflow.
func Compare ¶
Commpare t1 and t2 and returns -1 when t1 < t2, 0 when t1 == t2 and 1 otherwise. Returns false if t1 or t2 is nil
func DurationIsNegative ¶
DurationIsNegative returns true if the duration is negative. It assumes that d is valid (d..CheckValid() is nil).
Types ¶
This section is empty.