-
Notifications
You must be signed in to change notification settings - Fork 446
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
Support multiple units in format_timedelta() #1066
base: master
Are you sure you want to change the base?
Conversation
…d (depth=full for all non-zero units, depth=fullest for all)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1066 +/- ##
==========================================
- Coverage 90.99% 90.94% -0.05%
==========================================
Files 26 26
Lines 4444 4453 +9
==========================================
+ Hits 4044 4050 +6
- Misses 400 403 +3 ☔ View full report in Codecov by Sentry. |
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.
Thanks!
The depth names don't sound great to me, and this would really require some tests, in various locales too.
@@ -862,6 +863,7 @@ def format_timedelta( | |||
threshold: float = .85, | |||
add_direction: bool = False, | |||
format: Literal['narrow', 'short', 'medium', 'long'] = 'long', | |||
depth: Literal['shallow', 'full', 'fullest'] = 'shallow', |
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'm not sure these names are the best or most descriptive. No matter what they end up being, they do need to be documented, though.
return pattern.replace('{0}', str(value)) | ||
|
||
return '' | ||
if (depth=='shallow'): |
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.
if (depth=='shallow'): | |
if depth == 'shallow': |
if (depth=='shallow'): | ||
formatted_string = ' '.join(filter(None, [formatted_string, pattern.replace('{0}', str(value))])) | ||
break | ||
elif ((depth=='full' and value > 0) or depth == 'fullest'): |
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.
elif ((depth=='full' and value > 0) or depth == 'fullest'): | |
elif (depth == 'full' and value > 0) or depth == 'fullest': |
|
||
return '' | ||
if (depth=='shallow'): | ||
formatted_string = ' '.join(filter(None, [formatted_string, pattern.replace('{0}', str(value))])) |
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'm not sure I understand what's going on in this magic incantation 😄
It's repeated two lines underneath this, so maybe it should be DRYed out too?
Issue #728 describes returning measures for several units when using format_timedelta().
E.g. instead of
return for depth=="fullest"
3 hours 0 minutes 40 seconds
and for depth=="full"
3 hours 40 seconds
Tests are passing, but I haven't tried contributing to babel before, and am not aware of any additional requirements beyond the few lines of source code in this PR. Feedback appreciated.