Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
core.time: Implement Duration / Duration
Browse files Browse the repository at this point in the history
Fixes issue 15137
  • Loading branch information
CyberShadow committed Oct 2, 2015
1 parent 809b40a commit e02d47c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/core/time.d
Expand Up @@ -982,6 +982,44 @@ public:
}


/++
Divides two durations.
The legal types of arithmetic for $(D Duration) using this operator are
$(TABLE
$(TR $(TD Duration) $(TD /) $(TD Duration) $(TD -->) $(TD long))
)
Params:
rhs = The duration to divide this $(D Duration) by.
+/
long opBinary(string op)(Duration rhs) const nothrow @nogc
if(op == "/")
{
return _hnsecs / rhs._hnsecs;
}

unittest
{
assert(Duration(5) / Duration(7) == 0);
assert(Duration(7) / Duration(5) == 1);
assert(Duration(8) / Duration(4) == 2);

assert(Duration(5) / Duration(-7) == 0);
assert(Duration(7) / Duration(-5) == -1);
assert(Duration(8) / Duration(-4) == -2);

assert(Duration(-5) / Duration(7) == 0);
assert(Duration(-7) / Duration(5) == -1);
assert(Duration(-8) / Duration(4) == -2);

assert(Duration(-5) / Duration(-7) == 0);
assert(Duration(-7) / Duration(-5) == 1);
assert(Duration(-8) / Duration(-4) == 2);
}


/++
Multiplies an integral value and a $(D Duration).
Expand Down

0 comments on commit e02d47c

Please sign in to comment.