From 6418f693f7a5eea4508da9a94a33fdc26f2764c8 Mon Sep 17 00:00:00 2001 From: Daniel Moran Date: Tue, 7 Sep 2021 11:12:25 -0400 Subject: [PATCH] refactor: use new flux function to format duration literals (#22403) --- task/options/options.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/task/options/options.go b/task/options/options.go index 52568fbc85..4d29e3d8c9 100644 --- a/task/options/options.go +++ b/task/options/options.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "strconv" "strings" "time" @@ -13,6 +12,7 @@ import ( "github.com/influxdata/flux/ast" "github.com/influxdata/flux/ast/edit" "github.com/influxdata/flux/interpreter" + "github.com/influxdata/flux/parser" "github.com/influxdata/flux/values" "github.com/influxdata/influxdb/v2/pkg/pointer" ) @@ -47,18 +47,7 @@ type Duration struct { } func (a Duration) String() string { - // NOTE: This is a copy of `formatDurationLiteral` from the flux codebase. - // We copy it here so we can break the dependency on the Go formatter in this method without a change in behavior. - // The Rust-based formatter doesn't expose an interface for formatting individual nodes. - builder := strings.Builder{} - formatDuration := func(d ast.Duration) { - builder.WriteString(strconv.FormatInt(d.Magnitude, 10)) - builder.WriteString(d.Unit) - } - for _, d := range a.Node.Values { - formatDuration(d) - } - return builder.String() + return parser.FormatDuration(&a.Node) } // Parse parses a string into a Duration.