Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions host/host_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ func parseUptime(uptime string) uint64 {
var err error

switch ut[3] {
Copy link
Contributor

@mmorel-35 mmorel-35 Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using this :

func clearTime(ut string) string {
    return strings.TrimRight(strings.TrimRight(ut, ","),"s")
}

So you just switch on singular words for "day" or "hr" or "min" ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also agree with this, but it can get messy when ut[5] and ut[7] may or may not exist (you cannot trim them ahead of time).

I don't agree with the function name though. "clearTime" makes it seem like you're removing the time, rather than just trimming a string on the time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just a suggestion, everything can be changed. The main goal is to decouple the cleaning of comma and s and then look for the type of time

case "day,", "days,":
case "day,", "days,", "day", "days":
days, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil {
return 0
}

// day provided along with a single hour or hours
// ie: up 2 days, 20 hrs,
if ut[5] == "hr," || ut[5] == "hrs," {
if ut[5] == "hr," || ut[5] == "hrs," ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a subhandling for mins to be in ut[7], for a case where you have 20 days, 17 hrs, 5 mins

it all of these ifs should likely be exists/nil protected as well, since these array elements will only exist if the returned value previously has enough elements to fill it out this far.

Also both of these if ut[5] should probably be another switch/case statement for consistency.

ut[5] == "hr" || ut[5] == "hrs" {
hours, err = strconv.ParseUint(ut[4], 10, 64)
if err != nil {
return 0
Expand All @@ -85,7 +86,8 @@ func parseUptime(uptime string) uint64 {

// mins provided along with a single min or mins
// ie: up 4 days, 29 mins,
if ut[5] == "min," || ut[5] == "mins," {
if ut[5] == "min," || ut[5] == "mins," ||
ut[5] == "min" || ut[5] == "mins" {
mins, err = strconv.ParseUint(ut[4], 10, 64)
if err != nil {
return 0
Expand All @@ -105,12 +107,12 @@ func parseUptime(uptime string) uint64 {
return 0
}
}
case "hr,", "hrs,":
case "hr,", "hrs,", "hr", "hrs":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case also needs a subcase for mins to be in ut[5], with appropriate protections.

hours, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil {
return 0
}
case "min,", "mins,":
case "min,", "mins,", "min", "mins":
mins, err = strconv.ParseUint(ut[2], 10, 64)
if err != nil {
return 0
Expand Down
Loading