diff --git a/lib/typing/ext/time.go b/lib/typing/ext/time.go index 93243eb41..cd9e92b7b 100644 --- a/lib/typing/ext/time.go +++ b/lib/typing/ext/time.go @@ -47,8 +47,7 @@ func NewNestedKind(kindType ExtendedTimeKindType, optionalFormat string) (Nested // ExtendedTime is created because Golang's time.Time does not allow us to explicitly cast values as a date, or time // and only allows timestamp expressions. type ExtendedTime struct { - ts time.Time - nestedKind NestedKind + ts time.Time } // MarshalJSON is a custom JSON marshaller for ExtendedTime. @@ -58,26 +57,12 @@ func (e ExtendedTime) MarshalJSON() ([]byte, error) { return e.ts.UTC().MarshalJSON() } -// TODO: Have this return an error instead of nil func NewExtendedTime(t time.Time, kindType ExtendedTimeKindType, originalFormat string) *ExtendedTime { - defaultLayout, err := kindType.defaultLayout() - if err != nil { - return nil - } - return &ExtendedTime{ ts: t, - nestedKind: NestedKind{ - Type: kindType, - Format: cmp.Or(originalFormat, defaultLayout), - }, } } func (e *ExtendedTime) GetTime() time.Time { return e.ts } - -func (e *ExtendedTime) GetNestedKind() NestedKind { - return e.nestedKind -} diff --git a/lib/typing/mongo/bson.go b/lib/typing/mongo/bson.go index 9b6bd71be..494fb078f 100644 --- a/lib/typing/mongo/bson.go +++ b/lib/typing/mongo/bson.go @@ -11,8 +11,6 @@ import ( "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" - - "github.com/artie-labs/transfer/lib/typing/ext" ) // JSONEToMap - Takes a JSON Extended string and converts it to a map[string]any @@ -89,9 +87,9 @@ func bsonBinaryValueToMap(value primitive.Binary) (any, error) { func bsonValueToGoValue(value any) (any, error) { switch v := value.(type) { case primitive.DateTime: - return ext.NewExtendedTime(v.Time().UTC(), ext.TimestampTZKindType, ext.ISO8601), nil + return v.Time().UTC(), nil case primitive.Timestamp: - return ext.NewExtendedTime(time.Unix(int64(v.T), 0).UTC(), ext.TimestampTZKindType, ext.ISO8601), nil + return time.Unix(int64(v.T), 0).UTC(), nil case primitive.ObjectID: return v.Hex(), nil case primitive.Binary: diff --git a/lib/typing/parse.go b/lib/typing/parse.go index fe6edb36b..15d6d3c83 100644 --- a/lib/typing/parse.go +++ b/lib/typing/parse.go @@ -3,6 +3,7 @@ package typing import ( "fmt" "reflect" + "time" "github.com/artie-labs/transfer/lib/typing/decimal" "github.com/artie-labs/transfer/lib/typing/ext" @@ -48,12 +49,10 @@ func ParseValue(key string, optionalSchema map[string]KindDetails, val any) (Kin Kind: EDecimal.Kind, ExtendedDecimalDetails: &extendedDetails, }, nil - case *ext.ExtendedTime: - nestedKind := convertedVal.GetNestedKind() - return KindDetails{ - Kind: ETime.Kind, - ExtendedTimeDetails: &nestedKind, - }, nil + case time.Time: + // time.Time should only appear for bson.Timestamp and bson.DateTime + // All other sources will have an optional schema + return NewExtendedTimeDetails(ETime, ext.TimestampTZKindType, "") default: // Check if the val is one of our custom-types if reflect.TypeOf(val).Kind() == reflect.Slice {