Skip to content

Commit

Permalink
Consolidate time formatting logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
drn committed Nov 10, 2018
1 parent b8ba4a9 commit f722b0b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions format/long.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package format
import (
"fmt"
"math"
"time"
"regexp"
"strings"
"strconv"
Expand Down Expand Up @@ -60,9 +61,7 @@ func extractValues(node node.Node) []string {
fmt.Sprintf("%s ", node.User),
fmt.Sprintf("%s ", node.Group),
formatSize(node.Size),
node.Time.Month().String()[:3],
fmt.Sprintf("%2d", node.Time.Day()),
fmt.Sprintf("%02d:%02d", node.Time.Hour(), node.Time.Minute()),
formatTime(node.Time),
fmt.Sprintf(" %s", node.Name),
}
}
Expand All @@ -83,6 +82,16 @@ func formatSize(sizeInt int) string {
return color.New(color.FgRed, color.Bold).Sprint(str)
}

func formatTime(time time.Time) string {
return fmt.Sprintf(
"%s %s %02d:%02d",
time.Month().String()[:3],
fmt.Sprintf("%2d", time.Day()),
time.Hour(),
time.Minute(),
)
}

// strips ANSI color codes from string
func strip(str string) string {
return ansiRegex.ReplaceAllString(str, "")
Expand Down

0 comments on commit f722b0b

Please sign in to comment.