[#1074] neofs-cli: Move PrettyPrintUnixTime to the common package

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-26 09:41:17 +03:00 committed by fyrchik
parent b432558aaa
commit 736e09a70d
3 changed files with 17 additions and 13 deletions

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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())