Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 2725d0d

Browse files
committed
query_result: use strict date format, always include microseconds
Signed-off-by: Radim Hrazdil <[email protected]>
1 parent cdb0937 commit 2725d0d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

platform/model/query_result.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ package model
55
import (
66
"context"
77
"fmt"
8+
"reflect"
9+
"slices"
10+
"strings"
11+
"time"
12+
813
"github.com/QuesmaOrg/quesma/platform/common_table"
914
"github.com/QuesmaOrg/quesma/platform/logger"
1015
"github.com/QuesmaOrg/quesma/platform/schema"
1116
"github.com/QuesmaOrg/quesma/platform/util"
1217
"github.com/goccy/go-json"
13-
"reflect"
14-
"slices"
15-
"strings"
16-
"time"
1718
)
1819

1920
type (
@@ -46,7 +47,9 @@ func (c *QueryResultCol) String(ctx context.Context) string {
4647
}
4748
return fmt.Sprintf(`"%s": %s`, c.ColName, string(processed))
4849
case time.Time:
49-
return fmt.Sprintf(`"%s": "%v"`, c.ColName, valueExtracted)
50+
// Format timestamp with consistent microsecond precision
51+
formattedTime := valueExtracted.(time.Time).Format("2006-01-02 15:04:05.000000 -0700 MST")
52+
return fmt.Sprintf(`"%s": "%s"`, c.ColName, formattedTime)
5053
case int, int64, float64, uint64, bool:
5154
return fmt.Sprintf(`"%s": %v`, c.ColName, valueExtracted)
5255
default:

platform/model/query_result_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestQueryResultCol_String(t *testing.T) {
3434
value any
3535
expected string
3636
}{
37+
{time.Date(2023, 10, 5, 14, 30, 45, 000000000, time.UTC), `"name": "2023-10-05 14:30:45.000000 +0000 UTC"`},
3738
{time.Date(2023, 10, 5, 14, 30, 45, 123456000, time.UTC), `"name": "2023-10-05 14:30:45.123456 +0000 UTC"`},
3839
{"test", `"name": "test"`},
3940
{`test "GET"`, `"name": "test \"GET\""`},
@@ -42,10 +43,10 @@ func TestQueryResultCol_String(t *testing.T) {
4243
{int64(1), `"name": 1`},
4344
{uint64(1), `"name": 1`},
4445
{true, `"name": true`},
45-
{time.Time{}, `"name": "0001-01-01 00:00:00 +0000 UTC"`},
46+
{time.Time{}, `"name": "0001-01-01 00:00:00.000000 +0000 UTC"`},
4647
{strPtr, `"name": ""`},
4748
{strPtrNil, ``},
48-
{timePtr, `"name": "0001-01-01 00:00:00 +0000 UTC"`},
49+
{timePtr, `"name": "0001-01-01 00:00:00.000000 +0000 UTC"`},
4950
{timePtrNil, ``},
5051
{int64Ptr, `"name": 1`},
5152
{int64PtrNil, ``},

0 commit comments

Comments
 (0)