refactor: use new flux function to format duration literals (#22403)

pull/22405/head
Daniel Moran 2021-09-07 11:12:25 -04:00 committed by GitHub
parent 824e76c18d
commit 6418f693f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 13 deletions

View File

@ -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.