-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[aix][host]: Uptime might have a comma #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,15 +68,16 @@ func parseUptime(uptime string) uint64 { | |
| var err error | ||
|
|
||
| switch ut[3] { | ||
| 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," || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
|
@@ -105,12 +107,12 @@ func parseUptime(uptime string) uint64 { | |
| return 0 | ||
| } | ||
| } | ||
| case "hr,", "hrs,": | ||
| case "hr,", "hrs,", "hr", "hrs": | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 :
So you just switch on singular words for "day" or "hr" or "min" ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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