Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Oct 24, 2024
1 parent 4bc8fb8 commit 08bf895
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/debezium/converters/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions lib/debezium/converters/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand All @@ -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()))
}
Expand Down
10 changes: 4 additions & 6 deletions lib/debezium/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
{
Expand Down
1 change: 1 addition & 0 deletions lib/typing/ext/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 08bf895

Please sign in to comment.