forked from TrueCloudLab/frostfs-node
[#1074] neofs-cli: Move PrettyPrintUnixTime
to the common
package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
b432558aaa
commit
736e09a70d
3 changed files with 17 additions and 13 deletions
|
@ -2,6 +2,8 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -13,3 +15,16 @@ func PrintVerbose(format string, a ...interface{}) {
|
||||||
fmt.Printf(format+"\n", a...)
|
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()
|
||||||
|
}
|
||||||
|
|
|
@ -755,7 +755,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco
|
||||||
cmd.Printf("attribute: %s=%s (%s)\n",
|
cmd.Printf("attribute: %s=%s (%s)\n",
|
||||||
attribute.Key(),
|
attribute.Key(),
|
||||||
attribute.Value(),
|
attribute.Value(),
|
||||||
prettyPrintUnixTime(attribute.Value()))
|
common.PrettyPrintUnixTime(attribute.Value()))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -788,14 +788,3 @@ func prettyPrintBasicACL(cmd *cobra.Command, basicACL acl.BasicACL) {
|
||||||
}
|
}
|
||||||
cmd.Println()
|
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()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ func printHeader(cmd *cobra.Command, obj *object.Object) error {
|
||||||
cmd.Printf(" %s=%s (%s)\n",
|
cmd.Printf(" %s=%s (%s)\n",
|
||||||
attr.Key(),
|
attr.Key(),
|
||||||
attr.Value(),
|
attr.Value(),
|
||||||
prettyPrintUnixTime(attr.Value()))
|
common.PrettyPrintUnixTime(attr.Value()))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cmd.Printf(" %s=%s\n", attr.Key(), attr.Value())
|
cmd.Printf(" %s=%s\n", attr.Key(), attr.Value())
|
||||||
|
|
Loading…
Reference in a new issue