Skip to content

Commit

Permalink
Remove unecessary regex pattern for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xtineskim committed Aug 22, 2024
1 parent b7ca574 commit f36389e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/utils/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func ParseDuration(s string) (*time.Duration, error) {
return &parsedTime, nil
}

var reSplit = regexp.MustCompile(`[0-9]{1,5}(h|ms|s|m)`)

const maxDuration = 99999*time.Hour + 59*time.Minute + 59*time.Second + 999*time.Millisecond

func FormatDuration(duration time.Duration) (string, error) {
Expand Down Expand Up @@ -91,26 +89,27 @@ func FormatDuration(duration time.Duration) (string, error) {
seconds := int(duration.Seconds())

// calculating the hours
hours := int(seconds / 3600)
hours := seconds / 3600

if hours > 0 {
output += fmt.Sprintf("%dh", hours)
seconds -= hours * 3600
}

// calculating the minutes
minutes := int(seconds / 60)
minutes := seconds / 60

if minutes > 0 {
output += fmt.Sprintf("%dm", minutes)
seconds -= minutes * 60
}

// calculating the seconds
if seconds > 0 {
output += fmt.Sprintf("%ds", seconds)
}

// Golang's time.Duration allows for floating point seconds instead of converting to ms
// calculating the milliseconds
durationMilliseconds := durationMicroseconds / 1000

ms := durationMilliseconds % 1000
Expand Down

0 comments on commit f36389e

Please sign in to comment.