From 7d2bba13759dbdea88106a435b67820b2a79dbff Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Fri, 7 Aug 2020 11:40:17 +0530 Subject: [PATCH] cephfs: introduce parsetime() to parse createdAt field in snap return Signed-off-by: Humble Chirammal --- internal/cephfs/util.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/cephfs/util.go b/internal/cephfs/util.go index e67bf9e8c..c6039b44f 100644 --- a/internal/cephfs/util.go +++ b/internal/cephfs/util.go @@ -21,10 +21,13 @@ import ( "encoding/json" "errors" "fmt" + "time" "github.com/ceph/ceph-csi/internal/util" "github.com/container-storage-interface/spec/lib/go/csi" + "github.com/golang/protobuf/ptypes" + "github.com/golang/protobuf/ptypes/timestamp" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" klog "k8s.io/klog/v2" @@ -158,3 +161,21 @@ func getMonsAndClusterID(ctx context.Context, options map[string]string) (monito return } + +func parseTime(ctx context.Context, createTime string) (*timestamp.Timestamp, error) { + tm := ×tamp.Timestamp{} + layout := "2006-01-02 15:04:05.000000" + // TODO currently parsing of timestamp to time.ANSIC generate from ceph fs is failng + var t time.Time + t, err := time.Parse(layout, createTime) + if err != nil { + klog.Errorf(util.Log(ctx, "failed to parse time %s %v"), createTime, err) + return tm, err + } + tm, err = ptypes.TimestampProto(t) + if err != nil { + klog.Errorf(util.Log(ctx, "failed to convert time %s %v"), createTime, err) + return tm, err + } + return tm, nil +}