Skip to content

Commit

Permalink
data is a integer in seconds(#16)
Browse files Browse the repository at this point in the history
* data is a integer in seconds
Change-Id: Id66503d4338df79f7f4eb7534db14127aa8ba328
Signed-off-by: mtlljm <[email protected]>
  • Loading branch information
mtlljm authored Nov 19, 2024
1 parent d737e85 commit 4872006
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/esp/client/espwsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion internal/esp/field/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
Int
Timestamp
String
Date
)

var (
Expand All @@ -45,7 +46,7 @@ var (
"array(i32)": Array,
"array(i64)": Array,
"blob": Blob,
"date": String,
"date": Date,
"double": Double,
"int32": Int,
"int64": Int,
Expand Down

0 comments on commit 4872006

Please sign in to comment.