Skip to content

Better human duration precision#22

Merged
LK4D4 merged 1 commit intodocker:masterfrom
fabianofranz:better_human_duration_precision
Nov 30, 2016
Merged

Better human duration precision#22
LK4D4 merged 1 commit intodocker:masterfrom
fabianofranz:better_human_duration_precision

Conversation

@fabianofranz
Copy link
Contributor

Human duration today rounds hours by simply converting float to int, which blindly discards the fraction part. This makes for example 2 hours 59 minutes become just "2 hours". This PR makes it more precise by

  1. Properly rounding hours (e.g. 1h 45m becomes "2 hours", 3h 55m becomes "4 hours", but 1h 15m keeps the "About an hour" behavior, and so on).
  2. Start rounding minutes to "About an hour" in 46+ minutes, which is the approach adopted by some popular libraries like moment.js.

Adds a few more tests.

Signed-off-by: Fabiano Franz ffranz@redhat.com

Signed-off-by: Fabiano Franz <ffranz@redhat.com>
@fabianofranz
Copy link
Contributor Author

ping @dnephin @vdemeester

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@LK4D4
Copy link
Contributor

LK4D4 commented Nov 30, 2016

LGMT

@LK4D4 LK4D4 merged commit e30f1e7 into docker:master Nov 30, 2016
liggitt pushed a commit to liggitt/kubernetes that referenced this pull request Dec 7, 2016
…units

Automatic merge from submit-queue (batch tested with PRs 38294, 37009, 36778, 38130, 37835)

Bump github.com/docker/go-units dependency

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md
2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md
3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes
-->

**What this PR does / why we need it**: Bump [github.com/docker/go-units](https://github.com/docker/go-units/) to include docker/go-units#22 which improves the precision of human durations ("about an hour ago", "2 days ago", etc).

**Which issue this PR fixes**: Issue detected in OpenShift: openshift/origin#11967

**Release note**:
<!--  Steps to write your release note:
1. Use the release-note-* labels to set the release note state (if you have access) 
2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. 
-->
```release-note
NONE
```
thaJeztah added a commit to thaJeztah/containerd that referenced this pull request Apr 23, 2019
relevant changes:

- docker/go-units#19 make 1 second not to be plural seconds
- docker/go-units#20 Add `HumanSizeWithPrecision` function
- docker/go-units#21 change week display rule
- docker/go-units#22 Better human duration precision
- docker/go-units#23 Removes spaces before unit
- docker/go-units#27 Fix containerd#26 - RAMInBytes Bug
- docker/go-units#33 Fix handling of unlimited (-1) ulimit values
- docker/go-units#34 Revert 46 minute threshold

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants