diff --git a/lib/debezium/converters/time.go b/lib/debezium/converters/time.go index 6f276e6f8..99e4dc672 100644 --- a/lib/debezium/converters/time.go +++ b/lib/debezium/converters/time.go @@ -72,7 +72,7 @@ func (m MicroTime) Convert(value any) (any, error) { type ZonedTimestamp struct{} func (ZonedTimestamp) layout() string { - return "2006-01-02T15:04:05.999999999Z" + return ext.RFC3339 } func (z ZonedTimestamp) ToKindDetails() (typing.KindDetails, error) { @@ -108,7 +108,7 @@ func (z ZonedTimestamp) Convert(value any) (any, error) { type TimeWithTimezone struct{} func (t TimeWithTimezone) layout() string { - return "15:04:05.999999Z" + return "15:04:05.999999" + ext.TimezoneOffsetFormat } func (t TimeWithTimezone) ToKindDetails() (typing.KindDetails, error) { diff --git a/lib/debezium/converters/time_test.go b/lib/debezium/converters/time_test.go index d8d4e66a8..01cbae2a8 100644 --- a/lib/debezium/converters/time_test.go +++ b/lib/debezium/converters/time_test.go @@ -35,7 +35,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:12Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 12, 000000000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 12, 000000000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:12Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -44,7 +44,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 100000000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 100000000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.1Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -53,7 +53,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 120000000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 120000000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.12Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -62,7 +62,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123000000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123000000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.123Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -71,7 +71,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1234Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123400000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123400000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.1234Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -80,7 +80,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12345Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123450000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123450000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.12345Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -89,7 +89,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123456Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456000, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456000, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.123456Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -98,7 +98,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.1234567Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456700, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456700, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.1234567Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -107,7 +107,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.12345678Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456780, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456780, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.12345678Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } @@ -116,7 +116,7 @@ func TestZonedTimestamp_Convert(t *testing.T) { val, err := ZonedTimestamp{}.Convert("2025-09-13T00:00:00.123456789Z") assert.NoError(t, err) - expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456789, time.UTC), ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z") + expectedExtTime := ext.NewExtendedTime(time.Date(2025, time.September, 13, 0, 0, 0, 123456789, time.UTC), ext.TimestampTZKindType, ext.RFC3339) assert.Equal(t, expectedExtTime, val.(*ext.ExtendedTime)) assert.Equal(t, "2025-09-13T00:00:00.123456789Z", val.(*ext.ExtendedTime).GetTime().Format(ZonedTimestamp{}.layout())) } diff --git a/lib/debezium/schema_test.go b/lib/debezium/schema_test.go index 367bca237..15ab30368 100644 --- a/lib/debezium/schema_test.go +++ b/lib/debezium/schema_test.go @@ -230,11 +230,9 @@ func TestField_ToKindDetails(t *testing.T) { } { // Timestamp with timezone - for _, dbzType := range []SupportedDebeziumType{ZonedTimestamp} { - kd, err := Field{DebeziumType: dbzType}.ToKindDetails() - assert.NoError(t, err) - assert.Equal(t, typing.MustNewExtendedTimeDetails(typing.ETime, ext.TimestampTZKindType, "2006-01-02T15:04:05.999999999Z"), kd) - } + kd, err := Field{DebeziumType: ZonedTimestamp}.ToKindDetails() + assert.NoError(t, err) + assert.Equal(t, typing.MustNewExtendedTimeDetails(typing.ETime, ext.TimestampTZKindType, ext.RFC3339), kd) } { // Timestamp without timezone @@ -259,7 +257,7 @@ func TestField_ToKindDetails(t *testing.T) { for _, dbzType := range []SupportedDebeziumType{TimeWithTimezone} { kd, err := Field{DebeziumType: dbzType}.ToKindDetails() assert.NoError(t, err) - assert.Equal(t, typing.MustNewExtendedTimeDetails(typing.ETime, ext.TimeKindType, "15:04:05.999999Z"), kd, dbzType) + assert.Equal(t, typing.MustNewExtendedTimeDetails(typing.ETime, ext.TimeKindType, "15:04:05.999999"+ext.TimezoneOffsetFormat), kd, dbzType) } } { diff --git a/lib/typing/ext/variables.go b/lib/typing/ext/variables.go index 09f140a33..fb6c31b76 100644 --- a/lib/typing/ext/variables.go +++ b/lib/typing/ext/variables.go @@ -44,6 +44,7 @@ const TimezoneOffsetFormat = "Z07:00" // RFC3339 variants const ( + RFC3339 = RFC3339NoTZ + TimezoneOffsetFormat RFC3339NoTZ = "2006-01-02T15:04:05.999999999" RFC3339Millisecond = "2006-01-02T15:04:05.000" + TimezoneOffsetFormat RFC3339MillisecondNoTZ = "2006-01-02T15:04:05.000"