mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
parent
af0ca3a39b
commit
36a8da55cc
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jackc/pgtype"
|
"github.com/jackc/pgtype"
|
||||||
"github.com/jackc/pgtype/testutil"
|
"github.com/jackc/pgtype/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimestampTranscode(t *testing.T) {
|
func TestTimestampTranscode(t *testing.T) {
|
||||||
@ -77,6 +78,13 @@ func TestTimestampNanosecondsTruncated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgtype/issues/74
|
||||||
|
func TestTimestampDecodeTextInvalid(t *testing.T) {
|
||||||
|
tstz := &pgtype.Timestamp{}
|
||||||
|
err := tstz.DecodeText(nil, []byte(`eeeee`))
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTimestampSet(t *testing.T) {
|
func TestTimestampSet(t *testing.T) {
|
||||||
type _time time.Time
|
type _time time.Time
|
||||||
|
|
||||||
|
@ -111,9 +111,9 @@ func (dst *Timestamptz) DecodeText(ci *ConnInfo, src []byte) error {
|
|||||||
*dst = Timestamptz{Status: Present, InfinityModifier: -Infinity}
|
*dst = Timestamptz{Status: Present, InfinityModifier: -Infinity}
|
||||||
default:
|
default:
|
||||||
var format string
|
var format string
|
||||||
if sbuf[len(sbuf)-9] == '-' || sbuf[len(sbuf)-9] == '+' {
|
if len(sbuf) >= 9 && (sbuf[len(sbuf)-9] == '-' || sbuf[len(sbuf)-9] == '+') {
|
||||||
format = pgTimestamptzSecondFormat
|
format = pgTimestamptzSecondFormat
|
||||||
} else if sbuf[len(sbuf)-6] == '-' || sbuf[len(sbuf)-6] == '+' {
|
} else if len(sbuf) >= 6 && (sbuf[len(sbuf)-6] == '-' || sbuf[len(sbuf)-6] == '+') {
|
||||||
format = pgTimestamptzMinuteFormat
|
format = pgTimestamptzMinuteFormat
|
||||||
} else {
|
} else {
|
||||||
format = pgTimestamptzHourFormat
|
format = pgTimestamptzHourFormat
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jackc/pgtype"
|
"github.com/jackc/pgtype"
|
||||||
"github.com/jackc/pgtype/testutil"
|
"github.com/jackc/pgtype/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimestamptzTranscode(t *testing.T) {
|
func TestTimestamptzTranscode(t *testing.T) {
|
||||||
@ -77,6 +78,13 @@ func TestTimestamptzNanosecondsTruncated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgtype/issues/74
|
||||||
|
func TestTimestamptzDecodeTextInvalid(t *testing.T) {
|
||||||
|
tstz := &pgtype.Timestamptz{}
|
||||||
|
err := tstz.DecodeText(nil, []byte(`eeeee`))
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTimestamptzSet(t *testing.T) {
|
func TestTimestamptzSet(t *testing.T) {
|
||||||
type _time time.Time
|
type _time time.Time
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jackc/pgtype"
|
"github.com/jackc/pgtype"
|
||||||
"github.com/jackc/pgtype/testutil"
|
"github.com/jackc/pgtype/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTstzrangeTranscode(t *testing.T) {
|
func TestTstzrangeTranscode(t *testing.T) {
|
||||||
@ -39,3 +40,10 @@ func TestTstzrangeTranscode(t *testing.T) {
|
|||||||
a.Upper.InfinityModifier == b.Upper.InfinityModifier
|
a.Upper.InfinityModifier == b.Upper.InfinityModifier
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgtype/issues/74
|
||||||
|
func TestTstzRangeDecodeTextInvalid(t *testing.T) {
|
||||||
|
tstzrange := &pgtype.Tstzrange{}
|
||||||
|
err := tstzrange.DecodeText(nil, []byte(`[eeee,)`))
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user