Skip to content

Commit

Permalink
move common time behaviour to own package (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jun 4, 2021
1 parent 27f6028 commit 929b10b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
5 changes: 0 additions & 5 deletions pkg/common/time.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/service/list.go
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v3/fastly"
)

Expand Down Expand Up @@ -38,7 +39,7 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
for _, service := range services {
updatedAt := "n/a"
if service.UpdatedAt != nil {
updatedAt = service.UpdatedAt.UTC().Format(common.TimeFormat)
updatedAt = service.UpdatedAt.UTC().Format(time.Format)
}

activeVersion := fmt.Sprint(service.ActiveVersion)
Expand Down
3 changes: 2 additions & 1 deletion pkg/serviceversion/list.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v3/fastly"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
tw := text.NewTable(out)
tw.AddHeader("NUMBER", "ACTIVE", "LAST EDITED (UTC)")
for _, version := range versions {
tw.AddLine(version.Number, version.Active, version.UpdatedAt.UTC().Format(common.TimeFormat))
tw.AddLine(version.Number, version.Active, version.UpdatedAt.UTC().Format(time.Format))
}
tw.Print()
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/text/dictionary.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v3/fastly"
"github.com/segmentio/textio"
)
Expand All @@ -18,9 +18,9 @@ func PrintDictionary(out io.Writer, prefix string, d *fastly.Dictionary) {
fmt.Fprintf(out, "ID: %s\n", d.ID)
fmt.Fprintf(out, "Name: %s\n", d.Name)
fmt.Fprintf(out, "Write Only: %t\n", d.WriteOnly)
fmt.Fprintf(out, "Created (UTC): %s\n", d.CreatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Last edited (UTC): %s\n", d.UpdatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Created (UTC): %s\n", d.CreatedAt.UTC().Format(time.Format))
fmt.Fprintf(out, "Last edited (UTC): %s\n", d.UpdatedAt.UTC().Format(time.Format))
if d.DeletedAt != nil {
fmt.Fprintf(out, "Deleted (UTC): %s\n", d.DeletedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Deleted (UTC): %s\n", d.DeletedAt.UTC().Format(time.Format))
}
}
8 changes: 4 additions & 4 deletions pkg/text/dictionaryitem.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v3/fastly"
"github.com/segmentio/textio"
)
Expand All @@ -19,13 +19,13 @@ func PrintDictionaryItem(out io.Writer, prefix string, d *fastly.DictionaryItem)
fmt.Fprintf(out, "Item Key: %s\n", d.ItemKey)
fmt.Fprintf(out, "Item Value: %s\n", d.ItemValue)
if d.CreatedAt != nil {
fmt.Fprintf(out, "Created (UTC): %s\n", d.CreatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Created (UTC): %s\n", d.CreatedAt.UTC().Format(time.Format))
}
if d.UpdatedAt != nil {
fmt.Fprintf(out, "Last edited (UTC): %s\n", d.UpdatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Last edited (UTC): %s\n", d.UpdatedAt.UTC().Format(time.Format))
}
if d.DeletedAt != nil {
fmt.Fprintf(out, "Deleted (UTC): %s\n", d.DeletedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Deleted (UTC): %s\n", d.DeletedAt.UTC().Format(time.Format))
}
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/text/service.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"io"

"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/time"
"github.com/fastly/go-fastly/v3/fastly"
"github.com/segmentio/textio"
)
Expand Down Expand Up @@ -35,13 +35,13 @@ func PrintService(out io.Writer, prefix string, s *fastly.Service) {
}
fmt.Fprintf(out, "Customer ID: %s\n", s.CustomerID)
if s.CreatedAt != nil {
fmt.Fprintf(out, "Created (UTC): %s\n", s.CreatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Created (UTC): %s\n", s.CreatedAt.UTC().Format(time.Format))
}
if s.UpdatedAt != nil {
fmt.Fprintf(out, "Last edited (UTC): %s\n", s.UpdatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Last edited (UTC): %s\n", s.UpdatedAt.UTC().Format(time.Format))
}
if s.DeletedAt != nil {
fmt.Fprintf(out, "Deleted (UTC): %s\n", s.DeletedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Deleted (UTC): %s\n", s.DeletedAt.UTC().Format(time.Format))
}
fmt.Fprintf(out, "Active version: %d\n", s.ActiveVersion)
fmt.Fprintf(out, "Versions: %d\n", len(s.Versions))
Expand Down Expand Up @@ -73,13 +73,13 @@ func PrintServiceDetail(out io.Writer, indent string, s *fastly.ServiceDetail) {
}
fmt.Fprintf(out, "Customer ID: %s\n", s.CustomerID)
if s.CreatedAt != nil {
fmt.Fprintf(out, "Created (UTC): %s\n", s.CreatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Created (UTC): %s\n", s.CreatedAt.UTC().Format(time.Format))
}
if s.UpdatedAt != nil {
fmt.Fprintf(out, "Last edited (UTC): %s\n", s.UpdatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Last edited (UTC): %s\n", s.UpdatedAt.UTC().Format(time.Format))
}
if s.DeletedAt != nil {
fmt.Fprintf(out, "Deleted (UTC): %s\n", s.DeletedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Deleted (UTC): %s\n", s.DeletedAt.UTC().Format(time.Format))
}
if s.ActiveVersion.Active {
fmt.Fprintf(out, "Active version:\n")
Expand Down Expand Up @@ -111,12 +111,12 @@ func PrintVersion(out io.Writer, indent string, v *fastly.Version) {
fmt.Fprintf(out, "Staging: %v\n", v.Staging)
fmt.Fprintf(out, "Testing: %v\n", v.Testing)
if v.CreatedAt != nil {
fmt.Fprintf(out, "Created (UTC): %s\n", v.CreatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Created (UTC): %s\n", v.CreatedAt.UTC().Format(time.Format))
}
if v.UpdatedAt != nil {
fmt.Fprintf(out, "Last edited (UTC): %s\n", v.UpdatedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Last edited (UTC): %s\n", v.UpdatedAt.UTC().Format(time.Format))
}
if v.DeletedAt != nil {
fmt.Fprintf(out, "Deleted (UTC): %s\n", v.DeletedAt.UTC().Format(common.TimeFormat))
fmt.Fprintf(out, "Deleted (UTC): %s\n", v.DeletedAt.UTC().Format(time.Format))
}
}
2 changes: 2 additions & 0 deletions pkg/time/doc.go
@@ -0,0 +1,2 @@
// Package time contains helper abstractions for working with time formats.
package time
5 changes: 5 additions & 0 deletions pkg/time/time.go
@@ -0,0 +1,5 @@
package time

// Format is a format string for time.Format that reflects what the Fastly web
// UI uses.
const Format = "2006-01-02 15:04"

0 comments on commit 929b10b

Please sign in to comment.