From 736e09a70d50096a466aa452ec53fd7c9b984c5e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 26 May 2022 09:41:17 +0300 Subject: [PATCH] [#1074] neofs-cli: Move `PrettyPrintUnixTime` to the `common` package Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/internal/common/verbose.go | 15 +++++++++++++++ cmd/neofs-cli/modules/container.go | 13 +------------ cmd/neofs-cli/modules/object.go | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/neofs-cli/internal/common/verbose.go b/cmd/neofs-cli/internal/common/verbose.go index 48f9a2bbe..847349d67 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 1bba58126..6817dee53 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 b2dacad27..ed9a54524 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())