From 422700363e9c0e900b15f8de48bdd3d2d84e7b15 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Tue, 10 May 2016 12:14:38 -0600 Subject: [PATCH] feat(pkg): add a timeconv.String function Rather than do the same formatting repeatedly, we can just call a convenience function to format to a specific format. --- cmd/helm/install.go | 3 +-- cmd/helm/list.go | 3 +-- cmd/helm/status.go | 3 +-- pkg/timeconv/timeconv.go | 10 ++++++++++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 4d25b2dd1..cca37fe4e 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "time" "github.com/spf13/cobra" @@ -64,7 +63,7 @@ func printRelease(rel *release.Release) { } if flagVerbose { fmt.Printf("NAME: %s\n", rel.Name) - fmt.Printf("INFO: %s %s\n", timeconv.Format(rel.Info.LastDeployed, time.ANSIC), rel.Info.Status) + fmt.Printf("INFO: %s %s\n", timeconv.String(rel.Info.LastDeployed), rel.Info.Status) fmt.Printf("CHART: %s %s\n", rel.Chart.Metadata.Name, rel.Chart.Metadata.Version) fmt.Printf("MANIFEST: %s\n", rel.Manifest) } else { diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 19e9f6c9e..541b3d39f 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -3,7 +3,6 @@ package main import ( "fmt" "sort" - "time" "github.com/gosuri/uitable" "github.com/kubernetes/helm/pkg/helm" @@ -79,7 +78,7 @@ func formatList(rels []*release.Release) error { table.AddRow("NAME", "UPDATED", "CHART") for _, r := range rels { c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version) - t := timeconv.Format(r.Info.LastDeployed, time.ANSIC) + t := timeconv.String(r.Info.LastDeployed) table.AddRow(r.Name, t, c) } fmt.Println(table) diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 5a381545d..881af7212 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "time" "github.com/kubernetes/helm/pkg/helm" "github.com/kubernetes/helm/pkg/timeconv" @@ -34,7 +33,7 @@ func status(cmd *cobra.Command, args []string) error { return err } - fmt.Printf("Last Deployed: %s\n", timeconv.Format(res.Info.LastDeployed, time.ANSIC)) + fmt.Printf("Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) fmt.Printf("Status: %s\n", res.Info.Status.Code) if res.Info.Status.Details != nil { fmt.Printf("Details: %s\n", res.Info.Status.Details) diff --git a/pkg/timeconv/timeconv.go b/pkg/timeconv/timeconv.go index 8a3fb31c4..34089d92f 100644 --- a/pkg/timeconv/timeconv.go +++ b/pkg/timeconv/timeconv.go @@ -30,3 +30,13 @@ func Time(ts *timestamp.Timestamp) time.Time { func Format(ts *timestamp.Timestamp, layout string) string { return Time(ts).Format(layout) } + +// String formats the timestamp into a user-friendly string. +// +// Currently, this uses the 'time.ANSIC' format string, but there is no guarantee +// that this will not change. +// +// This is a convenience function for formatting timestamps for user display. +func String(ts *timestamp.Timestamp) string { + return Format(ts, time.ANSIC) +}