github.com/hedzr/evendeep@v0.4.8/diff/c_time.go (about)

     1  package diff
     2  
     3  import (
     4  	"github.com/hedzr/evendeep/internal/tool"
     5  
     6  	"reflect"
     7  	"time"
     8  )
     9  
    10  type timeComparer struct{}
    11  
    12  func (c *timeComparer) Match(typ reflect.Type) bool {
    13  	return typ.String() == "time.Time"
    14  }
    15  
    16  func (c *timeComparer) Equal(ctx Context, lhs, rhs reflect.Value, path Path) (equal bool) {
    17  	aTime := lhs.Interface().(time.Time) //nolint:errcheck //no need
    18  	bTime := rhs.Interface().(time.Time) //nolint:errcheck //no need
    19  	if equal = aTime.Equal(bTime); !equal {
    20  		ctx.PutModified(ctx.PutPath(path), Update{Old: aTime.String(), New: bTime.String(), Typ: tool.Typfmtvlite(&lhs)})
    21  	}
    22  	return
    23  }