Merge pull request #998 from trheyi/main
Enhance time value handling and improve test assertions
This commit is contained in:
commit
852815ca67
3 changed files with 44 additions and 1 deletions
13
dsl/io/db.go
13
dsl/io/db.go
|
|
@ -46,6 +46,19 @@ func fmtRow(row map[string]interface{}) map[string]interface{} {
|
||||||
if row["built_in"] != nil {
|
if row["built_in"] != nil {
|
||||||
row["built_in"] = toBool(row["built_in"])
|
row["built_in"] = toBool(row["built_in"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert time values
|
||||||
|
if mtime, ok := row["mtime"]; ok && mtime != nil {
|
||||||
|
if timeStr := toTime(mtime); timeStr != "" {
|
||||||
|
row["mtime"] = timeStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ctime, ok := row["ctime"]; ok && ctime != nil {
|
||||||
|
if timeStr := toTime(ctime); timeStr != "" {
|
||||||
|
row["ctime"] = timeStr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,9 @@ func TestDBList(t *testing.T) {
|
||||||
list, err = db.List(tc1.ListOptions(false))
|
list, err = db.List(tc1.ListOptions(false))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 1, len(list))
|
assert.Equal(t, 1, len(list))
|
||||||
|
if assert.Greater(t, len(list), 0, "List should not be empty") {
|
||||||
assert.Equal(t, tc1.ID, list[0].ID)
|
assert.Equal(t, tc1.ID, list[0].ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDBUpdate(t *testing.T) {
|
func TestDBUpdate(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package io
|
package io
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// toBool converts various types to boolean
|
// toBool converts various types to boolean
|
||||||
func toBool(v interface{}) bool {
|
func toBool(v interface{}) bool {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
|
@ -21,3 +23,29 @@ func toBool(v interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toTime converts various time formats to RFC3339 string
|
||||||
|
func toTime(v interface{}) string {
|
||||||
|
if v == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
switch val := v.(type) {
|
||||||
|
case string:
|
||||||
|
// Try common formats
|
||||||
|
formats := []string{
|
||||||
|
"2006-01-02 15:04:05", // SQLite format
|
||||||
|
"2006-01-02T15:04:05Z07:00", // RFC3339 format
|
||||||
|
"2006-01-02T15:04:05Z", // RFC3339 without timezone
|
||||||
|
time.RFC3339,
|
||||||
|
}
|
||||||
|
for _, format := range formats {
|
||||||
|
if t, err := time.Parse(format, val); err == nil {
|
||||||
|
return t.UTC().Format(time.RFC3339) // Convert to UTC and format as RFC3339
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case time.Time:
|
||||||
|
return val.UTC().Format(time.RFC3339) // Convert to UTC and format as RFC3339
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue