Change:
What happened: When the duration is exactly 2 years or 3 years, human readable duration is returned as or . But when the duration is exactly 4 years, 5 years, etc, the human readable duration is returned as , , etc. What you expected to happen: The format of an exact year should be consistent. Remove when duration is an exact year: should be should be Check other years... 4, 5, 6, 7... not sure if they also have the problem. How to reproduce it (as minimally and precisely as possible): Because this is time-dependent, it can be difficult to reproduce via the CLI, but you can see the problem illustrated in which shows the current behavior: The and test cases should be changed to want and , and the code should be changed to make that pass. Anything else we need to know?: Note, this is not a problem when the duration is exactly 1 year because the human readable duration is still shown in days. So nothing needs to change to handle the case of exactly 1 year. Environment: Kubernetes version (use ): 1.18 Cloud provider or hardware configuration: n/a OS (e.g: ): n/a Kernel (e.g. ): n/a Install tools: n/a Network plugin and version (if this is a network-related bug): n/a Others: n/a
/sig api-machinery
/good-first-issue
This request has been marked as suitable for new contributors. Please ensure the request meets the requirements listed . If this request no longer meets these requirements, the label can be removed by commenting with the command. <detailsIn response to : /good-first-issue Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
Could I pick this up as my first issue?
Absolutely. Just use to assign it to yourself.
Also I just updated the issue description. Check the other exact years 4, 5, 6, 7 because they might also have the problem, I can't remember. I know 8 and beyond don't have the problem because it just stops showing days after 8 years.
/assign bitscuit
might recall a related PR?
(also, I have to leave the pedantic note: a year isn't always 365 days, so it's surprising to me to see the abbreviation exists at all)
I can't find it. Maybe I was remembering
Yeah it was probably that one. At first I had the tests and the fix. But it sat for a while. I changed it to just the tests of existing behavior so it could be approved more easily. Then I made this issue for the fix but decided it would probably be a good first time issue for someone instead of me doing it.
so should leap years be considered by the code?
There's no way to know how long a year is without knowing the date, so it's not a good unit--in the abstract, there's no way to know if it's a leap year or not. The go language deliberately omits it IIRC. Henry Li <:
What's the intention of HumanDuration? From what I've seen, it is just an approximation of a timestamp solely for humans to understand, so assuming 365 days per year sounds about right to me. This issue is about consistency though, so it could be solved the other way. Instead of abbreviating when it's an exact year (2y, 3y, etc.), exact years could just all have 0d (2y0d, 3y0d, etc.)
I think it is just used for a ballpark duration. It loses accuracy as the duration increases anyway because it changes the units. I guess my intention for opening the issue was to make it consistent with itself. For example it doesn't say 2d0h or 2h0m, so it should not say 2y0d.
(FTR I agree that Xy0d looks worse than Xy.) Brian Pursley <:
Hi I have made the required changes. Shall I raise the PR if you haven't started working in it ?
already assigned it, so I think it would be good to let him submit the PR, unless he unassigns or does not submit a PR in a reasonable amount of time.
Thanks I was planning on submitting the PR over the weekend
Hello, I am a first timer in open source contribution community. I think I made the required changes for that issue. However, I don't know how assignment rules work. Should I submit a pull request or wait for a feedback?

Discussion:
} else if hours < 24*365*2 { return fmt.Sprintf("%dd", hours/24) } else if hours < 24*365*8 { <del> return fmt.Sprintf("%dy%dd", hours/24/365, (hours/24)%365) </del> <ins> dy := int(hours/24) % 365 if dy == 0 { return fmt.Sprintf("%dy", hours/24/365) } return fmt.Sprintf("%dy%dd", hours/24/365, dy) </ins> } return fmt.Sprintf("%dy", int(hours/24/365)) }

{d: 8 * 24 * time.Hour, want: "8d"}, {d: 8*24*time.Hour + 23*time.Hour, want: "8d"}, {d: 2*365*24*time.Hour - time.Millisecond, want: "729d"}, <del> {d: 2 * 365 * 24 * time.Hour, want: "2y0d"}, {d: 2*365*24*time.Hour + 23*time.Hour, want: "2y0d"}, {d: 3 * 365 * 24 * time.Hour, want: "3y0d"}, </del> <ins> {d: 2 * 365 * 24 * time.Hour, want: "2y"}, {d: 2*365*24*time.Hour + 23*time.Hour, want: "2y"}, {d: 2*365*24*time.Hour + 23*time.Hour + 59*time.Minute, want: "2y"}, {d: 2*365*24*time.Hour + 24*time.Hour - time.Millisecond, want: "2y"}, {d: 2*365*24*time.Hour + 24*time.Hour, want: "2y1d"}, {d: 3 * 365 * 24 * time.Hour, want: "3y"}, {d: 4 * 365 * 24 * time.Hour, want: "4y"}, {d: 5 * 365 * 24 * time.Hour, want: "5y"}, {d: 6 * 365 * 24 * time.Hour, want: "6y"}, {d: 7 * 365 * 24 * time.Hour, want: "7y"}, </ins> {d: 8*365*24*time.Hour - time.Millisecond, want: "7y364d"}, {d: 8 * 365 * 24 * time.Hour, want: "8y"}, {d: 8*365*24*time.Hour + 364*24*time.Hour, want: "8y"},