Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for range queries on time fields (#429)
* refactor: Index datetime fields as int64 * fix: addressing PR feedback * refactor: Remove schema dependency from lib
- Loading branch information
1 parent
bcbe062
commit d19ac5e
Showing
9 changed files
with
140 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package date | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// ToUnixNano converts a time to Unix nano seconds | ||
func ToUnixNano(format string, dateStr string) (int64, error) { | ||
t, err := time.Parse(format, dateStr) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return t.UnixNano(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package date | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"time" | ||
) | ||
|
||
func TestToUnixNano(t *testing.T) { | ||
validCases := []struct { | ||
name string | ||
date string | ||
expected int64 | ||
}{ | ||
{"UTC RFC 3339", "2022-10-18T00:51:07+00:00", 1666054267000000000}, | ||
{"UTC RFC 3339 Nano", "2022-10-18T00:51:07.528106+00:00", 1666054267528106000}, | ||
{"IST RFC 3339", "2022-10-11T04:19:32+05:30", 1665442172000000000}, | ||
{"IST RFC 3339 Nano", "2022-10-18T00:51:07.999999999+05:30", 1666034467999999999}, | ||
{"No TZ RFC 3339", "2022-10-18T00:51:07Z", 1666054267000000000}, | ||
} | ||
|
||
for _, v := range validCases { | ||
t.Run(v.name, func(t *testing.T) { | ||
actual, err := ToUnixNano(time.RFC3339Nano, v.date) | ||
assert.NoError(t, err) | ||
assert.Equal(t, v.expected, actual) | ||
}) | ||
} | ||
|
||
failureCases := []struct { | ||
name string | ||
date string | ||
errorLike string | ||
}{ | ||
{"RFC 1123", "Mon, 02 Jan 2006 15:04:05 MST", "cannot parse"}, | ||
} | ||
|
||
for _, v := range failureCases { | ||
t.Run(v.name, func(t *testing.T) { | ||
_, err := ToUnixNano(time.RFC3339Nano, v.date) | ||
assert.ErrorContains(t, err, v.errorLike) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters