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

Add decimal formatting for durations #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

64r
Copy link

@64r 64r commented Sep 2, 2019

Hi,

I've added functionality that allows timedeltas to be formatted as a decimal number instead of hours, minutes and seconds.
This is useful for users that want to calculate a price based on an hourly rate. For example watson aggreate now shows 4.50h if you've tracked 4 hours and 30 minutes.

This feature is configurable via watson config. You can also set the decimal precision used for formatting the numbers.

I've also added documentation and tests for this feature.

@@ -84,11 +85,15 @@ def _style_short_id(id):
return fmt(element)


def format_timedelta(delta):
def format_timedelta(watson, delta):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking the API, what about the following instead?

Suggested change
def format_timedelta(watson, delta):
def format_timedelta(delta, as_decimal=False):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I can change it to the way you suggested. Would you prefer if I made this a file-local variable in cli.py or do the call in every method that uses format_timedelta?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not having a separated method to format timedelta but a single entrypoint that does the heavy lifting. This should be sufficient for such a small piece of code and its testability. WDYT @k4nar?

Copy link
Contributor

@jmaupetit jmaupetit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thank you for this idea/contribution 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants