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

Latest commit

 

History

History
33 lines (27 loc) · 810 Bytes

README.md

File metadata and controls

33 lines (27 loc) · 810 Bytes

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)
	})
}