Add support for SELECT_JSON statements.

This commit is contained in:
go-jet 2025-02-21 19:55:01 +01:00
parent 7047de44a9
commit 7b16e432ff
46 changed files with 2732 additions and 307 deletions

View file

@ -1,6 +1,9 @@
package datetime
import "time"
import (
//"github.com/go-jet/jet/v2/internal/utils/min"
"time"
)
// ExtractTimeComponents extracts number of days, hours, minutes, seconds, microseconds from duration
func ExtractTimeComponents(duration time.Duration) (days, hours, minutes, seconds, microseconds int64) {
@ -20,3 +23,36 @@ func ExtractTimeComponents(duration time.Duration) (days, hours, minutes, second
return
}
// TryParseAsTime attempts to parse the provided value as a time using one of the given formats.
//
// The function iterates over the provided formats and tries to parse the value into a time.Time object.
// It returns the parsed time and a boolean indicating whether the parsing was successful.
func TryParseAsTime(value interface{}, formats []string) (time.Time, bool) {
var timeStr string
switch v := value.(type) {
case string:
timeStr = v
case []byte:
timeStr = string(v)
case int64:
return time.Unix(v, 0), true // sqlite
default:
return time.Time{}, false
}
for _, format := range formats {
formatLen := min(len(format), len(timeStr))
t, err := time.Parse(format[:formatLen], timeStr)
if err != nil {
continue
}
return t, true
}
return time.Time{}, false
}