Skip to content
Snippets Groups Projects
Commit c6c4601a authored by Alexander Kovalev's avatar Alexander Kovalev
Browse files

Merge branch 'fix-unaddressable-values-0.23' into 'release/v0.23'

fix unaddressable values

See merge request mashroom/backend/common!56
parents ffc1c160 2029c0e1
Branches release/v0.23
No related tags found
No related merge requests found
......@@ -1634,14 +1634,22 @@ func DecomposeStructName(t reflect.Type, fd *descriptor.DescriptorProto, reduce
return reflect.ValueOf(""), nil
}
tm, ok := reflect.Indirect(internal).Addr().Interface().(*generic.Date)
if !ok {
v := reflect.Indirect(internal)
if !v.IsValid() {
return reflect.ValueOf(""), nil
}
my := v.FieldByName("Year")
mm := v.FieldByName("Month")
md := v.FieldByName("Day")
if !my.CanInt() || !mm.CanInt() || !md.CanInt() {
return reflect.ValueOf(""), nil
}
y := int(tm.GetYear())
m := time.Month(tm.GetMonth())
d := int(tm.GetDay())
y := int(my.Int())
m := time.Month(mm.Int())
d := int(md.Int())
if y == 0 || m == 0 || d == 0 {
return reflect.ValueOf(""), nil
......@@ -1669,16 +1677,16 @@ func DecomposeStructName(t reflect.Type, fd *descriptor.DescriptorProto, reduce
return nil
}
t, err := time.Parse(time.RFC1123, external.String())
ts, err := time.Parse(time.RFC1123, external.String())
if err != nil {
return err
}
t = t.UTC()
ts = ts.UTC()
reflect.Indirect(internal).Set(reflect.ValueOf(timestamppb.Timestamp{
Seconds: t.Unix(),
Nanos: int32(t.Nanosecond()),
Seconds: ts.Unix(),
Nanos: int32(ts.Nanosecond()),
}))
return nil
......@@ -1687,18 +1695,24 @@ func DecomposeStructName(t reflect.Type, fd *descriptor.DescriptorProto, reduce
if IsNil(internal) {
return reflect.ValueOf(""), nil
}
tm, ok := reflect.Indirect(internal).Addr().Interface().(*timestamppb.Timestamp)
if !ok {
v := reflect.Indirect(internal)
if !v.IsValid() {
return reflect.ValueOf(""), nil
}
if (tm.GetSeconds() == (time.Time{}).Unix() || tm.GetSeconds() == 0) && tm.GetNanos() == 0 {
seconds := v.FieldByName("Seconds")
nanos := v.FieldByName("Nanos")
if !seconds.CanInt() || !nanos.CanInt() {
return reflect.ValueOf(""), nil
}
t := time.Unix(tm.GetSeconds(), int64(tm.GetNanos()))
if (seconds.Int() == (time.Time{}).Unix() || seconds.Int() == 0) && nanos.Int() == 0 {
return reflect.ValueOf(""), nil
}
return reflect.ValueOf(t.UTC().Format(time.RFC1123)), nil
return reflect.ValueOf(time.Unix(seconds.Int(), nanos.Int()).UTC().Format(time.RFC1123)), nil
},
Type: t,
Bind: &BindScalar{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment