diff --git a/cmd/neofs-cli/internal/common/verbose.go b/cmd/neofs-cli/internal/common/verbose.go index 48f9a2bb..847349d6 100644 --- a/cmd/neofs-cli/internal/common/verbose.go +++ b/cmd/neofs-cli/internal/common/verbose.go @@ -2,6 +2,8 @@ package common import ( "fmt" + "strconv" + "time" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/spf13/viper" @@ -13,3 +15,16 @@ func PrintVerbose(format string, a ...interface{}) { fmt.Printf(format+"\n", a...) } } + +// PrettyPrintUnixTime interprets s as unix timestamp and prints it as +// a date. Is s is invalid, "malformed" is returned. +func PrettyPrintUnixTime(s string) string { + unixTime, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return "malformed" + } + + timestamp := time.Unix(unixTime, 0) + + return timestamp.String() +} diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 1bba5812..6817dee5 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -755,7 +755,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco cmd.Printf("attribute: %s=%s (%s)\n", attribute.Key(), attribute.Value(), - prettyPrintUnixTime(attribute.Value())) + common.PrettyPrintUnixTime(attribute.Value())) continue } @@ -788,14 +788,3 @@ func prettyPrintBasicACL(cmd *cobra.Command, basicACL acl.BasicACL) { } cmd.Println() } - -func prettyPrintUnixTime(s string) string { - unixTime, err := strconv.ParseInt(s, 10, 64) - if err != nil { - return "malformed" - } - - timestamp := time.Unix(unixTime, 0) - - return timestamp.String() -} diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index b2dacad2..ed9a5452 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -1040,7 +1040,7 @@ func printHeader(cmd *cobra.Command, obj *object.Object) error { cmd.Printf(" %s=%s (%s)\n", attr.Key(), attr.Value(), - prettyPrintUnixTime(attr.Value())) + common.PrettyPrintUnixTime(attr.Value())) continue } cmd.Printf(" %s=%s\n", attr.Key(), attr.Value())