Skip to content
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

tools.time feature: "Raw" mode for seconds_to_human() #1824

Closed
dgw opened this issue Mar 25, 2020 · 3 comments · Fixed by #2026
Closed

tools.time feature: "Raw" mode for seconds_to_human() #1824

dgw opened this issue Mar 25, 2020 · 3 comments · Fixed by #2026
Labels
Milestone

Comments

@dgw
Copy link
Member

dgw commented Mar 25, 2020

It's cute that tools.time.seconds_to_human() takes care of the future/past grammar for you (adding "in " to the front or " ago" to the back, depending on the delta's sign). But it makes using that function really annoying in some cases, when it should be the perfect tool.

For the use cases I'm looking at, the most useful thing would be a "raw" mode that returns the intermediate list of units, rather than the fully-formatted string. In implementing this, we could actually simplify the code around here and eliminate the split(', ') below it:

sopel/sopel/tools/time.py

Lines 243 to 250 in 3959137

result = ", ".join(filter(lambda x: bool(x), [
"{0} {1}".format(years, years_text) if years else "",
"{0} {1}".format(months, months_text) if months else "",
"{0} {1}".format(days, days_text) if days else "",
"{0} {1}".format(hours, hours_text) if hours else "",
"{0} {1}".format(minutes, minutes_text) if minutes else "",
"{0} {1}".format(seconds, seconds_text) if seconds else ""
]))

Related: #1798, #1799. Not all of these will necessarily be implemented. Right now they're all just ideas, and picking the right one or two could make the API flexible and intuitive enough that we don't need to bake every little feature into it.

@dgw dgw added the Feature label Mar 25, 2020
@dgw dgw added this to the 7.1.0 milestone Mar 25, 2020
@dgw
Copy link
Member Author

dgw commented Oct 18, 2020

This actually should be low-hanging fruit, and I'll self-assign it for the last two weeks of Hacktoberfest to (hopefully) motivate myself to take care of it.

@dgw dgw self-assigned this Oct 18, 2020
@Exirel Exirel unassigned dgw Feb 6, 2021
@Exirel
Copy link
Contributor

Exirel commented Feb 6, 2021

I did that for you.

@dgw
Copy link
Member Author

dgw commented Feb 6, 2021

Aww, I forgot about this one after all. 😩

@dgw dgw closed this as completed in #2026 Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants