cmd/headscale/cli: use HeadscaleDateTimeFormat and util.Base10 consistently

Replace five hardcoded "2006-01-02 15:04:05" strings with the
HeadscaleDateTimeFormat constant already defined in utils.go.
Replace two literal 10 base arguments to strconv.FormatUint with
util.Base10 to match the convention in api_key.go and nodes.go.
This commit is contained in:
Kristoffer Dalby
2026-02-18 15:25:14 +00:00
parent 2765fd397f
commit ca321d3c13
4 changed files with 9 additions and 7 deletions

View File

@@ -315,7 +315,7 @@ func nodesToPtables(
if node.GetLastSeen() != nil {
lastSeen = node.GetLastSeen().AsTime()
lastSeenTime = lastSeen.Format("2006-01-02 15:04:05")
lastSeenTime = lastSeen.Format(HeadscaleDateTimeFormat)
}
var (
@@ -325,7 +325,7 @@ func nodesToPtables(
if node.GetExpiry() != nil {
expiry = node.GetExpiry().AsTime()
expiryTime = expiry.Format("2006-01-02 15:04:05")
expiryTime = expiry.Format(HeadscaleDateTimeFormat)
} else {
expiryTime = "N/A"
}

View File

@@ -7,6 +7,7 @@ import (
"strings"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/hscontrol/util"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)
@@ -80,13 +81,13 @@ var listPreAuthKeys = &cobra.Command{
}
tableData = append(tableData, []string{
strconv.FormatUint(key.GetId(), 10),
strconv.FormatUint(key.GetId(), util.Base10),
key.GetKey(),
strconv.FormatBool(key.GetReusable()),
strconv.FormatBool(key.GetEphemeral()),
strconv.FormatBool(key.GetUsed()),
expiration,
key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"),
key.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat),
owner,
})
}

View File

@@ -7,7 +7,7 @@ import (
)
func ColourTime(date time.Time) string {
dateStr := date.Format("2006-01-02 15:04:05")
dateStr := date.Format(HeadscaleDateTimeFormat)
if date.After(time.Now()) {
dateStr = pterm.LightGreen(dateStr)

View File

@@ -8,6 +8,7 @@ import (
"strconv"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/hscontrol/util"
"github.com/juanfont/headscale/hscontrol/util/zlog/zf"
"github.com/pterm/pterm"
"github.com/rs/zerolog/log"
@@ -189,11 +190,11 @@ var listUsersCmd = &cobra.Command{
tableData = append(
tableData,
[]string{
strconv.FormatUint(user.GetId(), 10),
strconv.FormatUint(user.GetId(), util.Base10),
user.GetDisplayName(),
user.GetName(),
user.GetEmail(),
user.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"),
user.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat),
},
)
}