Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an additional timestamp layout. #918

Merged
merged 4 commits into from
Sep 19, 2024
Merged
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
21 changes: 21 additions & 0 deletions lib/typing/ext/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ 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")
}
{
// 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) {
Expand Down
18 changes: 15 additions & 3 deletions lib/typing/ext/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ const (
)

var supportedDateTimeLayouts = []string{
// UTC
RFC3339MillisecondUTC,
RFC3339MicrosecondUTC,
RFC3339NanosecondUTC,
// RFC 3339
RFC3339Millisecond,
RFC3339Microsecond,
RFC3339Nanosecond,
time.RFC3339Nano,
// Others
ISO8601,
time.Layout,
time.ANSIC,
Expand All @@ -37,7 +46,10 @@ 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"
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add RFC3339MicrosecondUTC and RFC3339Nanosecond UTC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't hurt, I'll add!

RFC3339Nanosecond = "2006-01-02T15:04:05.000000000Z07:00"
)