Add tests for big time and port fix to Timestamp.DecodeBinary
https://github.com/jackc/pgtype/pull/128
This commit is contained in:
+4
-2
@@ -141,8 +141,10 @@ func (dst *Timestamp) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
case negativeInfinityMicrosecondOffset:
|
||||
*dst = Timestamp{Status: Present, InfinityModifier: -Infinity}
|
||||
default:
|
||||
microsecSinceUnixEpoch := microsecFromUnixEpochToY2K + microsecSinceY2K
|
||||
tim := time.Unix(microsecSinceUnixEpoch/1000000, (microsecSinceUnixEpoch%1000000)*1000).UTC()
|
||||
tim := time.Unix(
|
||||
microsecFromUnixEpochToY2K/1000000+microsecSinceY2K/1000000,
|
||||
(microsecFromUnixEpochToY2K%1000000*1000)+(microsecSinceY2K%1000000*1000),
|
||||
)
|
||||
*dst = Timestamp{Time: tim, Status: Present}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pgtype_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -33,6 +34,26 @@ func TestTimestampTranscode(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgtype/pull/128
|
||||
func TestTimestampTranscodeBigTimeBinary(t *testing.T) {
|
||||
conn := testutil.MustConnectPgx(t)
|
||||
if _, ok := conn.ConnInfo().DataTypeForName("line"); !ok {
|
||||
t.Skip("Skipping due to no line type")
|
||||
}
|
||||
defer testutil.MustCloseContext(t, conn)
|
||||
|
||||
in := &pgtype.Timestamp{Time: time.Date(294276, 12, 31, 23, 59, 59, 999999000, time.UTC), Status: pgtype.Present}
|
||||
var out pgtype.Timestamp
|
||||
|
||||
err := conn.QueryRow(context.Background(), "select $1::timestamptz", in).Scan(&out)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
require.Equal(t, in.Status, out.Status)
|
||||
require.Truef(t, in.Time.Equal(out.Time), "expected %v got %v", in.Time, out.Time)
|
||||
}
|
||||
|
||||
func TestTimestampNanosecondsTruncated(t *testing.T) {
|
||||
tests := []struct {
|
||||
input time.Time
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pgtype_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -33,6 +34,26 @@ func TestTimestamptzTranscode(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgtype/pull/128
|
||||
func TestTimestamptzTranscodeBigTimeBinary(t *testing.T) {
|
||||
conn := testutil.MustConnectPgx(t)
|
||||
if _, ok := conn.ConnInfo().DataTypeForName("line"); !ok {
|
||||
t.Skip("Skipping due to no line type")
|
||||
}
|
||||
defer testutil.MustCloseContext(t, conn)
|
||||
|
||||
in := &pgtype.Timestamptz{Time: time.Date(294276, 12, 31, 23, 59, 59, 999999000, time.UTC), Status: pgtype.Present}
|
||||
var out pgtype.Timestamptz
|
||||
|
||||
err := conn.QueryRow(context.Background(), "select $1::timestamptz", in).Scan(&out)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
require.Equal(t, in.Status, out.Status)
|
||||
require.Truef(t, in.Time.Equal(out.Time), "expected %v got %v", in.Time, out.Time)
|
||||
}
|
||||
|
||||
func TestTimestamptzNanosecondsTruncated(t *testing.T) {
|
||||
tests := []struct {
|
||||
input time.Time
|
||||
|
||||
Reference in New Issue
Block a user