`Duration#toHuman` does not print human-readable strings
Based on the name I would expect that `Duration#toHuman` returns strings that are optimal for human reading. But, IMHO this is not the case. The way I see it there are three issues. * If a `Duration` is created from a number of milliseconds then the milliseconds are printed as-is, which is not human-readable. ```js Duration.fromMillis(22140000).toHuman() //=> "22140000 milliseconds" ``` In this case, I would expect something like the string "6 hours and 9 minutes" which is what [humanize-duration](https://github.com/EvanHahn/HumanizeDuration.js) returns. * If a `Duration` is created with some units being zero then those units are printed even though they do not benefit humans. ```js Duration.fromMillis(3 * 60 * 1000).shiftTo("hours", "minutes").toHuman() //=> "0 hours, 3 minutes" Duration.fromObject({ days: 0, hours: 0, minutes: 12, seconds: 0 }).toHuman() //=> "0 days, 0 hours, 12 minutes, 0 seconds" ``` * If a `Duration` is created with an empty object then an empty string is returned. An empty string is not a human-readable duration. ```js Duration.fromObject({}).toHuman() //=> "" ``` It seems to me that `toHuman` only returns the internal representation of the duration with unit names attached and not actual human-friendly output. I think that either the `toHuman` method should be renamed as the current name is confusing or the above problems should be fixed. Units that are zero should not be printed and small units should be converted into larger units if possible.
Posted by paldepind on Feb 9, 2022, 10:15 AM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
`Duration#toHuman` does not print human-readable strings
Based on the name I would expect that `Duration#toHuman` returns strings that are optimal for human reading. But, IMHO this is not the case. The way I see it there are three issues. * If a `Duration` is created from a number of milliseconds then the milliseconds are printed as-is, which is not human-readable. ```js Duration.fromMillis(22140000).toHuman() //=> "22140000 milliseconds" ``` In this case, I would expect something like the string "6 hours and 9 minutes" which is what [humanize-duration](https://github.com/EvanHahn/HumanizeDuration.js) returns. * If a `Duration` is created with some units being zero then those units are printed even though they do not benefit humans. ```js Duration.fromMillis(3 * 60 * 1000).shiftTo("hours", "minutes").toHuman() //=> "0 hours, 3 minutes" Duration.fromObject({ days: 0, hours: 0, minutes: 12, seconds: 0 }).toHuman() //=> "0 days, 0 hours, 12 minutes, 0 seconds" ``` * If a `Duration` is created with an empty object then an empty string is returned. An empty string is not a human-readable duration. ```js Duration.fromObject({}).toHuman() //=> "" ``` It seems to me that `toHuman` only returns the internal representation of the duration with unit names attached and not actual human-friendly output. I think that either the `toHuman` method should be renamed as the current name is confusing or the above problems should be fixed. Units that are zero should not be printed and small units should be converted into larger units if possible.
Comments (0)
No comments yet. Start the discussion.