diff --git a/src/core/time.d b/src/core/time.d index 12796ed600..6cd1c65e04 100644 --- a/src/core/time.d +++ b/src/core/time.d @@ -1104,6 +1104,22 @@ public: } } + /++ + Allow Duration to be used as a boolean. + Returns: `true` if this duration is non-zero. + +/ + bool opCast(T : bool)() const nothrow @nogc + { + return _hnsecs != 0; + } + + unittest + { + auto d = 10.minutes; + assert(d); + assert(!(d - d)); + assert(d + d); + } //Temporary hack until bug http://d.puremagic.com/issues/show_bug.cgi?id=5747 is fixed. Duration opCast(T)() const nothrow @nogc