From 4872006e0099266622f3173d67dac8ac4674fa38 Mon Sep 17 00:00:00 2001 From: Liam McGregor <88196797+mtlljm@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:25:52 +0000 Subject: [PATCH] data is a integer in seconds(#16) * data is a integer in seconds Change-Id: Id66503d4338df79f7f4eb7534db14127aa8ba328 Signed-off-by: mtlljm --- internal/esp/client/espwsclient.go | 16 ++++++++++++++++ internal/esp/field/field.go | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/esp/client/espwsclient.go b/internal/esp/client/espwsclient.go index 52bcbd5..ce3f006 100644 --- a/internal/esp/client/espwsclient.go +++ b/internal/esp/client/espwsclient.go @@ -455,6 +455,9 @@ func parseFieldValue(rawValue any, sub *subscription, schemaType field.SchemaTyp case field.Timestamp: signed := int64(rawValue.(uint64)) fieldValue = time.UnixMicro(signed) + case field.Date: + signed := int64(rawValue.(uint64)) + fieldValue = time.Unix(signed, 0) default: fieldValue = rawValue } @@ -497,6 +500,14 @@ func parseJsonFieldValue(rawValue any, schemaType field.SchemaType) any { } fieldValue = time.UnixMicro(fieldValueInt) + case field.Date: + fieldValueInt, err := strconv.ParseInt(fieldValueString, 10, 64) + if err != nil { + log.DefaultLogger.Error(fmt.Sprintf("Cannot convert field value to type timestamp: %s", fieldValueString)) + panic(err) + } + + fieldValue = time.Unix(fieldValueInt, 0) default: err := fmt.Errorf("unsupported field type %d", schemaType) log.DefaultLogger.Error(err.Error()) @@ -543,6 +554,11 @@ func (espWsClient *EspWsClient) validateField(name string, value any, sub *subsc case uint64: return nil } + case field.Date: + switch value.(type) { + case uint64: + return nil + } default: err := fmt.Errorf("unexpected schema field type %v", fieldType) log.DefaultLogger.Error(err.Error()) diff --git a/internal/esp/field/field.go b/internal/esp/field/field.go index 5fc53a6..9816440 100644 --- a/internal/esp/field/field.go +++ b/internal/esp/field/field.go @@ -37,6 +37,7 @@ const ( Int Timestamp String + Date ) var ( @@ -45,7 +46,7 @@ var ( "array(i32)": Array, "array(i64)": Array, "blob": Blob, - "date": String, + "date": Date, "double": Double, "int32": Int, "int64": Int,