Bug 8411 – core.time: No easy way to check if Duration is empty

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-22T06:46:00Z
Last change time
2017-08-07T12:25:48Z
Keywords
bootcamp, pull
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2012-07-22T06:46:38Z
The simplest way to check for an empty Duration seems to be: if (!duration.total!"hnsecs"()) { ... } I suggest either implementing an isEmpty property (given that there already is an isNegative property), or implement opCast!bool so that the following will work: if (!duration) { ... }
Comment #1 by issues.dlang — 2013-01-24T12:36:20Z
We now have Duration.zero, so if(duration != Duration.zero) will work as will if(duration != Duration.init) But there's no such thing as an "empty" duration. All durations have a value, and they aren't ranges or containers. It makes as much sense to have an isEmpty property on a Duration as it does to have it on an int.
Comment #2 by dlang-bugzilla — 2013-01-24T23:13:59Z
An interval has a .empty property, though.
Comment #3 by schveiguy — 2017-03-16T22:17:54Z
I have a further, more difficult use case for this: if(auto d = calculateSomeDuration()) { display(d); } This is not as easily worked around with the current API. Adding opCast!bool was easy enough: https://github.com/dlang/druntime/pull/1793
Comment #4 by github-bugzilla — 2017-03-17T15:00:49Z
Commits pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/1caa1fc2c98c0fe06b8440f435cbac744fe7729c Fix issue 8411 - add opCast!bool support for Duration. https://github.com/dlang/druntime/commit/827fb5ddc73e94b4a55bad0d7aabfa6401b52898 Merge pull request #1793 from schveiguy/addbooldur Fix issue 8411 - add opCast!bool support for Duration.
Comment #5 by github-bugzilla — 2017-03-22T12:21:14Z
Commits pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/1caa1fc2c98c0fe06b8440f435cbac744fe7729c Fix issue 8411 - add opCast!bool support for Duration. https://github.com/dlang/druntime/commit/827fb5ddc73e94b4a55bad0d7aabfa6401b52898 Merge pull request #1793 from schveiguy/addbooldur
Comment #6 by github-bugzilla — 2017-08-07T12:25:48Z
Commits pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/1caa1fc2c98c0fe06b8440f435cbac744fe7729c Fix issue 8411 - add opCast!bool support for Duration. https://github.com/dlang/druntime/commit/827fb5ddc73e94b4a55bad0d7aabfa6401b52898 Merge pull request #1793 from schveiguy/addbooldur