Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Functions for converting from null.Time to Google Protobuf Timestamp, and vice versa

Notifications You must be signed in to change notification settings

AlpacaLabs/go-timestamp-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-timestamp-sql

Functions for converting from null.Time to Google Protobuf Timestamp, and vice versa.

This is useful since we're using the guregu/null library for storing timestamp fields into SQL.

Getting started

go get -v github.com/AlpacaLabs/go-timestamp-sql

and in your Go code

import (
	"testing"
	"time"

	clock "github.com/AlpacaLabs/go-timestamp"

	. "github.com/smartystreets/goconvey/convey"
)

func Test_TimestampConversion(t *testing.T) {
	Convey("Given some non-zero time", t, func(c C) {
		now := time.Now()
		pb := clock.TimeToTimestamp(now)
		nt := TimestampToNullTime(pb)
		So(nt.Time, ShouldEqual, now)
		pb2 := TimestampFromNullTime(nt)
		So(pb.Seconds, ShouldEqual, pb2.Seconds)
		So(pb.Nanos, ShouldEqual, pb2.Nanos)
	})
}

About

Functions for converting from null.Time to Google Protobuf Timestamp, and vice versa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published