timepb

package
v1.0.0-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

timepb

timepb is a Go package that provides functions to do time operations with protobuf timestamp and protobuf duration structures.

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

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

func AddStd(t *tspb.Timestamp, d time.Duration) *tspb.Timestamp

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

func Compare(t1, t2 *tspb.Timestamp) int

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

func DurationIsNegative(d *durpb.Duration) bool

DurationIsNegative returns true if the duration is negative. It assumes that d is valid (d..CheckValid() is nil).

func IsZero

func IsZero(t *tspb.Timestamp) bool

IsZero returns true only when t is nil

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL