Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/cli/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/timeofday"
"github.com/cockroachdb/cockroach/pkg/util/timetz"
"github.com/cockroachdb/cockroach/pkg/util/version"
"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -683,9 +684,9 @@ func dumpTableData(w io.Writer, conn *sqlConn, clusterTS string, bmd basicMetada
}
case types.TimeFamily:
// pq awkwardly represents TIME as a time.Time with date 0000-01-01.
d = tree.MakeDTime(timeofday.FromTime(t))
d = tree.MakeDTime(timeofday.FromTimeAllow2400(t))
case types.TimeTZFamily:
d = tree.NewDTimeTZFromTime(t)
d = tree.NewDTimeTZ(timetz.MakeTimeTZFromTimeAllow2400(t))
case types.TimestampFamily:
d = tree.MakeDTimestamp(t, time.Nanosecond)
case types.TimestampTZFamily:
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/copy_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/timeofday"
"github.com/cockroachdb/cockroach/pkg/util/timetz"
"github.com/lib/pq"
)

Expand Down Expand Up @@ -250,9 +251,9 @@ func TestCopyRandom(t *testing.T) {
case time.Time:
var dt tree.NodeFormatter
if typs[i].Family() == types.TimeFamily {
dt = tree.MakeDTime(timeofday.FromTime(d))
dt = tree.MakeDTime(timeofday.FromTimeAllow2400(d))
} else if typs[i].Family() == types.TimeTZFamily {
dt = tree.NewDTimeTZFromTime(d)
dt = tree.NewDTimeTZ(timetz.MakeTimeTZFromTimeAllow2400(d))
} else {
dt = tree.MakeDTimestamp(d, time.Microsecond)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/alter_table
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,3 @@ ALTER TABLE t43092 ALTER COLUMN x DROP NOT NULL

statement ok
DROP TABLE t43092

2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/timetz
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ SELECT '23:59:59.999999-10':::TIMETZ;
query T
SELECT '24:00:00':::TIMETZ;
----
0000-01-01 00:00:00 +0000 UTC
0000-01-02 00:00:00 +0000 UTC

query T
SELECT TIMETZ '12:00:00-07';
Expand Down
16 changes: 15 additions & 1 deletion pkg/sql/pgwire/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,17 @@ const (
pgDateFormat = "2006-01-02"
pgTimeStampFormatNoOffset = pgDateFormat + " " + pgTimeFormat
pgTimeStampFormat = pgTimeStampFormatNoOffset + "-07:00"
pgTime2400Format = "24:00:00"
)

// formatTime formats t into a format lib/pq understands, appending to the
// provided tmp buffer and reallocating if needed. The function will then return
// the resulting buffer.
func formatTime(t timeofday.TimeOfDay, tmp []byte) []byte {
// time.Time's AppendFormat does not recognize 2400, so special case it accordingly.
if t == timeofday.Time2400 {
return []byte(pgTime2400Format)
}
return t.ToTime().AppendFormat(tmp, pgTimeFormat)
}

Expand All @@ -514,7 +519,16 @@ func formatTime(t timeofday.TimeOfDay, tmp []byte) []byte {
// Note it does not understand the "second" component of the offset as lib/pq
// cannot parse it.
func formatTimeTZ(t timetz.TimeTZ, tmp []byte) []byte {
return t.ToTime().AppendFormat(tmp, pgTimeTZFormat)
ret := t.ToTime().AppendFormat(tmp, pgTimeTZFormat)
// time.Time's AppendFormat does not recognize 2400, so special case it accordingly.
if t.TimeOfDay == timeofday.Time2400 {
// It instead reads 00:00:00. Replace that text.
var newRet []byte
newRet = append(newRet, pgTime2400Format...)
newRet = append(newRet, ret[len(pgTime2400Format):]...)
ret = newRet
}
return ret
}

func formatTs(t time.Time, offset *time.Location, tmp []byte) (b []byte) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/sqlbase/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ var (
types.TimeFamily: {
tree.MakeDTime(timeofday.Min),
tree.MakeDTime(timeofday.Max),
tree.MakeDTime(timeofday.Time2400),
},
types.TimeTZFamily: {
tree.DMinTimeTZ,
// Uncomment this once #44548 has been resolved.
// tree.DMaxTimeTZ,
tree.DMaxTimeTZ,
},
types.TimestampFamily: func() []tree.Datum {
res := make([]tree.Datum, len(randTimestampSpecials))
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/timeofday/time_of_day.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ func FromTime(t time.Time) TimeOfDay {
return FromInt(nanos / nanosPerMicro)
}

// FromTimeAllow2400 assumes 24:00 time is possible from the given input,
// otherwise falling back to FromTime.
// It assumes time.Time is represented as lib/pq or as unix time.
func FromTimeAllow2400(t time.Time) TimeOfDay {
if t.Day() != 1 {
return Time2400
}
return FromTime(t)
}

// ToTime converts a TimeOfDay to a time.Time, using the Unix epoch as the date.
func (t TimeOfDay) ToTime() time.Time {
return timeutil.Unix(0, int64(t)*nanosPerMicro)
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/timetz/timetz.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func MakeTimeTZFromTime(t time.Time) TimeTZ {
)
}

// MakeTimeTZFromTimeAllow2400 creates a TimeTZ from a time.Time,
// but factors in that Time2400 may be possible.
// This assumes either a lib/pq time or unix time is set.
func MakeTimeTZFromTimeAllow2400(t time.Time) TimeTZ {
if t.Day() != 1 {
return MakeTimeTZFromLocation(timeofday.Time2400, t.Location())
}
return MakeTimeTZFromTime(t)
}

// Now returns the TimeTZ of the current location.
func Now() TimeTZ {
return MakeTimeTZFromTime(timeutil.Now())
Expand Down
2 changes: 1 addition & 1 deletion vendor
Submodule vendor updated 34 files
+1,311 −0 github.com/lib/pq/array_test.go
+434 −0 github.com/lib/pq/bench_test.go
+16 −0 github.com/lib/pq/buf_test.go
+3 −0 github.com/lib/pq/certs/README
+19 −0 github.com/lib/pq/certs/bogus_root.crt
+69 −0 github.com/lib/pq/certs/postgresql.crt
+15 −0 github.com/lib/pq/certs/postgresql.key
+24 −0 github.com/lib/pq/certs/root.crt
+81 −0 github.com/lib/pq/certs/server.crt
+27 −0 github.com/lib/pq/certs/server.key
+11 −2 github.com/lib/pq/conn.go
+1,777 −0 github.com/lib/pq/conn_test.go
+29 −0 github.com/lib/pq/connector_example_test.go
+67 −0 github.com/lib/pq/connector_test.go
+3 −1 github.com/lib/pq/copy.go
+468 −0 github.com/lib/pq/copy_test.go
+20 −0 github.com/lib/pq/encode.go
+845 −0 github.com/lib/pq/encode_test.go
+98 −0 github.com/lib/pq/example/listen/doc.go
+319 −0 github.com/lib/pq/go18_test.go
+98 −0 github.com/lib/pq/go19_test.go
+118 −0 github.com/lib/pq/hstore/hstore.go
+148 −0 github.com/lib/pq/hstore/hstore_test.go
+26 −0 github.com/lib/pq/issues_test.go
+71 −0 github.com/lib/pq/notice.go
+33 −0 github.com/lib/pq/notice_example_test.go
+49 −0 github.com/lib/pq/notice_test.go
+5 −1 github.com/lib/pq/notify.go
+570 −0 github.com/lib/pq/notify_test.go
+218 −0 github.com/lib/pq/rows_test.go
+279 −0 github.com/lib/pq/ssl_test.go
+66 −0 github.com/lib/pq/url_test.go
+1 −1 github.com/lib/pq/user_posix.go
+46 −0 github.com/lib/pq/uuid_test.go