From 4ff1707cd006a4bc551ed7bc425cfc8165a6d93b Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 19 Sep 2024 11:52:04 -0700 Subject: [PATCH 1/4] Adding an additional timestamp layout. --- lib/typing/ext/parse_test.go | 6 ++++++ lib/typing/ext/variables.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/typing/ext/parse_test.go b/lib/typing/ext/parse_test.go index ab73e6b3a..21ab2124b 100644 --- a/lib/typing/ext/parse_test.go +++ b/lib/typing/ext/parse_test.go @@ -1,6 +1,7 @@ package ext import ( + "fmt" "testing" "time" @@ -36,6 +37,11 @@ func TestParseFromInterface(t *testing.T) { _, err := ParseFromInterface(false, TimestampTzKindType) assert.ErrorContains(t, err, "failed to parse colVal, expected type string or *ExtendedTime and got: bool") } + { + value, err := ParseFromInterface("2024-09-19T16:05:18.630Z", TimestampTzKindType) + assert.NoError(t, err) + fmt.Println("value", value) + } } func TestParseFromInterfaceDateTime(t *testing.T) { diff --git a/lib/typing/ext/variables.go b/lib/typing/ext/variables.go index 02a409df5..75e7b0231 100644 --- a/lib/typing/ext/variables.go +++ b/lib/typing/ext/variables.go @@ -12,6 +12,8 @@ const ( var supportedDateTimeLayouts = []string{ time.RFC3339Nano, + // TODO: This should be pulled into `TIMESTAMP_NTZ` + "2006-01-02T15:04:05.000Z", // RFC 3339 without timezone ISO8601, time.Layout, time.ANSIC, From 713c3db8876bc4b9caa1330f7068c19a17771f2f Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 19 Sep 2024 11:52:38 -0700 Subject: [PATCH 2/4] Update tests. --- lib/typing/ext/parse_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/typing/ext/parse_test.go b/lib/typing/ext/parse_test.go index 21ab2124b..9732a6d17 100644 --- a/lib/typing/ext/parse_test.go +++ b/lib/typing/ext/parse_test.go @@ -1,7 +1,6 @@ package ext import ( - "fmt" "testing" "time" @@ -40,7 +39,7 @@ func TestParseFromInterface(t *testing.T) { { value, err := ParseFromInterface("2024-09-19T16:05:18.630Z", TimestampTzKindType) assert.NoError(t, err) - fmt.Println("value", value) + assert.Equal(t, "2024-09-19T16:05:18.630Z", value.String("")) } } From 5c632fdb0fbc1f63baebc6ff5ed4ee8f6255f41f Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 19 Sep 2024 12:09:10 -0700 Subject: [PATCH 3/4] Clean up. --- lib/typing/ext/parse_test.go | 1 + lib/typing/ext/variables.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/typing/ext/parse_test.go b/lib/typing/ext/parse_test.go index 9732a6d17..63510b76b 100644 --- a/lib/typing/ext/parse_test.go +++ b/lib/typing/ext/parse_test.go @@ -40,6 +40,7 @@ func TestParseFromInterface(t *testing.T) { value, err := ParseFromInterface("2024-09-19T16:05:18.630Z", TimestampTzKindType) assert.NoError(t, err) assert.Equal(t, "2024-09-19T16:05:18.630Z", value.String("")) + assert.Equal(t, RFC3339MillisecondUTC, value.nestedKind.Format) } } diff --git a/lib/typing/ext/variables.go b/lib/typing/ext/variables.go index 75e7b0231..bda6d8812 100644 --- a/lib/typing/ext/variables.go +++ b/lib/typing/ext/variables.go @@ -11,9 +11,8 @@ const ( ) var supportedDateTimeLayouts = []string{ + RFC3339MillisecondUTC, time.RFC3339Nano, - // TODO: This should be pulled into `TIMESTAMP_NTZ` - "2006-01-02T15:04:05.000Z", // RFC 3339 without timezone ISO8601, time.Layout, time.ANSIC, @@ -39,7 +38,8 @@ var SupportedTimeFormats = []string{ // RFC3339 variants const ( - RFC3339Millisecond = "2006-01-02T15:04:05.000Z07:00" - RFC3339Microsecond = "2006-01-02T15:04:05.000000Z07:00" - RFC3339Nanosecond = "2006-01-02T15:04:05.000000000Z07:00" + RFC3339MillisecondUTC = "2006-01-02T15:04:05.000Z" + RFC3339Millisecond = "2006-01-02T15:04:05.000Z07:00" + RFC3339Microsecond = "2006-01-02T15:04:05.000000Z07:00" + RFC3339Nanosecond = "2006-01-02T15:04:05.000000000Z07:00" ) From 8b9ff38208420675acc3fec123e67a165ed3d0fb Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 19 Sep 2024 13:09:12 -0700 Subject: [PATCH 4/4] PR Feedback. --- lib/typing/ext/parse_test.go | 15 +++++++++++++++ lib/typing/ext/variables.go | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/typing/ext/parse_test.go b/lib/typing/ext/parse_test.go index 63510b76b..a0e387818 100644 --- a/lib/typing/ext/parse_test.go +++ b/lib/typing/ext/parse_test.go @@ -37,11 +37,26 @@ func TestParseFromInterface(t *testing.T) { assert.ErrorContains(t, err, "failed to parse colVal, expected type string or *ExtendedTime and got: bool") } { + // String - RFC3339MillisecondUTC value, err := ParseFromInterface("2024-09-19T16:05:18.630Z", TimestampTzKindType) assert.NoError(t, err) assert.Equal(t, "2024-09-19T16:05:18.630Z", value.String("")) assert.Equal(t, RFC3339MillisecondUTC, value.nestedKind.Format) } + { + // String - RFC3339MicrosecondUTC + value, err := ParseFromInterface("2024-09-19T16:05:18.630000Z", TimestampTzKindType) + assert.NoError(t, err) + assert.Equal(t, "2024-09-19T16:05:18.630000Z", value.String("")) + assert.Equal(t, RFC3339MicrosecondUTC, value.nestedKind.Format) + } + { + // String - RFC3339NanosecondUTC + value, err := ParseFromInterface("2024-09-19T16:05:18.630000000Z", TimestampTzKindType) + assert.NoError(t, err) + assert.Equal(t, "2024-09-19T16:05:18.630000000Z", value.String("")) + assert.Equal(t, RFC3339NanosecondUTC, value.nestedKind.Format) + } } func TestParseFromInterfaceDateTime(t *testing.T) { diff --git a/lib/typing/ext/variables.go b/lib/typing/ext/variables.go index bda6d8812..8d4f413ab 100644 --- a/lib/typing/ext/variables.go +++ b/lib/typing/ext/variables.go @@ -11,8 +11,16 @@ const ( ) var supportedDateTimeLayouts = []string{ + // UTC RFC3339MillisecondUTC, + RFC3339MicrosecondUTC, + RFC3339NanosecondUTC, + // RFC 3339 + RFC3339Millisecond, + RFC3339Microsecond, + RFC3339Nanosecond, time.RFC3339Nano, + // Others ISO8601, time.Layout, time.ANSIC, @@ -39,6 +47,8 @@ var SupportedTimeFormats = []string{ // RFC3339 variants const ( RFC3339MillisecondUTC = "2006-01-02T15:04:05.000Z" + RFC3339MicrosecondUTC = "2006-01-02T15:04:05.000000Z" + RFC3339NanosecondUTC = "2006-01-02T15:04:05.000000000Z" RFC3339Millisecond = "2006-01-02T15:04:05.000Z07:00" RFC3339Microsecond = "2006-01-02T15:04:05.000000Z07:00" RFC3339Nanosecond = "2006-01-02T15:04:05.000000000Z07:00"