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
Updated uptime segment to have show time in a better way #2036
Conversation
Thanks for your work @StopMotionCuber! I have some comments:
|
That's true Mainly I did that because code gets more repetitive if you have to assign every Keyword Argument.
I would prefer approach 3 as I doubt that many people have a custom format here anyway and this would lead to a clean, maintainable solution, but I'd be fine with all 3 approaches |
Personally, I'd prefer the following solution:
|
I made the current solution now backwards compatible, but didn't add a new format (yet), so no need to merge already. The problems that I see for supporting a new for format while maintaining backwards compatibility is:
While all of this is possible to implement, I don't want to have a hacky if/else solution that covers every of these edge cases while bloating the code just for the sake of backwards compatibility. Speaking of backward compatibility, why do we want to keep this? If it's only the latter, I'd recommend to keep these parameters and make them non-functional (or, even better, replace them by a non-functional keyword-arguments). |
Adding a new Note that before your changes it was indeed possible to not show some of the values—by setting one of the format parameters to |
Looking at the original code again, I realized that there is actually no need for a general format parameter: Setting a specific format string to minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
time_formatted = list(filter(None, [
days_format.format(days=days) if days_format else None,
hours_format.format(hours=hours) if hours_format else None,
minutes_format.format(minutes=minutes) if minutes_format else None,
seconds_format.format(seconds=seconds) if seconds_format else None,
]))
first_non_zero = next((i for i, x in enumerate([days, hours, minutes, seconds]) if x != 0))
time_formatted = time_formatted[first_non_zero:first_non_zero + shorten_len]
return ''.join(time_formatted).strip() |
Left this PR hanging for a rather long time, I included your code now @PH111P and I think this should be mergable if the tests pass (Otherwise I'll take a look at those tests) |
This mainly addresses #1859 and provides a reasonable standard way of showing the uptime.
Now, this format
I would be happy if this could get merged and finds it way into the repo