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

'human' doesn't work great for negative durations #390

Closed
sharkdp opened this issue Mar 8, 2024 · 4 comments
Closed

'human' doesn't work great for negative durations #390

sharkdp opened this issue Mar 8, 2024 · 4 comments
Labels
bug Something isn't working good first issue

Comments

@sharkdp
Copy link
Owner

sharkdp commented Mar 8, 2024

>>> -3.5 days -> human

    = -4 days + 12 hours    [String]
@sharkdp sharkdp added bug Something isn't working good first issue labels Mar 8, 2024
@MugheesQasim
Copy link
Contributor

@sharkdp the reason for the wrong result of 'human' for negative duration is the usage of 'floor' command. 'floor' returns the largest integer less than or equal to the given number. In our case, we are getting '-4' when we provide '-3.5' as input as '-4' is the largest integer less than or equal to '-3.5'.

Example case:
human (-3.5 days)

There can be two possible solutions for this issue:
1-) The one suggested in PR #400. To use ago instead in case of negative duration, the expected output would be:
3 days 12 hours ago
2-) Use abs() function to floor the duration to a positive integer first and then showing the output in this format:
- (3 days + 12 hours)

Let me know which one seems more reasonable or if you have anything else in mind, I would be happy to contribute.

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 16, 2024

@MugheesQasim Did you also see #425?

@MugheesQasim
Copy link
Contributor

@sharkdp yes, the solution in PR #425 is using 'ago' in case of negative duration. If Numbat is ready to have two variants of human, human_date and human_time, then merging the PR will resolve this issue also.

@sharkdp
Copy link
Owner Author

sharkdp commented Oct 9, 2024

closed via #425

@sharkdp sharkdp closed this as completed Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue
Projects
None yet
Development

No branches or pull requests

2 participants