Skip to content

Commit

Permalink
Add RFC3339Nano to supported formats for time
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Apr 5, 2023
1 parent 333a892 commit cb3c4a1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func ConvertToSafeType(arg string, dataType DataType) (interface{}, bool) {
}

func validateTime(timeStr string) bool {
for _, format := range []string{time.RFC3339, "2006-01-02 15:04:05", "2006-01-02"} {
for _, format := range []string{time.RFC3339, time.RFC3339Nano, "2006-01-02 15:04:05", "2006-01-02"} {
_, err := time.Parse(format, timeStr)
if err == nil {
return true
Expand Down
2 changes: 2 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ func TestConvertToSafeType(t *testing.T) {
{value: "2023-03-23", dataType: DataTypeTime, want: "2023-03-23", wantOk: true},
{value: "2023-03-23 12:13:24", dataType: DataTypeTime, want: "2023-03-23 12:13:24", wantOk: true},
{value: "2023-03-23T12:13:24Z", dataType: DataTypeTime, want: "2023-03-23T12:13:24Z", wantOk: true},
{value: "2022-11-02T09:12:03.081967+01:00", dataType: DataTypeTime, want: "2022-11-02T09:12:03.081967+01:00", wantOk: true},
{value: "2023-03-23T12:13:24", dataType: DataTypeTime, want: nil, wantOk: false},
{value: "not a date", dataType: DataTypeTime, want: nil, wantOk: false},
{value: "1234", dataType: DataTypeTime, want: nil, wantOk: false},
{value: "2023-03-23", dataType: DataTypeTimeArray, want: "2023-03-23", wantOk: true},
{value: "2023-03-23 12:13:24", dataType: DataTypeTimeArray, want: "2023-03-23 12:13:24", wantOk: true},
{value: "2023-03-23T12:13:24Z", dataType: DataTypeTimeArray, want: "2023-03-23T12:13:24Z", wantOk: true},
{value: "2022-11-02T09:12:03.081967+01:00", dataType: DataTypeTimeArray, want: "2022-11-02T09:12:03.081967+01:00", wantOk: true},
{value: "2023-03-23T12:13:24", dataType: DataTypeTimeArray, want: nil, wantOk: false},
{value: "not a date", dataType: DataTypeTimeArray, want: nil, wantOk: false},
{value: "1234", dataType: DataTypeTimeArray, want: nil, wantOk: false},
Expand Down

0 comments on commit cb3c4a1

Please sign in to comment.